mirror of
https://github.com/OHTU-German-learning-website/OHTU-German-learning-website.git
synced 2026-10-12 19:13:51 +03:00
392 implement front for saving texts from quill (#404)
Co-authored-by: Filippa Högnäsbacka <filippa.hognasbacka@gmail.com>
This commit is contained in:
co-authored by
Filippa Högnäsbacka
parent
5cfbadfde1
commit
e952ea7cb2
@@ -33,6 +33,18 @@ export default function Chapters() {
|
|||||||
fetchHTML();
|
fetchHTML();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const submitEditorContent = async () => {
|
||||||
|
const jsonData = JSON.stringify({ content: editorContent });
|
||||||
|
const res = await fetch(`/api/html-content/${parseInt(chapter)}`, {
|
||||||
|
headers: {
|
||||||
|
Accept: "application/json",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
method: "PUT",
|
||||||
|
body: jsonData,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const Chapter = chapters.find((c) => c.id === chapter);
|
const Chapter = chapters.find((c) => c.id === chapter);
|
||||||
if (!Chapter) {
|
if (!Chapter) {
|
||||||
router.replace("/resources");
|
router.replace("/resources");
|
||||||
@@ -48,9 +60,15 @@ export default function Chapters() {
|
|||||||
if (editorActive) {
|
if (editorActive) {
|
||||||
return (
|
return (
|
||||||
<Column className={layout.viewContent}>
|
<Column className={layout.viewContent}>
|
||||||
<Button onClick={() => setEditorActive(false)}>Close editor</Button>
|
<Row gap="1rem">
|
||||||
|
<Button onClick={() => setEditorActive(false)}>Close editor</Button>
|
||||||
|
<Button onClick={submitEditorContent}>Save changes</Button>
|
||||||
|
</Row>
|
||||||
<Row justify="space-between" pb="xl">
|
<Row justify="space-between" pb="xl">
|
||||||
<Editor defaultContent={editorContent.content} />
|
<Editor
|
||||||
|
defaultContent={editorContent.content}
|
||||||
|
updateEditorContent={(content) => setEditorContent(content)}
|
||||||
|
/>
|
||||||
</Row>
|
</Row>
|
||||||
</Column>
|
</Column>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import "quill/dist/quill.snow.css";
|
|||||||
|
|
||||||
const ClientEditor = (props) => {
|
const ClientEditor = (props) => {
|
||||||
const containerRef = useRef(null);
|
const containerRef = useRef(null);
|
||||||
|
const updateEditorContentRef = useRef(props.updateEditorContent);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let quill;
|
let quill;
|
||||||
@@ -10,6 +11,10 @@ const ClientEditor = (props) => {
|
|||||||
const Quill = (await import("quill")).default;
|
const Quill = (await import("quill")).default;
|
||||||
if (containerRef.current && containerRef.current.children.length === 0) {
|
if (containerRef.current && containerRef.current.children.length === 0) {
|
||||||
quill = new Quill(containerRef.current, { theme: "snow" });
|
quill = new Quill(containerRef.current, { theme: "snow" });
|
||||||
|
quill.root.setAttribute("spellcheck", false);
|
||||||
|
quill.on(Quill.events.TEXT_CHANGE, () => {
|
||||||
|
updateEditorContentRef.current?.(quill.getSemanticHTML());
|
||||||
|
});
|
||||||
if (props.defaultContent) {
|
if (props.defaultContent) {
|
||||||
quill.clipboard.dangerouslyPasteHTML(props.defaultContent);
|
quill.clipboard.dangerouslyPasteHTML(props.defaultContent);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user