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