|
1 | 1 | import { platform } from "@yaakapp-internal/platform"; |
2 | | -import type { SettingsTab } from "../components/Settings/Settings"; |
| 2 | +import type { SettingsTab, SettingsTabWithSubtab } from "../components/Settings/Settings"; |
3 | 3 | import { activeWorkspaceIdAtom } from "../hooks/useActiveWorkspace"; |
4 | 4 | import { createFastMutation } from "../hooks/useFastMutation"; |
| 5 | +import { showDialog } from "../lib/dialog"; |
5 | 6 | import { jotaiStore } from "../lib/jotai"; |
6 | 7 | import { router } from "../lib/router"; |
7 | 8 | import { rpc } from "../lib/rpc"; |
8 | 9 |
|
9 | | -// Allow tab with optional subtab (e.g., "plugins:installed") |
10 | | -type SettingsTabWithSubtab = SettingsTab | `${SettingsTab}:${string}` | null; |
11 | | - |
12 | | -export const openSettings = createFastMutation<void, string, SettingsTabWithSubtab>({ |
| 10 | +export const openSettings = createFastMutation<void, string, SettingsTabWithSubtab | null>({ |
13 | 11 | mutationKey: ["open_settings"], |
14 | 12 | mutationFn: async (tab) => { |
15 | 13 | const workspaceId = jotaiStore.get(activeWorkspaceIdAtom); |
16 | 14 | if (workspaceId == null) return; |
17 | 15 |
|
18 | | - const to = "/workspaces/$workspaceId/settings" as const; |
19 | | - const params = { workspaceId }; |
20 | | - const search = { tab: (tab ?? undefined) as SettingsTab | undefined }; |
21 | | - |
22 | 16 | // Settings is its own window where the host has windows to give. Where it |
23 | | - // doesn't — a browser tab — the same route opens in place, which is the |
24 | | - // whole difference: it is already a route, not a separate app. |
| 17 | + // doesn't — a browser tab — it's a dialog like any other, so opening it |
| 18 | + // doesn't take you away from the request you were working on. |
25 | 19 | if (!platform.capabilities.multiWindow) { |
26 | | - await router.navigate({ to, params, search }); |
| 20 | + // Imported here so Settings stays out of the startup bundle, the way the |
| 21 | + // route that renders it on desktop already keeps it |
| 22 | + const { default: Settings } = await import("../components/Settings/Settings"); |
| 23 | + showDialog({ |
| 24 | + id: "settings", |
| 25 | + size: "md", |
| 26 | + className: "h-[calc(100vh-5rem)] max-h-150! overflow-hidden", |
| 27 | + noPadding: true, |
| 28 | + noScroll: true, |
| 29 | + // Keyed so opening a specific tab while the dialog is already up moves to it |
| 30 | + render: ({ hide }) => <Settings key={tab ?? "general"} tab={tab} hide={hide} />, |
| 31 | + }); |
27 | 32 | return; |
28 | 33 | } |
29 | 34 |
|
30 | | - const location = router.buildLocation({ to, params, search }); |
| 35 | + const location = router.buildLocation({ |
| 36 | + to: "/workspaces/$workspaceId/settings", |
| 37 | + params: { workspaceId }, |
| 38 | + search: { tab: (tab ?? undefined) as SettingsTab | undefined }, |
| 39 | + }); |
31 | 40 |
|
32 | 41 | await rpc("cmd_new_child_window", { |
33 | 42 | url: location.href, |
|
0 commit comments