From bac89b1afe26882875d1ad376bff207dca69ceaa Mon Sep 17 00:00:00 2001 From: Nexus Dev Date: Sat, 11 Apr 2026 16:44:03 +0000 Subject: [PATCH] refactor(nexus): drop orphaned useInboxBadge hook (phase 7) --- ui/src/hooks/useInboxBadge.ts | 141 ---------------------------------- 1 file changed, 141 deletions(-) delete mode 100644 ui/src/hooks/useInboxBadge.ts diff --git a/ui/src/hooks/useInboxBadge.ts b/ui/src/hooks/useInboxBadge.ts deleted file mode 100644 index 6b7daa2b..00000000 --- a/ui/src/hooks/useInboxBadge.ts +++ /dev/null @@ -1,141 +0,0 @@ -import { useEffect, useMemo, useState } from "react"; -import { useQuery } from "@tanstack/react-query"; -import { accessApi } from "../api/access"; -import { ApiError } from "../api/client"; -import { approvalsApi } from "../api/approvals"; -import { dashboardApi } from "../api/dashboard"; -import { heartbeatsApi } from "../api/heartbeats"; -import { issuesApi } from "../api/issues"; -import { queryKeys } from "../lib/queryKeys"; -import { - computeInboxBadgeData, - getRecentTouchedIssues, - loadDismissedInboxItems, - saveDismissedInboxItems, - loadReadInboxItems, - saveReadInboxItems, - READ_ITEMS_KEY, -} from "../lib/inbox"; - -const INBOX_ISSUE_STATUSES = "backlog,todo,in_progress,in_review,blocked,done"; - -export function useDismissedInboxItems() { - const [dismissed, setDismissed] = useState>(loadDismissedInboxItems); - - useEffect(() => { - const handleStorage = (event: StorageEvent) => { - if (event.key !== "paperclip:inbox:dismissed") return; - setDismissed(loadDismissedInboxItems()); - }; - window.addEventListener("storage", handleStorage); - return () => window.removeEventListener("storage", handleStorage); - }, []); - - const dismiss = (id: string) => { - setDismissed((prev) => { - const next = new Set(prev); - next.add(id); - saveDismissedInboxItems(next); - return next; - }); - }; - - return { dismissed, dismiss }; -} - -export function useReadInboxItems() { - const [readItems, setReadItems] = useState>(loadReadInboxItems); - - useEffect(() => { - const handleStorage = (event: StorageEvent) => { - if (event.key !== READ_ITEMS_KEY) return; - setReadItems(loadReadInboxItems()); - }; - window.addEventListener("storage", handleStorage); - return () => window.removeEventListener("storage", handleStorage); - }, []); - - const markRead = (id: string) => { - setReadItems((prev) => { - const next = new Set(prev); - next.add(id); - saveReadInboxItems(next); - return next; - }); - }; - - const markUnread = (id: string) => { - setReadItems((prev) => { - const next = new Set(prev); - next.delete(id); - saveReadInboxItems(next); - return next; - }); - }; - - return { readItems, markRead, markUnread }; -} - -export function useInboxBadge(companyId: string | null | undefined) { - const { dismissed } = useDismissedInboxItems(); - - const { data: approvals = [] } = useQuery({ - queryKey: queryKeys.approvals.list(companyId!), - queryFn: () => approvalsApi.list(companyId!), - enabled: !!companyId, - }); - - const { data: joinRequests = [] } = useQuery({ - queryKey: queryKeys.access.joinRequests(companyId!), - queryFn: async () => { - try { - return await accessApi.listJoinRequests(companyId!, "pending_approval"); - } catch (err) { - if (err instanceof ApiError && (err.status === 401 || err.status === 403)) { - return []; - } - throw err; - } - }, - enabled: !!companyId, - retry: false, - }); - - const { data: dashboard } = useQuery({ - queryKey: queryKeys.dashboard(companyId!), - queryFn: () => dashboardApi.summary(companyId!), - enabled: !!companyId, - }); - - const { data: mineIssuesRaw = [] } = useQuery({ - queryKey: queryKeys.issues.listMineByMe(companyId!), - queryFn: () => - issuesApi.list(companyId!, { - touchedByUserId: "me", - inboxArchivedByUserId: "me", - status: INBOX_ISSUE_STATUSES, - }), - enabled: !!companyId, - }); - - const mineIssues = useMemo(() => getRecentTouchedIssues(mineIssuesRaw), [mineIssuesRaw]); - - const { data: heartbeatRuns = [] } = useQuery({ - queryKey: queryKeys.heartbeats(companyId!), - queryFn: () => heartbeatsApi.list(companyId!), - enabled: !!companyId, - }); - - return useMemo( - () => - computeInboxBadgeData({ - approvals, - joinRequests, - dashboard, - heartbeatRuns, - mineIssues, - dismissed, - }), - [approvals, joinRequests, dashboard, heartbeatRuns, mineIssues, dismissed], - ); -}