]>
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 = { | |
5 | topic?: TopicAction | |
6 | }; | |
7 | ||
8 | export type TopicAction = { | |
9 | id: string | |
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) => { | |
19 | ||
20 | actions.update((actionsValue: Actions): Actions => { | |
21 | ||
22 | actionsValue.topic = { | |
23 | id | |
24 | }; | |
25 | return actionsValue; | |
26 | }); | |
27 | }; | |
28 | ||
29 | export const disableTopicActions = () => { | |
30 | ||
31 | actions.update((actionsValue): Actions => { | |
32 | ||
33 | delete actionsValue.topic; | |
34 | return actionsValue; | |
35 | }); | |
36 | }; | |
37 | ||
38 | export const topicActions: Readable<TopicAction> = derived( | |
39 | actions, | |
40 | ($actions) => $actions.topic | |
41 | ); |