Skip to content

Commit 3b4b4bc

Browse files
committed
refactor(web): share command footer actions
1 parent 67c933b commit 3b4b4bc

5 files changed

Lines changed: 54 additions & 32 deletions

File tree

‎apps/web/src/components/CommandPalette.tsx‎

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,13 @@ import { isPreviewFocused } from "../lib/previewFocus";
9595
import { isTerminalFocused } from "../lib/terminalFocus";
9696
import { selectActiveRightPanel, useRightPanelStore } from "../rightPanelStore";
9797
import { getLatestThreadForProject, sortThreads } from "../lib/threadSort";
98-
import { cn, isMacPlatform, isWindowsPlatform, newProjectId } from "../lib/utils";
98+
import {
99+
cn,
100+
getLocalFileManagerName,
101+
isMacPlatform,
102+
isWindowsPlatform,
103+
newProjectId,
104+
} from "../lib/utils";
99105
import { selectThreadTerminalUiState, useTerminalUiStateStore } from "../terminalUiStateStore";
100106
import { buildThreadRouteParams, resolveThreadRouteTarget } from "../threadRoutes";
101107
import {
@@ -147,7 +153,7 @@ import {
147153
type ProviderInstanceEntry,
148154
} from "../providerInstances";
149155
import { resolveShortcutCommand, threadJumpIndexFromCommand } from "../keybindings";
150-
import { CommandDialog, CommandDialogPopup } from "./ui/command";
156+
import { CommandDialog, CommandDialogPopup, CommandFooterAction } from "./ui/command";
151157
import { Button } from "./ui/button";
152158
import { Kbd, KbdGroup } from "./ui/kbd";
153159
import { stackedThreadToast, toastManager } from "./ui/toast";
@@ -175,16 +181,6 @@ function projectFavicon(project: Project) {
175181
);
176182
}
177183

