aboutsummaryrefslogtreecommitdiff
path: root/src/lib/stores/actions.ts
blob: 19e9a6976b4465764d2cb3934f073378ef545a99 (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 { 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);