webapp/src/stores/editor.ts

44 lines
1.0 KiB
TypeScript
Raw Normal View History

2022-10-05 08:55:26 +00:00
import { persistentAtom } from '@nanostores/persistent'
2022-10-07 19:35:53 +00:00
import type { Reaction } from '../graphql/types.gen'
import { atom } from 'nanostores'
import { createSignal } from 'solid-js'
2022-10-05 08:55:26 +00:00
interface Draft {
2022-10-09 00:00:13 +00:00
[x: string]: any
2022-10-05 08:55:26 +00:00
createdAt: Date
body?: string
title?: string
}
interface Collab {
authors: string[] // slugs
invites?: string[]
createdAt: Date
body?: string
title?: string
}
2022-10-09 00:00:13 +00:00
export const drafts = persistentAtom<{ [key: string]: Draft }>(
'drafts',
{},
{
encode: JSON.stringify,
decode: JSON.parse
}
) // save drafts on device
2022-10-05 08:55:26 +00:00
2022-10-07 19:35:53 +00:00
export const collabs = atom<Collab[]>([]) // save collabs in backend or in p2p network
export const [editorReactions, setReactions] = createSignal<Reaction[]>([])
2022-10-05 08:55:26 +00:00
/*
const approvals = computed(
reactions,
(rdict) => Object.values(rdict)
.filter((r: Reaction) => r.kind === ReactionKind.Accept)
)
const proposals = computed<Reaction[], typeof reactions>(
reactions,
(rdict) => Object.values(rdict)
.filter((r: Reaction) => r.kind === ReactionKind.Propose)
)
*/