MCPcopy
hub / github.com/Peppermint-Lab/peppermint / NotebookEditor

Function NotebookEditor

apps/client/components/NotebookEditor/index.tsx:30–217  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28}
29
30export default function NotebookEditor() {
31 const router = useRouter();
32 const token = getCookie("session");
33
34 const user = useUser();
35
36 const [initialContent, setInitialContent] = useState<
37 PartialBlock[] | undefined | "loading"
38 >("loading");
39
40 const editor = useMemo(() => {
41 if (initialContent === "loading") {
42 return undefined;
43 }
44 return BlockNoteEditor.create({ initialContent });
45 }, [initialContent]);
46
47 const [value, setValue] = useState<any>();
48 const [note, setNote] = useState();
49 const [title, setTitle] = useState();
50 const [loading, setLoading] = useState(true);
51 const [saving, setSaving] = useState(false);
52 const [lastSaved, setLastSaved] = useState();
53
54 const [debouncedValue] = useDebounce(value, 500);
55 const [debounceTitle] = useDebounce(title, 500);
56
57 async function fetchNotebook() {
58 setValue(undefined);
59 setLoading(true);
60 const res = await fetch(`/api/v1/notebooks/note/${router.query.id}`, {
61 method: "GET",
62 headers: {
63 "Content-Type": "application/json",
64 Authorization: `Bearer ${token}`,
65 },
66 }).then((res) => res.json());
67 if (res.note.userId !== user.user.id) {
68 router.back();
69 }
70 await loadFromStorage(res.note.note).then((content) => {
71 setInitialContent(content);
72 });
73 setNote(res.note);
74 setTitle(res.note.title);
75 setLoading(false);
76 }
77
78 async function updateNoteBook() {
79 setSaving(true);
80 const res = await fetch(`/api/v1/notebooks/note/${router.query.id}/update`, {
81 method: "PUT",
82 headers: {
83 "Content-Type": "application/json",
84 Authorization: `Bearer ${token}`,
85 },
86 body: JSON.stringify({
87 title: debounceTitle,

Callers

nothing calls this directly

Calls 5

useUserFunction · 0.90
fetchNotebookFunction · 0.85
updateNoteBookFunction · 0.85
deleteNotebookFunction · 0.85
convertHTMLFunction · 0.70

Tested by

no test coverage detected