From 0e24eeeb1cfa14bccc3f69bdd3378e78722de845 Mon Sep 17 00:00:00 2001 From: jeffvli Date: Wed, 3 Jun 2026 00:24:43 -0700 Subject: [PATCH] only show queue save toast on explicit request (#2090) --- .../components/play-queue-list-controls.tsx | 15 ++++++-- .../player/hooks/use-queue-restore.ts | 34 ++++++++----------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/renderer/features/now-playing/components/play-queue-list-controls.tsx b/src/renderer/features/now-playing/components/play-queue-list-controls.tsx index a0d1fa477..d1e4a53aa 100644 --- a/src/renderer/features/now-playing/components/play-queue-list-controls.tsx +++ b/src/renderer/features/now-playing/components/play-queue-list-controls.tsx @@ -1,6 +1,6 @@ import { useIsFetching } from '@tanstack/react-query'; import { t } from 'i18next'; -import { RefObject } from 'react'; +import { RefObject, useCallback } from 'react'; import { useTranslation } from 'react-i18next'; import styles from './play-queue-list-controls.module.css'; @@ -21,6 +21,7 @@ import { ActionIcon } from '/@/shared/components/action-icon/action-icon'; import { Box } from '/@/shared/components/box/box'; import { Divider } from '/@/shared/components/divider/divider'; import { Group } from '/@/shared/components/group/group'; +import { toast } from '/@/shared/components/toast/toast'; import { ServerFeature } from '/@/shared/types/features-types'; import { ItemListKey, ListDisplayType } from '/@/shared/types/types'; @@ -135,7 +136,17 @@ const QueueRestoreActions = () => { const isFetching = useIsFetching({ queryKey: queryKeys.player.fetch({ type: 'queue' }) }); - const { isPending: isSavingQueue, mutate: handleSaveQueue } = useSaveQueue(); + const { isPending: isSavingQueue, mutate: saveQueue } = useSaveQueue(); + + const handleSaveQueue = useCallback(() => { + saveQueue(undefined, { + onSuccess: () => { + toast.success({ + message: t('form.saveQueue.success'), + }); + }, + }); + }, [saveQueue]); const handleRestoreQueue = useRestoreQueue(); diff --git a/src/renderer/features/player/hooks/use-queue-restore.ts b/src/renderer/features/player/hooks/use-queue-restore.ts index b836927f8..1aae370e5 100644 --- a/src/renderer/features/player/hooks/use-queue-restore.ts +++ b/src/renderer/features/player/hooks/use-queue-restore.ts @@ -170,26 +170,20 @@ export const useSaveQueue = () => { throw new Error(`${t('error.multipleServerSaveQueueError')}`); } - try { - await api.controller.savePlayQueue({ - apiClientProps: { serverId }, - query: { - currentIndex: queue.items.length > 0 ? state.player.index : undefined, - positionMs: useTimestampStoreBase.getState().timestamp * 1000, - songs: queue.items.map((item) => item.id), - }, - }); - - toast.success({ - message: t('form.saveQueue.success'), - }); - } catch (error) { - toast.error({ - message: (error as Error).message, - title: t('error.saveQueueFailed'), - }); - throw error; - } + return api.controller.savePlayQueue({ + apiClientProps: { serverId }, + query: { + currentIndex: queue.items.length > 0 ? state.player.index : undefined, + positionMs: useTimestampStoreBase.getState().timestamp * 1000, + songs: queue.items.map((item) => item.id), + }, + }); + }, + onError: (error) => { + toast.error({ + message: (error as Error).message, + title: t('error.saveQueueFailed'), + }); }, });