Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui2): separate hotkeys #88726

Merged
merged 4 commits into from
Apr 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 19 additions & 31 deletions static/app/utils/theme/useThemeSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,19 @@ export function useThemeSwitcher(): DO_NOT_USE_ChonkTheme | Theme {
}, [config.theme, organization, previousTheme, setChonkTheme]);

// Hotkey definition for toggling the current theme
const currentThemeHotkey = useMemo(
const darkModeHotkey = useMemo(
() => ({
match: ['command+shift+1', 'ctrl+shift+1'],
includeInputs: true,
callback: () => {
removeBodyTheme();
if (chonkTheme.theme) {
addMessage(`Using default theme`, 'success');
setChonkTheme({
theme: chonkTheme.theme === 'dark' ? 'light' : 'dark',
});
} else {
ConfigStore.set('theme', config.theme === 'dark' ? 'light' : 'dark');
}
ConfigStore.set(
'theme',
chonkTheme.theme === null
? config.theme === 'dark'
? 'light'
: 'dark'
: chonkTheme.theme === 'dark'
? 'dark'
: 'light'
);
setChonkTheme({theme: null});
},
}),
[chonkTheme.theme, config.theme, setChonkTheme]
Expand All @@ -81,33 +74,28 @@ export function useThemeSwitcher(): DO_NOT_USE_ChonkTheme | Theme {
match: ['command+shift+2', 'ctrl+shift+2'],
includeInputs: true,
callback: () => {
removeBodyTheme();
if (!chonkTheme.theme) {
if (chonkTheme.theme) {
addMessage(`Using default theme`, 'success');
ConfigStore.set('theme', chonkTheme.theme);
setChonkTheme({
theme: null,
});
} else {
addMessage(`Previewing new theme`, 'success');
setChonkTheme({
theme: config.theme,
});
}
setChonkTheme({
theme:
// A bit of extra logic to ensure that toggling from chonk to legacy and
// vice versa persists the current theme. This makes it easier to look for UI
// changes as we can quickly swap between light or dark themes.
chonkTheme.theme === null
? config.theme === 'dark'
? 'dark'
: 'light'
: chonkTheme.theme === 'dark'
? 'light'
: 'dark',
});
},
}),
[chonkTheme.theme, config.theme, setChonkTheme]
);

const themeToggleHotkeys = useMemo(() => {
return organization?.features?.includes('chonk-ui')
? [currentThemeHotkey, chonkThemeHotkey]
: [currentThemeHotkey];
}, [organization, chonkThemeHotkey, currentThemeHotkey]);
? [darkModeHotkey, chonkThemeHotkey]
: [darkModeHotkey];
}, [organization, chonkThemeHotkey, darkModeHotkey]);

useHotkeys(themeToggleHotkeys);
return theme;
Expand Down
Loading