mirror of
https://github.com/muerwre/markdown-home-tab.git
synced 2025-04-25 00:46:41 +07:00
implement Storage Provider
This commit is contained in:
parent
db911e51e4
commit
2ba35b8e2b
16 changed files with 393 additions and 96 deletions
|
@ -1,11 +1,10 @@
|
|||
import { FC, Suspense, lazy } from "react";
|
||||
import { SimpleTextareaEditor } from "../../components/SimpleTextareaEditor";
|
||||
import { MarkdownViewer } from "../../components/MarkdownViewer";
|
||||
import { usePersistedValue } from "./hooks/usePersistedValue";
|
||||
import styles from "./styles.module.scss";
|
||||
import { useSettings } from "~/modules/settings/context/SettingsContext";
|
||||
import { EmptyViewer } from "../../components/EmptyViewer";
|
||||
import { FC, Suspense, useCallback } from "react";
|
||||
import { EditorWrapper } from "../../components/EditorWrapper";
|
||||
import { EmptyViewer } from "../../components/EmptyViewer";
|
||||
import { MarkdownViewer } from "../../components/MarkdownViewer";
|
||||
import { SimpleTextareaEditor } from "../../components/SimpleTextareaEditor";
|
||||
import styles from "./styles.module.scss";
|
||||
import { useStorage } from "../../../../modules/storage/StorageContext";
|
||||
|
||||
interface MarkdownEditorContainerProps {
|
||||
id: string;
|
||||
|
@ -14,29 +13,22 @@ interface MarkdownEditorContainerProps {
|
|||
remove: VoidCallback;
|
||||
}
|
||||
|
||||
const RichEditor = lazy(() =>
|
||||
import("../../components/RemirrorEditor").then((module) => ({
|
||||
default: module.RemirrorEditor,
|
||||
}))
|
||||
);
|
||||
|
||||
export const MarkdownEditorContainer: FC<MarkdownEditorContainerProps> = ({
|
||||
id,
|
||||
locked,
|
||||
startEditing,
|
||||
remove,
|
||||
}) => {
|
||||
const {
|
||||
settings: { richEditorEnabled },
|
||||
} = useSettings();
|
||||
|
||||
const { value, setValue, hydrated } = usePersistedValue(
|
||||
id,
|
||||
"MarkdownEditorContainer"
|
||||
);
|
||||
const { panels, setPanel, hydrated } = useStorage();
|
||||
|
||||
const value = panels[id] ?? "";
|
||||
const empty = !value.trim();
|
||||
|
||||
const onChange = useCallback(
|
||||
(val: string) => setPanel(id, val),
|
||||
[id, setPanel]
|
||||
);
|
||||
|
||||
const viewer = empty ? (
|
||||
<EmptyViewer startEditing={startEditing} />
|
||||
) : (
|
||||
|
@ -45,15 +37,11 @@ export const MarkdownEditorContainer: FC<MarkdownEditorContainerProps> = ({
|
|||
|
||||
const editor = (
|
||||
<EditorWrapper save={startEditing} remove={remove}>
|
||||
{richEditorEnabled ? (
|
||||
<RichEditor value={value} onChange={setValue} locked={locked} />
|
||||
) : (
|
||||
<SimpleTextareaEditor
|
||||
value={value}
|
||||
onChange={setValue}
|
||||
save={startEditing}
|
||||
/>
|
||||
)}
|
||||
<SimpleTextareaEditor
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
save={startEditing}
|
||||
/>
|
||||
</EditorWrapper>
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue