fix(webui): show platform-specific new chat shortcut
This commit is contained in:
@@ -55,12 +55,29 @@ interface SidebarProps {
|
||||
hostChromeInset?: boolean;
|
||||
}
|
||||
|
||||
type NavigatorWithUserAgentData = Navigator & {
|
||||
userAgentData?: { platform?: string };
|
||||
};
|
||||
|
||||
function isApplePlatform(): boolean {
|
||||
if (typeof navigator === "undefined") return false;
|
||||
const platform = navigator.platform || "";
|
||||
const userAgentPlatform =
|
||||
(navigator as NavigatorWithUserAgentData).userAgentData?.platform || "";
|
||||
return /mac|iphone|ipad|ipod/i.test(`${platform} ${userAgentPlatform}`);
|
||||
}
|
||||
|
||||
function newChatShortcutLabel(): string {
|
||||
return isApplePlatform() ? "⌘⇧O" : "Ctrl+Shift+O";
|
||||
}
|
||||
|
||||
export function Sidebar(props: SidebarProps) {
|
||||
const { t } = useTranslation();
|
||||
const [menuPortalContainer, setMenuPortalContainer] =
|
||||
useState<HTMLElement | null>(null);
|
||||
const collapsed = Boolean(props.collapsed);
|
||||
const toggleLabel = t("thread.header.toggleSidebar");
|
||||
const newChatShortcut = newChatShortcutLabel();
|
||||
|
||||
return (
|
||||
<nav
|
||||
@@ -124,7 +141,8 @@ export function Sidebar(props: SidebarProps) {
|
||||
label={t("sidebar.newChat")}
|
||||
onClick={props.onNewChat}
|
||||
icon={<SquarePen className="h-4 w-4" />}
|
||||
shortcut="Cmd/Ctrl+Shift+O"
|
||||
shortcut={newChatShortcut}
|
||||
ariaKeyShortcuts="Meta+Shift+O Control+Shift+O"
|
||||
/>
|
||||
<SidebarActionButton
|
||||
collapsed={collapsed}
|
||||
@@ -215,6 +233,7 @@ function SidebarActionButton({
|
||||
active = false,
|
||||
className,
|
||||
shortcut,
|
||||
ariaKeyShortcuts,
|
||||
}: {
|
||||
collapsed: boolean;
|
||||
label: string;
|
||||
@@ -223,6 +242,7 @@ function SidebarActionButton({
|
||||
active?: boolean;
|
||||
className?: string;
|
||||
shortcut?: string;
|
||||
ariaKeyShortcuts?: string;
|
||||
}) {
|
||||
const title = shortcut ? `${label} (${shortcut})` : collapsed ? label : undefined;
|
||||
|
||||
@@ -232,6 +252,7 @@ function SidebarActionButton({
|
||||
variant="ghost"
|
||||
aria-label={label}
|
||||
aria-current={active ? "page" : undefined}
|
||||
aria-keyshortcuts={ariaKeyShortcuts}
|
||||
title={title}
|
||||
onClick={() => onClick()}
|
||||
className={cn(
|
||||
|
||||
Reference in New Issue
Block a user