From 294871505c1574cb7621b13d1c14855fac3053b3 Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Sun, 9 Oct 2022 11:41:33 +0300 Subject: [PATCH] draft-fixes --- src/components/Editor/store/ctrl.ts | 26 ++++++++++---------------- src/stores/editor.ts | 5 +++-- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/components/Editor/store/ctrl.ts b/src/components/Editor/store/ctrl.ts index 60570602..29517985 100644 --- a/src/components/Editor/store/ctrl.ts +++ b/src/components/Editor/store/ctrl.ts @@ -258,8 +258,6 @@ export const createCtrl = (initial): [Store, { [key: string]: any }] => { const loadDraft = async (config: Config, path: string): Promise => { const draftstore = useStore(draftsatom) const draft = createMemo(() => draftstore()[path]) - const lastModified = draft().lastModified - const draftContent = draft().body const schema = createSchema({ config, markdown: false, @@ -267,20 +265,16 @@ export const createCtrl = (initial): [Store, { [key: string]: any }] => { keymap }) const parser = createMarkdownParser(schema) - const doc = parser.parse(draftContent).toJSON() - const text = { - doc, - selection: { - type: 'text', - anchor: 1, - head: 1 - } - } return { ...draft(), - body: doc, - text, - lastModified: lastModified.toISOString(), + text: { + doc: parser.parse(draft().body).toJSON(), + selection: { + type: 'text', + anchor: 1, + head: 1 + } + }, path } } @@ -357,9 +351,9 @@ export const createCtrl = (initial): [Store, { [key: string]: any }] => { if (isInitialized(state.text as EditorState)) { if (state.path) { - const text = serialize(store.editorView.state) + // const text = serialize(store.editorView.state) // await remote.writeDraft(state.path, text) - draftsatom.setKey(state.path, text) + draftsatom.setKey(state.path, store.editorView.state) } else { data.text = store.editorView.state.toJSON() } diff --git a/src/stores/editor.ts b/src/stores/editor.ts index 015aa0de..c91302dd 100644 --- a/src/stores/editor.ts +++ b/src/stores/editor.ts @@ -1,11 +1,12 @@ -import { persistentAtom, persistentMap } from '@nanostores/persistent' +import { persistentMap } from '@nanostores/persistent' import type { Reaction } from '../graphql/types.gen' import { atom } from 'nanostores' import { createSignal } from 'solid-js' interface Draft { - [x: string]: any createdAt: Date + topics?: string[] + lastModified: Date body?: string title?: string }