summaryrefslogtreecommitdiffhomepage
path: root/packages/storybook/.storybook/mocks/app/context/comments.ts
blob: 6c01d203b811a9f76f1971d558b88d9103b1c8e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { createSignal } from "solid-js"

type Comment = {
  id: string
  file: string
  selection: { start: number; end: number }
  comment: string
  time: number
}

const [list, setList] = createSignal<Comment[]>([])
const [focus, setFocus] = createSignal<{ file: string; id: string } | null>(null)
const [active, setActive] = createSignal<{ file: string; id: string } | null>(null)

export function useComments() {
  return {
    all: list,
    replace(next: Comment[]) {
      setList(next)
    },
    remove(file: string, id: string) {
      setList((current) => current.filter((item) => !(item.file === file && item.id === id)))
    },
    clear() {
      setList([])
      setFocus(null)
      setActive(null)
    },
    focus,
    setFocus,
    active,
    setActive,
  }
}