]>
Commit | Line | Data |
---|---|---|
a7cf03c1 RBR |
1 | import { derived, writable } from 'svelte/store'; |
2 | import type { Readable, Writable } from 'svelte/store'; | |
3 | ||
4 | export type Actions = { | |
cac85db0 | 5 | topic?: TopicAction; |
a7cf03c1 RBR |
6 | }; |
7 | ||
8 | export type TopicAction = { | |
cac85db0 | 9 | id: string; |
a7cf03c1 RBR |
10 | }; |
11 | ||
12 | /* | |
13 | * This is a store to set the actions in the top header. | |
14 | */ | |
15 | ||
16 | const actions: Writable<Actions> = writable({}); | |
17 | ||
18 | export const enableTopicActions = (id: string) => { | |
cac85db0 RBR |
19 | actions.update((actionsValue: Actions): Actions => { |
20 | actionsValue.topic = { | |
21 | id | |
22 | }; | |
23 | return actionsValue; | |
24 | }); | |
a7cf03c1 RBR |
25 | }; |
26 | ||
27 | export const disableTopicActions = () => { | |
cac85db0 RBR |
28 | actions.update((actionsValue): Actions => { |
29 | delete actionsValue.topic; | |
30 | return actionsValue; | |
31 | }); | |
a7cf03c1 RBR |
32 | }; |
33 | ||
cac85db0 | 34 | export const topicActions: Readable<TopicAction> = derived(actions, ($actions) => $actions.topic); |