Skip to content

Commit da436ce

Browse files
committed
cleanup
1 parent 24ab053 commit da436ce

6 files changed

Lines changed: 23 additions & 30 deletions

File tree

packages/app/src/components/dialog-select-mcp.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const DialogSelectMcp: Component = () => {
3333
if (sync.data.mcp[name]?.status === "connected") await sdk.client.mcp.disconnect({ name })
3434
else await sdk.client.mcp.connect({ name })
3535
},
36-
onSuccess: () => queryClient.refetchQueries({ queryKey: queryOptions.mcp(sync.directory).queryKey }),
36+
onSuccess: () => queryClient.refetchQueries(queryOptions.mcp(sync.directory)),
3737
}))
3838

3939
const enabledCount = createMemo(() => items().filter((i) => i.status === "connected").length)

packages/app/src/components/status-popover-body.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ const useMcpToggleMutation = () => {
146146
const status = sync.data.mcp[name]
147147
await (status?.status === "connected" ? sdk.client.mcp.disconnect({ name }) : sdk.client.mcp.connect({ name }))
148148
},
149-
onSuccess: () => queryClient.refetchQueries({ queryKey: queryOptions.mcp(sync.directory).queryKey }),
149+
onSuccess: () => queryClient.refetchQueries(queryOptions.mcp(sync.directory)),
150150
onError: (err) => {
151151
showToast({
152152
variant: "error",

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ export const loadLspQuery = (directory: string, sdk: OpencodeClient) =>
6262
queryFn: () => sdk.lsp.status().then((r) => r.data ?? []),
6363
})
6464

65+
function makeQueryOptionsApi(globalSDK: () => OpencodeClient, sdkFor: (dir: string) => OpencodeClient) {
66+
return {
67+
globalConfig: () => loadGlobalConfigQuery(globalSDK()),
68+
projects: () => loadProjectsQuery(globalSDK()),
69+
providers: (directory: string | null) =>
70+
loadProvidersQuery(directory, directory === null ? globalSDK() : sdkFor(directory)),
71+
path: (directory: string | null) => loadPathQuery(directory, directory === null ? globalSDK() : sdkFor(directory)),
72+
agents: (directory: string) => loadAgentsQuery(directory, sdkFor(directory)),
73+
mcp: (directory: string) => loadMcpQuery(directory, sdkFor(directory)),
74+
lsp: (directory: string) => loadLspQuery(directory, sdkFor(directory)),
75+
sessions: (directory: string) => ({ queryKey: [directory, "loadSessions"] as const }),
76+
}
77+
}
78+
export type QueryOptionsApi = ReturnType<typeof makeQueryOptionsApi>
79+
6580
function createGlobalSync() {
6681
const globalSDK = useGlobalSDK()
6782
const language = useLanguage()
@@ -85,18 +100,7 @@ function createGlobalSync() {
85100
return sdk
86101
}
87102

88-
const queryOptionsApi = {
89-
globalConfig: () => loadGlobalConfigQuery(globalSDK.client),
90-
projects: () => loadProjectsQuery(globalSDK.client),
91-
providers: (directory: string | null) =>
92-
loadProvidersQuery(directory, directory === null ? globalSDK.client : sdkFor(directory)),
93-
path: (directory: string | null) =>
94-
loadPathQuery(directory, directory === null ? globalSDK.client : sdkFor(directory)),
95-
agents: (directory: string) => loadAgentsQuery(directory, sdkFor(directory)),
96-
mcp: (directory: string) => loadMcpQuery(directory, sdkFor(directory)),
97-
lsp: (directory: string) => loadLspQuery(directory, sdkFor(directory)),
98-
sessions: (directory: string) => ({ queryKey: [directory, "loadSessions"] as const }),
99-
}
103+
const queryOptionsApi = makeQueryOptionsApi(() => globalSDK.client, sdkFor)
100104

101105
const [configQuery, providerQuery, pathQuery] = useQueries(() => ({
102106
queries: [queryOptionsApi.globalConfig(), queryOptionsApi.providers(null), queryOptionsApi.path(null)],

packages/app/src/context/global-sync/child-store.test.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@ describe("createChildStoreManager", () => {
2222
onBootstrap() {},
2323
onDispose() {},
2424
translate: (key) => key,
25-
queryOptions: {
26-
lsp: () => null!,
27-
mcp: () => null!,
28-
path: () => null!,
29-
providers: () => null!,
30-
},
25+
queryOptions: {} as any,
3126
global: { provider: null! },
3227
})
3328

packages/app/src/context/global-sync/child-store.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import {
1515
} from "./types"
1616
import { canDisposeDirectory, pickDirectoriesToEvict } from "./eviction"
1717
import { useQueries } from "@tanstack/solid-query"
18-
import { loadPathQuery, loadProvidersQuery } from "./bootstrap"
19-
import { loadLspQuery, loadMcpQuery } from "../global-sync"
18+
import { QueryOptionsApi } from "../global-sync"
2019
import { directoryKey, type DirectoryKey } from "./utils"
2120

2221
export function createChildStoreManager(input: {
@@ -26,12 +25,7 @@ export function createChildStoreManager(input: {
2625
onBootstrap: (directory: string) => void
2726
onDispose: (directory: string) => void
2827
translate: (key: string, vars?: Record<string, string | number>) => string
29-
queryOptions: {
30-
lsp: (directory: string) => ReturnType<typeof loadLspQuery>
31-
mcp: (directory: string) => ReturnType<typeof loadMcpQuery>
32-
path: (directory: string) => ReturnType<typeof loadPathQuery>
33-
providers: (directory: string) => ReturnType<typeof loadProvidersQuery>
34-
}
28+
queryOptions: QueryOptionsApi
3529
global: {
3630
provider: ProviderListResponse
3731
}

packages/app/src/pages/layout/sidebar-workspace.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ export const SortableWorkspace = (props: {
321321
const boot = createMemo(() => open() || active())
322322
const count = createMemo(() => sessions()?.length ?? 0)
323323
const hasMore = createMemo(() => workspaceStore.sessionTotal > count())
324-
const fetching = useIsFetching(() => ({ queryKey: queryOptions.sessions(props.directory).queryKey }))
324+
const fetching = useIsFetching(() => queryOptions.sessions(props.directory))
325325
const busy = createMemo(() => props.ctx.isBusy(props.directory))
326326
const loading = () => fetching() > 0 && count() === 0
327327
const touch = createMediaQuery("(hover: none)")
@@ -456,7 +456,7 @@ export const LocalWorkspace = (props: {
456456
const slug = createMemo(() => base64Encode(props.project.worktree))
457457
const sessions = createMemo(() => sortedRootSessions(workspace().store, props.sortNow()))
458458
const count = createMemo(() => sessions()?.length ?? 0)
459-
const fetching = useIsFetching(() => ({ queryKey: queryOptions.sessions(props.project.worktree).queryKey }))
459+
const fetching = useIsFetching(() => queryOptions.sessions(props.project.worktree))
460460
const hasMore = createMemo(() => workspace().store.sessionTotal > count())
461461
const loading = () => fetching() > 0 && count() === 0
462462
const loadMore = async () => {

0 commit comments

Comments
 (0)