tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
289
fork
atom
a tool for shared writing and social publishing
289
fork
atom
overview
issues
27
pulls
pipelines
add missing thread state store
awarm.space
2 months ago
728a8393
a805d97b
+28
1 changed file
expand all
collapse all
unified
split
src
useThreadState.ts
+28
src/useThreadState.ts
···
1
1
+
import { create } from "zustand";
2
2
+
import { combine } from "zustand/middleware";
3
3
+
4
4
+
export const useThreadState = create(
5
5
+
combine(
6
6
+
{
7
7
+
// Set of collapsed thread URIs
8
8
+
collapsedThreads: new Set<string>(),
9
9
+
},
10
10
+
(set) => ({
11
11
+
toggleCollapsed: (uri: string) => {
12
12
+
set((state) => {
13
13
+
const newCollapsed = new Set(state.collapsedThreads);
14
14
+
if (newCollapsed.has(uri)) {
15
15
+
newCollapsed.delete(uri);
16
16
+
} else {
17
17
+
newCollapsed.add(uri);
18
18
+
}
19
19
+
return { collapsedThreads: newCollapsed };
20
20
+
});
21
21
+
},
22
22
+
isCollapsed: (uri: string) => {
23
23
+
// This is a selector helper, but we'll use the state directly
24
24
+
return false;
25
25
+
},
26
26
+
}),
27
27
+
),
28
28
+
);