-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CreateHelp component for editing help content and update snackbar…
… messages
- Loading branch information
1 parent
ce7636f
commit 6cc622f
Showing
4 changed files
with
72 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { doc, setDoc } from "firebase/firestore"; | ||
import { snackbar } from "mdui"; | ||
import React from "react"; | ||
import Markdown from "react-markdown"; | ||
import { useLoaderData } from "react-router-dom"; | ||
import { db } from "../firebase"; | ||
|
||
export default function CreateHelp() { | ||
const { helpContent } = useLoaderData() as { | ||
helpContent: { content: string }; | ||
}; | ||
const [content, setContent] = React.useState(helpContent.content); | ||
|
||
const [publishing, setPublishing] = React.useState(false); | ||
|
||
async function publishHelpContent() { | ||
setPublishing(true); | ||
setDoc(doc(db, "docs", "help"), { content }) | ||
.then(() => { | ||
snackbar({ message: "Veröffentlicht" }); | ||
setPublishing(false); | ||
}) | ||
.catch(() => { | ||
snackbar({ message: "Fehler beim Speichern" }); | ||
setPublishing(false); | ||
}); | ||
} | ||
return ( | ||
<div className="mdui-prose"> | ||
<mdui-tabs value="edit"> | ||
<mdui-tab value="edit">Bearbeiten</mdui-tab> | ||
<mdui-tab value="preview">Vorschau</mdui-tab> | ||
|
||
<mdui-tab-panel slot="panel" value="edit"> | ||
<p /> | ||
<mdui-text-field | ||
variant="outlined" | ||
autosize | ||
min-rows={15} | ||
label="Inhalt" | ||
value={content} | ||
onInput={(e) => setContent((e.target as HTMLInputElement).value)} | ||
></mdui-text-field> | ||
</mdui-tab-panel> | ||
<mdui-tab-panel slot="panel" value="preview"> | ||
<p /> | ||
<Markdown className={"help"}>{content}</Markdown> | ||
</mdui-tab-panel> | ||
</mdui-tabs> | ||
|
||
<div style={{ position: "fixed", bottom: "1rem", right: "1rem" }}> | ||
{publishing ? ( | ||
<mdui-fab icon="public" loading extended> | ||
Veröffentlichen | ||
</mdui-fab> | ||
) : ( | ||
<mdui-fab icon="public" extended onClick={publishHelpContent}> | ||
Veröffentlichen | ||
</mdui-fab> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters