Skip to content

Commit 38b406f

Browse files
authored
app: Initial tabs impl (anomalyco#28436)
1 parent 4702cdd commit 38b406f

86 files changed

Lines changed: 10780 additions & 598 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/app/src/components/titlebar.tsx

Lines changed: 362 additions & 142 deletions
Large diffs are not rendered by default.

packages/app/src/context/directory-sync.ts

Lines changed: 596 additions & 0 deletions
Large diffs are not rendered by default.

packages/app/src/context/global-sync.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { queryOptions, useMutation, useQueries, useQuery, useQueryClient } from
3636
import { createRefreshQueue } from "./global-sync/queue"
3737
import { directoryKey } from "./global-sync/utils"
3838
import { PathKey } from "@/utils/path-key"
39+
import { createDirSyncContext } from "./directory-sync"
3940

4041
type GlobalStore = {
4142
ready: boolean
@@ -431,6 +432,9 @@ function createGlobalSync() {
431432
},
432433
}))
433434

435+
const dirSyncContexts = new Map<string, ReturnType<typeof createDirSyncContext>>()
436+
const dirSyncContextRefCounts = new Map<string, number>()
437+
434438
return {
435439
data: globalStore,
436440
set,
@@ -449,6 +453,26 @@ function createGlobalSync() {
449453
todo: {
450454
set: setSessionTodo,
451455
},
456+
createDirSyncContext: (directory: string) => {
457+
onCleanup(() => {
458+
dirSyncContextRefCounts.set(directory, (dirSyncContextRefCounts.get(directory) ?? 0) - 1)
459+
if (dirSyncContextRefCounts.get(directory) === 0) {
460+
dirSyncContexts.delete(directory)
461+
dirSyncContextRefCounts.delete(directory)
462+
}
463+
})
464+
465+
const cached = dirSyncContexts.get(directory)
466+
if (cached) {
467+
dirSyncContextRefCounts.set(directory, (dirSyncContextRefCounts.get(directory) ?? 0) + 1)
468+
return cached
469+
}
470+
const ctx = createDirSyncContext(globalSDK.createClient({ directory, throwOnError: true }), directory)
471+
dirSyncContexts.set(directory, ctx)
472+
dirSyncContextRefCounts.set(directory, 1)
473+
474+
return ctx
475+
},
452476
}
453477
}
454478

0 commit comments

Comments
 (0)