summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/context
diff options
context:
space:
mode:
Diffstat (limited to 'packages/app/src/context')
-rw-r--r--packages/app/src/context/global-sync.test.ts8
-rw-r--r--packages/app/src/context/global-sync.tsx3
-rw-r--r--packages/app/src/context/notification-index.ts66
-rw-r--r--packages/app/src/context/notification.test.ts73
4 files changed, 2 insertions, 148 deletions
diff --git a/packages/app/src/context/global-sync.test.ts b/packages/app/src/context/global-sync.test.ts
index 7956057fd..93e9c4175 100644
--- a/packages/app/src/context/global-sync.test.ts
+++ b/packages/app/src/context/global-sync.test.ts
@@ -1,10 +1,6 @@
import { describe, expect, test } from "bun:test"
-import {
- canDisposeDirectory,
- estimateRootSessionTotal,
- loadRootSessionsWithFallback,
- pickDirectoriesToEvict,
-} from "./global-sync"
+import { canDisposeDirectory, pickDirectoriesToEvict } from "./global-sync/eviction"
+import { estimateRootSessionTotal, loadRootSessionsWithFallback } from "./global-sync/session-load"
describe("pickDirectoriesToEvict", () => {
test("keeps pinned stores and evicts idle stores", () => {
diff --git a/packages/app/src/context/global-sync.tsx b/packages/app/src/context/global-sync.tsx
index 4090699a8..645bd678b 100644
--- a/packages/app/src/context/global-sync.tsx
+++ b/packages/app/src/context/global-sync.tsx
@@ -402,6 +402,3 @@ export function useGlobalSync() {
if (!context) throw new Error("useGlobalSync must be used within GlobalSyncProvider")
return context
}
-
-export { canDisposeDirectory, pickDirectoriesToEvict } from "./global-sync/eviction"
-export { estimateRootSessionTotal, loadRootSessionsWithFallback } from "./global-sync/session-load"
diff --git a/packages/app/src/context/notification-index.ts b/packages/app/src/context/notification-index.ts
deleted file mode 100644
index 0b316e7ec..000000000
--- a/packages/app/src/context/notification-index.ts
+++ /dev/null
@@ -1,66 +0,0 @@
-type NotificationIndexItem = {
- directory?: string
- session?: string
- viewed: boolean
- type: string
-}
-
-export function buildNotificationIndex<T extends NotificationIndexItem>(list: T[]) {
- const sessionAll = new Map<string, T[]>()
- const sessionUnseen = new Map<string, T[]>()
- const sessionUnseenCount = new Map<string, number>()
- const sessionUnseenHasError = new Map<string, boolean>()
- const projectAll = new Map<string, T[]>()
- const projectUnseen = new Map<string, T[]>()
- const projectUnseenCount = new Map<string, number>()
- const projectUnseenHasError = new Map<string, boolean>()
-
- for (const notification of list) {
- const session = notification.session
- if (session) {
- const all = sessionAll.get(session)
- if (all) all.push(notification)
- else sessionAll.set(session, [notification])
-
- if (!notification.viewed) {
- const unseen = sessionUnseen.get(session)
- if (unseen) unseen.push(notification)
- else sessionUnseen.set(session, [notification])
-
- sessionUnseenCount.set(session, (sessionUnseenCount.get(session) ?? 0) + 1)
- if (notification.type === "error") sessionUnseenHasError.set(session, true)
- }
- }
-
- const directory = notification.directory
- if (directory) {
- const all = projectAll.get(directory)
- if (all) all.push(notification)
- else projectAll.set(directory, [notification])
-
- if (!notification.viewed) {
- const unseen = projectUnseen.get(directory)
- if (unseen) unseen.push(notification)
- else projectUnseen.set(directory, [notification])
-
- projectUnseenCount.set(directory, (projectUnseenCount.get(directory) ?? 0) + 1)
- if (notification.type === "error") projectUnseenHasError.set(directory, true)
- }
- }
- }
-
- return {
- session: {
- all: sessionAll,
- unseen: sessionUnseen,
- unseenCount: sessionUnseenCount,
- unseenHasError: sessionUnseenHasError,
- },
- project: {
- all: projectAll,
- unseen: projectUnseen,
- unseenCount: projectUnseenCount,
- unseenHasError: projectUnseenHasError,
- },
- }
-}
diff --git a/packages/app/src/context/notification.test.ts b/packages/app/src/context/notification.test.ts
deleted file mode 100644
index 44bacb704..000000000
--- a/packages/app/src/context/notification.test.ts
+++ /dev/null
@@ -1,73 +0,0 @@
-import { describe, expect, test } from "bun:test"
-import { buildNotificationIndex } from "./notification-index"
-
-type Notification = {
- type: "turn-complete" | "error"
- session: string
- directory: string
- viewed: boolean
- time: number
-}
-
-const turn = (session: string, directory: string, viewed = false): Notification => ({
- type: "turn-complete",
- session,
- directory,
- viewed,
- time: 1,
-})
-
-const error = (session: string, directory: string, viewed = false): Notification => ({
- type: "error",
- session,
- directory,
- viewed,
- time: 1,
-})
-
-describe("buildNotificationIndex", () => {
- test("builds unseen counts and unseen error flags", () => {
- const list = [
- turn("s1", "d1", false),
- error("s1", "d1", false),
- turn("s1", "d1", true),
- turn("s2", "d1", false),
- error("s3", "d2", true),
- ]
-
- const index = buildNotificationIndex(list)
-
- expect(index.session.all.get("s1")?.length).toBe(3)
- expect(index.session.unseen.get("s1")?.length).toBe(2)
- expect(index.session.unseenCount.get("s1")).toBe(2)
- expect(index.session.unseenHasError.get("s1")).toBe(true)
-
- expect(index.session.unseenCount.get("s2")).toBe(1)
- expect(index.session.unseenHasError.get("s2") ?? false).toBe(false)
- expect(index.session.unseenCount.get("s3") ?? 0).toBe(0)
- expect(index.session.unseenHasError.get("s3") ?? false).toBe(false)
-
- expect(index.project.unseenCount.get("d1")).toBe(3)
- expect(index.project.unseenHasError.get("d1")).toBe(true)
- expect(index.project.unseenCount.get("d2") ?? 0).toBe(0)
- expect(index.project.unseenHasError.get("d2") ?? false).toBe(false)
- })
-
- test("updates selectors after viewed transitions", () => {
- const list = [turn("s1", "d1", false), error("s1", "d1", false), turn("s2", "d1", false)]
- const next = list.map((item) => (item.session === "s1" ? { ...item, viewed: true } : item))
-
- const before = buildNotificationIndex(list)
- const after = buildNotificationIndex(next)
-
- expect(before.session.unseenCount.get("s1")).toBe(2)
- expect(before.session.unseenHasError.get("s1")).toBe(true)
- expect(before.project.unseenCount.get("d1")).toBe(3)
- expect(before.project.unseenHasError.get("d1")).toBe(true)
-
- expect(after.session.unseenCount.get("s1") ?? 0).toBe(0)
- expect(after.session.unseenHasError.get("s1") ?? false).toBe(false)
- expect(after.project.unseenCount.get("d1")).toBe(1)
- expect(after.project.unseenHasError.get("d1") ?? false).toBe(false)
- })
-})