Skip to content

Commit a13691b

Browse files
thomaspblockcursoragentwesbillmanBrain
authored
Polish desktop profile menu interactions (#836)
Signed-off-by: Wes <[email protected]> Co-authored-by: Cursor <[email protected]> Co-authored-by: Wes <[email protected]> Co-authored-by: Brain <21994759fc7a6fa6b965551d35cfd7897d262f2495467f2d78694ddcfa6a5c7e@sprout-oss.stage.blox.sqprod.co>
1 parent 0d9b814 commit a13691b

15 files changed

Lines changed: 774 additions & 389 deletions

File tree

‎desktop/src/app/AppShell.tsx‎

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { AppTopChrome } from "@/app/AppTopChrome";
1212
import { useAppNavigation } from "@/app/navigation/useAppNavigation";
1313
import { useBackForwardControls } from "@/app/navigation/useBackForwardControls";
1414
import { useMarkAsReadShortcuts } from "@/app/useMarkAsReadShortcuts";
15+
import { useSettingsShortcuts } from "@/app/useSettingsShortcuts";
1516
import { useWebviewZoomShortcuts } from "@/app/useWebviewZoomShortcuts";
1617
import {
1718
channelsQueryKey,
@@ -170,6 +171,9 @@ export function AppShell() {
170171
const [settingsSection, setSettingsSection] = React.useState<SettingsSection>(
171172
DEFAULT_SETTINGS_SECTION,
172173
);
174+
const [settingsMode, setSettingsMode] = React.useState<
175+
"profile" | "preferences"
176+
>("preferences");
173177

174178
const [isChannelManagementOpen, setIsChannelManagementOpen] =
175179
React.useState(false);
@@ -407,8 +411,9 @@ export function AppShell() {
407411
);
408412

409413
const handleOpenSettings = React.useCallback(
410-
(section: SettingsSection = DEFAULT_SETTINGS_SECTION) => {
414+
(section: SettingsSection = "appearance") => {
411415
setIsChannelManagementOpen(false);
416+
setSettingsMode(section === "profile" ? "profile" : "preferences");
412417
setSettingsSection(section);
413418
setSettingsOpen(true);
414419
},
@@ -601,32 +606,11 @@ export function AppShell() {
601606
settingsOpen,
602607
]);
603608

604-
React.useLayoutEffect(() => {
605-
function handleKeyDown(event: KeyboardEvent) {
606-
const isSettingsShortcut =
607-
(event.key === "," || event.code === "Comma") &&
608-
hasPrimaryShortcutModifier(event) &&
609-
!event.altKey &&
610-
!event.shiftKey;
611-
612-
if (!isSettingsShortcut) {
613-
return;
614-
}
615-
616-
event.preventDefault();
617-
if (settingsOpen) {
618-
handleCloseSettings();
619-
return;
620-
}
621-
622-
handleOpenSettings();
623-
}
624-
625-
window.addEventListener("keydown", handleKeyDown);
626-
return () => {
627-
window.removeEventListener("keydown", handleKeyDown);
628-
};
629-
}, [handleCloseSettings, handleOpenSettings, settingsOpen]);
609+
useSettingsShortcuts({
610+
onClose: handleCloseSettings,
611+
onOpenSettings: handleOpenSettings,
612+
open: settingsOpen,
613+
});
630614

631615
useMarkAsReadShortcuts({
632616
activeChannelId: activeChannel?.id ?? null,
@@ -862,6 +846,7 @@ export function AppShell() {
862846
notificationSettings={notificationSettings.settings}
863847
onClose={handleCloseSettings}
864848
onSectionChange={setSettingsSection}
849+
mode={settingsMode}
865850
onSetDesktopNotificationsEnabled={
866851
notificationSettings.setDesktopEnabled
867852
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import * as React from "react";
2+
3+
import { hasPrimaryShortcutModifier } from "@/shared/lib/platform";
4+
5+
type UseSettingsShortcutsOptions = {
6+
onClose: () => void;
7+
onOpenSettings: () => void;
8+
open: boolean;
9+
};
10+
11+
export function useSettingsShortcuts({
12+
onClose,
13+
onOpenSettings,
14+
open,
15+
}: UseSettingsShortcutsOptions) {
16+
React.useLayoutEffect(() => {
17+
function handleKeyDown(event: KeyboardEvent) {
18+
const isSettingsShortcut =
19+
hasPrimaryShortcutModifier(event) &&
20+
!event.altKey &&
21+
!event.shiftKey &&
22+
(event.key === "," || event.code === "Comma");
23+
24+
if (!isSettingsShortcut) {
25+
return;
26+
}
27+
28+
event.preventDefault();
29+
if (open) {
30+
onClose();
31+
return;
32+
}
33+
34+
onOpenSettings();
35+
}
36+
37+
window.addEventListener("keydown", handleKeyDown);
38+
return () => {
39+
window.removeEventListener("keydown", handleKeyDown);
40+
};
41+
}, [onClose, onOpenSettings, open]);
42+
}

0 commit comments

Comments
 (0)