draft-fixes
This commit is contained in:
parent
ce9057d637
commit
294871505c
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user