draft-fixes

This commit is contained in:
tonyrewin 2022-10-09 11:41:33 +03:00
parent ce9057d637
commit 294871505c
2 changed files with 13 additions and 18 deletions

View File

@ -258,8 +258,6 @@ export const createCtrl = (initial): [Store<State>, { [key: string]: any }] => {
const loadDraft = async (config: Config, path: string): Promise<Draft> => {
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<State>, { [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<State>, { [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()
}

View File

@ -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
}