Skip to content

Commit

Permalink
Do not show undo notifications on desktop (#4097)
Browse files Browse the repository at this point in the history
* Do not show undo notifications on desktop

* add release note

* fix linter

* Update packages/desktop-client/src/hooks/useUndo.ts

Co-authored-by: Joel Jeremy Marquez <[email protected]>

* Update useUndo.ts

* fix code pasted on wrong line

* drive-by fix typo

* Update 4097.md

---------

Co-authored-by: Joel Jeremy Marquez <[email protected]>
  • Loading branch information
psybers and joel-jeremy authored Jan 7, 2025
1 parent 82e1922 commit 7c2408d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/desktop-client/src/hooks/useUndo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { useDispatch } from 'react-redux';
import { undo, redo, addNotification } from 'loot-core/client/actions';
import { type Notification } from 'loot-core/client/state-types/notifications';

import { useResponsive } from '../components/responsive/ResponsiveProvider';

type UndoActions = {
undo: () => void;
redo: () => void;
Expand All @@ -15,6 +17,7 @@ const timeout = 10000;

export function useUndo(): UndoActions {
const dispatch = useDispatch();
const { isNarrowWidth } = useResponsive();

const dispatchUndo = useCallback(() => {
dispatch(undo());
Expand All @@ -26,6 +29,10 @@ export function useUndo(): UndoActions {

const showUndoNotification = useCallback(
(notification: Notification) => {
if (!isNarrowWidth) {
return;
}

dispatch(
addNotification({
type: 'message',
Expand All @@ -38,11 +45,15 @@ export function useUndo(): UndoActions {
}),
);
},
[dispatch, dispatchUndo],
[dispatch, dispatchUndo, isNarrowWidth],
);

const showRedoNotification = useCallback(
(notificaton: Notification) => {
(notification: Notification) => {
if (!isNarrowWidth) {
return;
}

dispatch(
addNotification({
type: 'message',
Expand All @@ -51,11 +62,11 @@ export function useUndo(): UndoActions {
title: 'Redo',
action: dispatchRedo,
},
...notificaton,
...notification,
}),
);
},
[dispatch, dispatchRedo],
[dispatch, dispatchRedo, isNarrowWidth],
);

return {
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/4097.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [psybers]
---

Do not show undo/redo notifications on desktop.

0 comments on commit 7c2408d

Please sign in to comment.