(scope: ServerScope, dir: string, id: string | undefined)
| 171 | } |
| 172 | |
| 173 | function createCommentSession(scope: ServerScope, dir: string, id: string | undefined) { |
| 174 | const legacy = `${dir}/comments${id ? "/" + id : ""}.v1` |
| 175 | |
| 176 | const [store, setStore, _, ready] = persisted( |
| 177 | Persist.serverScoped(scope, dir, id, "comments", [legacy]), |
| 178 | createStore<CommentStore>({ |
| 179 | comments: {}, |
| 180 | }), |
| 181 | ) |
| 182 | const session = createCommentSessionState(store, setStore) |
| 183 | |
| 184 | return { |
| 185 | ready, |
| 186 | list: session.list, |
| 187 | all: session.all, |
| 188 | add: session.add, |
| 189 | remove: session.remove, |
| 190 | update: session.update, |
| 191 | replace: session.replace, |
| 192 | clear: session.clear, |
| 193 | focus: session.focus, |
| 194 | setFocus: session.setFocus, |
| 195 | clearFocus: session.clearFocus, |
| 196 | active: session.active, |
| 197 | setActive: session.setActive, |
| 198 | clearActive: session.clearActive, |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | export const { use: useComments, provider: CommentsProvider } = createSimpleContext({ |
| 203 | name: "Comments", |
no test coverage detected