MCPcopy Index your code
hub / github.com/21st-dev/1code / useSubChatDraftsCache

Function useSubChatDraftsCache

src/renderer/features/agents/lib/drafts.ts:279–303  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

277 * Returns a Record<key, text> for quick lookups
278 */
279export function useSubChatDraftsCache(): Record<string, string> {
280 const [draftsCache, setDraftsCache] = useState<Record<string, string>>(() => {
281 if (typeof window === "undefined") return {}
282 return buildDraftsCache()
283 })
284
285 useEffect(() => {
286 const handleChange = () => {
287 const newCache = buildDraftsCache()
288 setDraftsCache(newCache)
289 }
290
291 // Listen for custom event (same-tab changes)
292 window.addEventListener(DRAFTS_CHANGE_EVENT, handleChange)
293 // Listen for storage event (cross-tab changes)
294 window.addEventListener("storage", handleChange)
295
296 return () => {
297 window.removeEventListener(DRAFTS_CHANGE_EVENT, handleChange)
298 window.removeEventListener("storage", handleChange)
299 }
300 }, [])
301
302 return draftsCache
303}
304
305/**
306 * Hook to get a specific sub-chat draft

Callers 2

AgentsSubChatsSidebarFunction · 0.90
useSubChatDraftFunction · 0.85

Calls 1

buildDraftsCacheFunction · 0.85

Tested by

no test coverage detected