diff options
| author | Adam <[email protected]> | 2025-12-30 04:57:28 -0600 |
|---|---|---|
| committer | Adam <[email protected]> | 2025-12-30 04:57:37 -0600 |
| commit | a576fdb5e4ecddc73dede97ff26239d90c94e72f (patch) | |
| tree | f44d10ff36b1ecc6aa8e8222d0a9b9bf3f4221fc /packages/app/src/pages | |
| parent | ae53f876f1e201363415279826e820b2e7769f56 (diff) | |
| download | opencode-a576fdb5e4ecddc73dede97ff26239d90c94e72f.tar.gz opencode-a576fdb5e4ecddc73dede97ff26239d90c94e72f.zip | |
feat(web): open projects
Diffstat (limited to 'packages/app/src/pages')
| -rw-r--r-- | packages/app/src/pages/home.tsx | 48 | ||||
| -rw-r--r-- | packages/app/src/pages/layout.tsx | 94 |
2 files changed, 79 insertions, 63 deletions
diff --git a/packages/app/src/pages/home.tsx b/packages/app/src/pages/home.tsx index 7cd2916e8..129a50320 100644 --- a/packages/app/src/pages/home.tsx +++ b/packages/app/src/pages/home.tsx @@ -8,11 +8,14 @@ import { base64Encode } from "@opencode-ai/util/encode" import { Icon } from "@opencode-ai/ui/icon" import { usePlatform } from "@/context/platform" import { DateTime } from "luxon" +import { useDialog } from "@opencode-ai/ui/context/dialog" +import { DialogSelectDirectory } from "@/components/dialog-select-directory" export default function Home() { const sync = useGlobalSync() const layout = useLayout() const platform = usePlatform() + const dialog = useDialog() const navigate = useNavigate() const homedir = createMemo(() => sync.data.path.home) @@ -22,16 +25,27 @@ export default function Home() { } async function chooseProject() { - const result = await platform.openDirectoryPickerDialog?.({ - title: "Open project", - multiple: true, - }) - if (Array.isArray(result)) { - for (const directory of result) { - openProject(directory) + function resolve(result: string | string[] | null) { + if (Array.isArray(result)) { + for (const directory of result) { + openProject(directory) + } + } else if (result) { + openProject(result) } - } else if (result) { - openProject(result) + } + + if (platform.openDirectoryPickerDialog) { + const result = await platform.openDirectoryPickerDialog?.({ + title: "Open project", + multiple: true, + }) + resolve(result) + } else { + dialog.show( + () => <DialogSelectDirectory multiple={true} onSelect={resolve} />, + () => resolve(null), + ) } } @@ -43,11 +57,9 @@ export default function Home() { <div class="mt-20 w-full flex flex-col gap-4"> <div class="flex gap-2 items-center justify-between pl-3"> <div class="text-14-medium text-text-strong">Recent projects</div> - <Show when={platform.openDirectoryPickerDialog}> - <Button icon="folder-add-left" size="normal" class="pl-2 pr-3" onClick={chooseProject}> - Open project - </Button> - </Show> + <Button icon="folder-add-left" size="normal" class="pl-2 pr-3" onClick={chooseProject}> + Open project + </Button> </div> <ul class="flex flex-col gap-2"> <For @@ -80,11 +92,9 @@ export default function Home() { <div class="text-12-regular text-text-weak">Get started by opening a local project</div> </div> <div /> - <Show when={platform.openDirectoryPickerDialog}> - <Button class="px-3" onClick={chooseProject}> - Open project - </Button> - </Show> + <Button class="px-3" onClick={chooseProject}> + Open project + </Button> </div> </Match> </Switch> diff --git a/packages/app/src/pages/layout.tsx b/packages/app/src/pages/layout.tsx index 480c5eddf..46ea3bd4d 100644 --- a/packages/app/src/pages/layout.tsx +++ b/packages/app/src/pages/layout.tsx @@ -52,6 +52,7 @@ import { DialogSelectProvider } from "@/components/dialog-select-provider" import { DialogEditProject } from "@/components/dialog-edit-project" import { useCommand, type CommandOption } from "@/context/command" import { ConstrainDragXAxis } from "@/utils/solid-dnd" +import { DialogSelectDirectory } from "@/components/dialog-select-directory" export default function Layout(props: ParentProps) { const [store, setStore] = createStore({ @@ -338,17 +339,13 @@ export default function Layout(props: ParentProps) { keybind: "mod+b", onSelect: () => layout.sidebar.toggle(), }, - ...(platform.openDirectoryPickerDialog - ? [ - { - id: "project.open", - title: "Open project", - category: "Project", - keybind: "mod+o", - onSelect: () => chooseProject(), - }, - ] - : []), + { + id: "project.open", + title: "Open project", + category: "Project", + keybind: "mod+o", + onSelect: () => chooseProject(), + }, { id: "provider.connect", title: "Connect provider", @@ -457,17 +454,28 @@ export default function Layout(props: ParentProps) { } async function chooseProject() { - const result = await platform.openDirectoryPickerDialog?.({ - title: "Open project", - multiple: true, - }) - if (Array.isArray(result)) { - for (const directory of result) { - openProject(directory, false) + function resolve(result: string | string[] | null) { + if (Array.isArray(result)) { + for (const directory of result) { + openProject(directory, false) + } + navigateToProject(result[0]) + } else if (result) { + openProject(result) } - navigateToProject(result[0]) - } else if (result) { - openProject(result) + } + + if (platform.openDirectoryPickerDialog) { + const result = await platform.openDirectoryPickerDialog?.({ + title: "Open project", + multiple: true, + }) + resolve(result) + } else { + dialog.show( + () => <DialogSelectDirectory multiple={true} onSelect={resolve} />, + () => resolve(null), + ) } } @@ -955,30 +963,28 @@ export default function Layout(props: ParentProps) { </Tooltip> </Match> </Switch> - <Show when={platform.openDirectoryPickerDialog}> - <Tooltip - placement="right" - value={ - <div class="flex items-center gap-2"> - <span>Open project</span> - <Show when={!sidebarProps.mobile}> - <span class="text-icon-base text-12-medium">{command.keybind("project.open")}</span> - </Show> - </div> - } - inactive={expanded()} + <Tooltip + placement="right" + value={ + <div class="flex items-center gap-2"> + <span>Open project</span> + <Show when={!sidebarProps.mobile}> + <span class="text-icon-base text-12-medium">{command.keybind("project.open")}</span> + </Show> + </div> + } + inactive={expanded()} + > + <Button + class="flex w-full text-left justify-start text-text-base stroke-[1.5px] rounded-lg px-2" + variant="ghost" + size="large" + icon="folder-add-left" + onClick={chooseProject} > - <Button - class="flex w-full text-left justify-start text-text-base stroke-[1.5px] rounded-lg px-2" - variant="ghost" - size="large" - icon="folder-add-left" - onClick={chooseProject} - > - <Show when={expanded()}>Open project</Show> - </Button> - </Tooltip> - </Show> + <Show when={expanded()}>Open project</Show> + </Button> + </Tooltip> <Tooltip placement="right" value="Share feedback" inactive={expanded()}> <Button as={"a"} |
