fix(dashboard): modernize UndoRedo shortcut + cancel SliceAdder debounce

- UndoRedoKeyListeners now normalizes event.key and uses shiftKey so
  Ctrl/Cmd+Shift+Z triggers redo instead of undo. Drops deprecated
  event.keyCode checks.
- SliceAdder cancels the debounced search handler on unmount to avoid
  post-unmount state updates and stray /api/v1/chart fetches.
This commit is contained in:
Evan Rusackas
2026-04-18 10:33:00 -07:00
committed by Claude
parent de802edf2a
commit ec14530574
2 changed files with 12 additions and 4 deletions

View File

@@ -260,6 +260,13 @@ function SliceAdder({
[fetchSlices, searchUpdated, sortBy, userIdForFetch],
);
useEffect(
() => () => {
handleChange.cancel();
},
[handleChange],
);
const handleSelect = useCallback(
(newSortBy: keyof Slice) => {
setSortBy(newSortBy);

View File

@@ -29,8 +29,9 @@ function UndoRedoKeyListeners({ onUndo, onRedo }: UndoRedoKeyListenersProps) {
(event: KeyboardEvent) => {
const controlOrCommand = event.ctrlKey || event.metaKey;
if (controlOrCommand) {
const isZChar = event.key === 'z' || event.keyCode === 90;
const isYChar = event.key === 'y' || event.keyCode === 89;
const key = event.key.toLowerCase();
const isUndo = key === 'z' && !event.shiftKey;
const isRedo = key === 'y' || (key === 'z' && event.shiftKey);
const isEditingMarkdown = document?.querySelector(
'.dashboard-markdown--editing',
);
@@ -38,9 +39,9 @@ function UndoRedoKeyListeners({ onUndo, onRedo }: UndoRedoKeyListenersProps) {
'.editable-title--editing',
);
if (!isEditingMarkdown && !isEditingTitle && (isZChar || isYChar)) {
if (!isEditingMarkdown && !isEditingTitle && (isUndo || isRedo)) {
event.preventDefault();
const func = isZChar ? onUndo : onRedo;
const func = isUndo ? onUndo : onRedo;
func();
}
}