178-
function getLocalFileManagerName(platform: string): string {
179-
if (isMacPlatform(platform)) {
180-
return "Finder";
181-
}
182-
if (isWindowsPlatform(platform)) {
183-
return "Explorer";
184-
}
185-
return "Files";
186-
}
187-
188184
function getEnvironmentBrowsePlatform(os: string | null | undefined): string {
189185
if (os === "windows") {
190186
return "Win32";
@@ -2418,17 +2414,14 @@ function OpenCommandPaletteDialog(props: {
24182414
: undefined;
24192415

24202416
const footerTrailing = canOpenProjectFromFileManager ? (
2421-
<Button
2422-
variant="ghost"
2423-
size="xs"
2424-
className="h-auto px-2 text-muted-foreground text-xs hover:bg-transparent hover:text-foreground"
2417+
<CommandFooterAction
24252418
disabled={isPickingProjectFolder}
24262419
onClick={() => {
24272420
void handleOpenProjectFromFileManager();
24282421
}}
24292422
>
24302423
{`Open in ${fileManagerName}`}
2431-
</Button>
2424+
</CommandFooterAction>
24322425
) : null;
24332426

24342427
return (

‎apps/web/src/components/settings/ProjectFaviconPickerDialog.tsx‎

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useMemo, useState } from "react";
55

66
import { primaryServerKeybindingsAtom } from "~/state/server";
77
import { useTheme } from "~/hooks/useTheme";
8-
import { isMacPlatform, isWindowsPlatform } from "~/lib/utils";
8+
import { getLocalFileManagerName, isWindowsPlatform } from "~/lib/utils";
99
import { CommandPaletteContent } from "../CommandPaletteContent";
1010
import type { CommandPaletteActionItem } from "../CommandPalette.logic";
1111
import { CommandPaletteResults } from "../CommandPaletteResults";
@@ -15,8 +15,7 @@ import {
1515
PROJECT_FILE_PICKER_RESULT_LIMIT,
1616
} from "../files/ProjectFilePicker.logic";
1717
import { useProjectFilePickerQuery } from "../files/projectFilesQueryState";
18-
import { Button } from "../ui/button";
19-
import { CommandDialog, CommandDialogPopup } from "../ui/command";
18+
import { CommandDialog, CommandDialogPopup, CommandFooterAction } from "../ui/command";
2019
import { toastManager } from "../ui/toast";
2120

2221
function emptyMessage(query: string, error: string | null, isPending: boolean): string {
@@ -50,12 +49,9 @@ export function ProjectFaviconPickerDialog(props: {
5049
const { resolvedTheme } = useTheme();
5150
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
5251
const pickExternal = props.onPickExternal;
53-
const fileManagerName =
54-
typeof navigator !== "undefined" && isMacPlatform(navigator.platform)
55-
? "Finder"
56-
: typeof navigator !== "undefined" && isWindowsPlatform(navigator.platform)
57-
? "Explorer"
58-
: "Files";
52+
const fileManagerName = getLocalFileManagerName(
53+
typeof navigator === "undefined" ? "" : navigator.platform,
54+
);
5955
const items = useMemo<CommandPaletteActionItem[]>(
6056
() =>
6157
getProjectFilePickerMatches(result.entries, result.matchedQuery).map((match) => ({
@@ -85,10 +81,7 @@ export function ProjectFaviconPickerDialog(props: {
8581
footerActionLabel="Select icon"
8682
footerTrailing={
8783
pickExternal ? (
88-
<Button
89-
variant="ghost"
90-
size="xs"
91-
className="h-auto px-2 text-muted-foreground text-xs hover:bg-transparent hover:text-foreground"
84+
<CommandFooterAction
9285
disabled={isPickingExternal}
9386
onClick={() => {
9487
setIsPickingExternal(true);
@@ -110,7 +103,7 @@ export function ProjectFaviconPickerDialog(props: {
110103
}}
111104
>
112105
{`Open in ${fileManagerName}`}
113-
</Button>
106+
</CommandFooterAction>
114107
) : null
115108
}
116109
inputProps={{ placeholder: "Search image files…" }}

‎apps/web/src/components/ui/command.tsx‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
AutocompleteSeparator,
1717
} from "~/components/ui/autocomplete";
1818
import { DIALOG_BACKDROP_CLASS, DIALOG_POPUP_CLASS } from "~/components/ui/dialog-styles";
19+
import { Button } from "~/components/ui/button";
1920

2021
const CommandDialog = CommandDialogPrimitive.Root;
2122

@@ -225,6 +226,20 @@ function CommandFooter({ className, ...props }: React.ComponentProps<"div">) {
225226
);
226227
}
227228

229+
function CommandFooterAction({
230+
className,
231+
...props
232+
}: Omit<React.ComponentProps<typeof Button>, "size" | "variant">) {
233+
return (
234+
<Button
235+
{...props}
236+
variant="ghost-muted"
237+
size="xs"
238+
className={cn("h-auto px-2 text-xs hover:bg-transparent", className)}
239+
/>
240+
);
241+
}
242+
228243
export {
229244
CommandCreateHandle,
230245
Command,
@@ -234,6 +249,7 @@ export {
234249
CommandDialogTrigger,
235250
CommandEmpty,
236251
CommandFooter,
252+
CommandFooterAction,
237253
CommandGroup,
238254
CommandGroupLabel,
239255
CommandInput,

‎apps/web/src/lib/utils.test.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import { describe, assert, it } from "vite-plus/test";
2-
import { isWindowsPlatform } from "./utils";
2+
import { getLocalFileManagerName, isWindowsPlatform } from "./utils";
3+
4+
describe("getLocalFileManagerName", () => {
5+
it.each([
6+
["MacIntel", "Finder"],
7+
["Win32", "Explorer"],
8+
["Linux", "Files"],
9+
])("uses the %s file manager name", (platform, expected) => {
10+
assert.strictEqual(getLocalFileManagerName(platform), expected);
11+
});
12+
});
313

414
describe("isWindowsPlatform", () => {
515
it("matches Windows platform identifiers", () => {

‎apps/web/src/lib/utils.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ export function isLinuxPlatform(platform: string): boolean {
2020
return /linux/i.test(platform);
2121
}
2222

23+
export function getLocalFileManagerName(platform: string): string {
24+
if (isMacPlatform(platform)) {
25+
return "Finder";
26+
}
27+
if (isWindowsPlatform(platform)) {
28+
return "Explorer";
29+
}
30+
return "Files";
31+
}
32+
2333
export function randomHex(byteLength: number): string {
2434
return Encoding.encodeHex(globalThis.crypto.getRandomValues(new Uint8Array(byteLength)));
2535
}

0 commit comments

Comments
 (0)