feat(ui): add hotkey to cycle compare modes

This commit is contained in:
psychedelicious 2024-06-02 15:19:53 +10:00
parent 9a0b77ad38
commit 7153d846a9
2 changed files with 19 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import {
comparedImagesSwapped, comparedImagesSwapped,
comparisonFitChanged, comparisonFitChanged,
comparisonModeChanged, comparisonModeChanged,
comparisonModeCycled,
imageToCompareChanged, imageToCompareChanged,
} from 'features/gallery/store/gallerySlice'; } from 'features/gallery/store/gallerySlice';
import { memo, useCallback } from 'react'; import { memo, useCallback } from 'react';
@ -36,6 +37,10 @@ export const CompareToolbar = memo(() => {
dispatch(imageToCompareChanged(null)); dispatch(imageToCompareChanged(null));
}, [dispatch]); }, [dispatch]);
useHotkeys('esc', exitCompare, [exitCompare]); useHotkeys('esc', exitCompare, [exitCompare]);
const nextMode = useCallback(() => {
dispatch(comparisonModeCycled());
}, [dispatch]);
useHotkeys('m', nextMode, [nextMode]);
return ( return (
<Flex w="full" gap={2}> <Flex w="full" gap={2}>

View File

@ -46,6 +46,19 @@ export const gallerySlice = createSlice({
comparisonModeChanged: (state, action: PayloadAction<ComparisonMode>) => { comparisonModeChanged: (state, action: PayloadAction<ComparisonMode>) => {
state.comparisonMode = action.payload; state.comparisonMode = action.payload;
}, },
comparisonModeCycled: (state) => {
switch (state.comparisonMode) {
case 'slider':
state.comparisonMode = 'side-by-side';
break;
case 'side-by-side':
state.comparisonMode = 'hover';
break;
case 'hover':
state.comparisonMode = 'slider';
break;
}
},
shouldAutoSwitchChanged: (state, action: PayloadAction<boolean>) => { shouldAutoSwitchChanged: (state, action: PayloadAction<boolean>) => {
state.shouldAutoSwitch = action.payload; state.shouldAutoSwitch = action.payload;
}, },
@ -143,6 +156,7 @@ export const {
comparisonModeChanged, comparisonModeChanged,
comparedImagesSwapped, comparedImagesSwapped,
comparisonFitChanged, comparisonFitChanged,
comparisonModeCycled,
} = gallerySlice.actions; } = gallerySlice.actions;
const isAnyBoardDeleted = isAnyOf( const isAnyBoardDeleted = isAnyOf(