aboutsummaryrefslogtreecommitdiff
path: root/src/lib/stores/actions.ts
blob: 95702dc10b7404a913b489254ed8eb4fe71bb050 (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
35
36
37
38
39
40
41
import { derived, writable } from 'svelte/store';
import type { Readable, Writable } from 'svelte/store';

export type Actions = {
  topic?: TopicAction
};

export type TopicAction = {
  id: string
};

/*
 * This is a store to set the actions in the top header.
 */

const actions: Writable<Actions> = writable({});

export const enableTopicActions = (id: string) => {

  actions.update((actionsValue: Actions): Actions => {

    actionsValue.topic = {
      id
    };
    return actionsValue;
  });
};

export const disableTopicActions = () => {

  actions.update((actionsValue): Actions => {

    delete actionsValue.topic;
    return actionsValue;
  });
};

export const topicActions: Readable<TopicAction> = derived(
  actions,
  ($actions) => $actions.topic
);