a tool for shared writing and social publishing
1import { create } from "zustand"; 2import { combine } from "zustand/middleware"; 3 4export const useThreadState = create( 5 combine( 6 { 7 // Set of collapsed thread URIs 8 collapsedThreads: new Set<string>(), 9 }, 10 (set) => ({ 11 toggleCollapsed: (uri: string) => { 12 set((state) => { 13 const newCollapsed = new Set(state.collapsedThreads); 14 if (newCollapsed.has(uri)) { 15 newCollapsed.delete(uri); 16 } else { 17 newCollapsed.add(uri); 18 } 19 return { collapsedThreads: newCollapsed }; 20 }); 21 }, 22 isCollapsed: (uri: string) => { 23 // This is a selector helper, but we'll use the state directly 24 return false; 25 }, 26 }), 27 ), 28);