]>
Commit | Line | Data |
---|---|---|
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 | actions.update((actionsValue: Actions): Actions => { | |
20 | actionsValue.topic = { | |
21 | id | |
22 | }; | |
23 | return actionsValue; | |
24 | }); | |
25 | }; | |
26 | ||
27 | export const disableTopicActions = () => { | |
28 | actions.update((actionsValue): Actions => { | |
29 | delete actionsValue.topic; | |
30 | return actionsValue; | |
31 | }); | |
32 | }; | |
33 | ||
34 | export const topicActions: Readable<TopicAction> = derived(actions, ($actions) => $actions.topic); |