Skip to content

Commit

Permalink
[180] Deactivate the palette on the login and help page
Browse files Browse the repository at this point in the history
Bug: #180
Signed-off-by: Stéphane Bégaudeau <stephane.begaudeau@gmail.com>
  • Loading branch information
sbegaudeau committed Jun 28, 2023
1 parent 2ba6572 commit a1ae46e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion frontend/svalyn-studio-app/src/palette/PaletteProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import { useEffect, useState } from 'react';
import { useLocation } from 'react-router-dom';
import { actions } from './DefaultPaletteActions';
import { Palette } from './Palette';
import { PaletteAction } from './Palette.types';
Expand All @@ -28,7 +29,12 @@ import { PaletteProviderProps, PaletteProviderState } from './PaletteProvider.ty
export const PaletteProvider = ({ children }: PaletteProviderProps) => {
const [state, setState] = useState<PaletteProviderState>({ actions, open: false });

const location = useLocation();
useEffect(() => {
if (location.pathname === '/login' || location.pathname === '/help') {
return;
}

const keyDownEventListener = (event: KeyboardEvent) => {
if (event.key === 'k' && (event.ctrlKey || event.metaKey)) {
setState((prevState) => ({ ...prevState, open: !prevState.open }));
Expand All @@ -39,7 +45,7 @@ export const PaletteProvider = ({ children }: PaletteProviderProps) => {

document.addEventListener('keydown', keyDownEventListener);
return () => document.removeEventListener('keydown', keyDownEventListener);
}, []);
}, [location]);

const handleClose = () => setState((prevState) => ({ ...prevState, open: false }));

Expand Down

0 comments on commit a1ae46e

Please sign in to comment.