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 loadDraft = async (config: Config, path: string): Promise<Draft> => {
const draftstore = useStore(draftsatom) const draftstore = useStore(draftsatom)
const draft = createMemo(() => draftstore()[path]) const draft = createMemo(() => draftstore()[path])
const lastModified = draft().lastModified
const draftContent = draft().body
const schema = createSchema({ const schema = createSchema({
config, config,
markdown: false, markdown: false,
@ -267,20 +265,16 @@ export const createCtrl = (initial): [Store<State>, { [key: string]: any }] => {
keymap keymap
}) })
const parser = createMarkdownParser(schema) const parser = createMarkdownParser(schema)
const doc = parser.parse(draftContent).toJSON()
const text = {
doc,
selection: {
type: 'text',
anchor: 1,
head: 1
}
}
return { return {
...draft(), ...draft(),
body: doc, text: {
text, doc: parser.parse(draft().body).toJSON(),
lastModified: lastModified.toISOString(), selection: {
type: 'text',
anchor: 1,
head: 1
}
},
path path
} }
} }
@ -357,9 +351,9 @@ export const createCtrl = (initial): [Store<State>, { [key: string]: any }] => {
if (isInitialized(state.text as EditorState)) { if (isInitialized(state.text as EditorState)) {
if (state.path) { if (state.path) {
const text = serialize(store.editorView.state) // const text = serialize(store.editorView.state)
// await remote.writeDraft(state.path, text) // await remote.writeDraft(state.path, text)
draftsatom.setKey(state.path, text) draftsatom.setKey(state.path, store.editorView.state)
} else { } else {
data.text = store.editorView.state.toJSON() 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 type { Reaction } from '../graphql/types.gen'
import { atom } from 'nanostores' import { atom } from 'nanostores'
import { createSignal } from 'solid-js' import { createSignal } from 'solid-js'
interface Draft { interface Draft {
[x: string]: any
createdAt: Date createdAt: Date
topics?: string[]
lastModified: Date
body?: string body?: string
title?: string title?: string
} }