]> git.r.bdr.sh - rbdr/forum/blame - src/lib/stores/actions.ts
Adjust formatting of jest
[rbdr/forum] / src / lib / stores / actions.ts
CommitLineData
a7cf03c1
RBR
1import { derived, writable } from 'svelte/store';
2import type { Readable, Writable } from 'svelte/store';
3
4export type Actions = {
cac85db0 5 topic?: TopicAction;
a7cf03c1
RBR
6};
7
8export 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
16const actions: Writable<Actions> = writable({});
17
18export 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
27export const disableTopicActions = () => {
cac85db0
RBR
28 actions.update((actionsValue): Actions => {
29 delete actionsValue.topic;
30 return actionsValue;
31 });
a7cf03c1
RBR
32};
33
cac85db0 34export const topicActions: Readable<TopicAction> = derived(actions, ($actions) => $actions.topic);