mirror of
https://github.com/jeffvli/feishin.git
synced 2026-06-17 08:54:27 +02:00
only show queue save toast on explicit request (#2090)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { useIsFetching } from '@tanstack/react-query';
|
import { useIsFetching } from '@tanstack/react-query';
|
||||||
import { t } from 'i18next';
|
import { t } from 'i18next';
|
||||||
import { RefObject } from 'react';
|
import { RefObject, useCallback } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import styles from './play-queue-list-controls.module.css';
|
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 { Box } from '/@/shared/components/box/box';
|
||||||
import { Divider } from '/@/shared/components/divider/divider';
|
import { Divider } from '/@/shared/components/divider/divider';
|
||||||
import { Group } from '/@/shared/components/group/group';
|
import { Group } from '/@/shared/components/group/group';
|
||||||
|
import { toast } from '/@/shared/components/toast/toast';
|
||||||
import { ServerFeature } from '/@/shared/types/features-types';
|
import { ServerFeature } from '/@/shared/types/features-types';
|
||||||
import { ItemListKey, ListDisplayType } from '/@/shared/types/types';
|
import { ItemListKey, ListDisplayType } from '/@/shared/types/types';
|
||||||
|
|
||||||
@@ -135,7 +136,17 @@ const QueueRestoreActions = () => {
|
|||||||
|
|
||||||
const isFetching = useIsFetching({ queryKey: queryKeys.player.fetch({ type: 'queue' }) });
|
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();
|
const handleRestoreQueue = useRestoreQueue();
|
||||||
|
|
||||||
|
|||||||
@@ -170,26 +170,20 @@ export const useSaveQueue = () => {
|
|||||||
throw new Error(`${t('error.multipleServerSaveQueueError')}`);
|
throw new Error(`${t('error.multipleServerSaveQueueError')}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
return api.controller.savePlayQueue({
|
||||||
await api.controller.savePlayQueue({
|
apiClientProps: { serverId },
|
||||||
apiClientProps: { serverId },
|
query: {
|
||||||
query: {
|
currentIndex: queue.items.length > 0 ? state.player.index : undefined,
|
||||||
currentIndex: queue.items.length > 0 ? state.player.index : undefined,
|
positionMs: useTimestampStoreBase.getState().timestamp * 1000,
|
||||||
positionMs: useTimestampStoreBase.getState().timestamp * 1000,
|
songs: queue.items.map((item) => item.id),
|
||||||
songs: queue.items.map((item) => item.id),
|
},
|
||||||
},
|
});
|
||||||
});
|
},
|
||||||
|
onError: (error) => {
|
||||||
toast.success({
|
toast.error({
|
||||||
message: t('form.saveQueue.success'),
|
message: (error as Error).message,
|
||||||
});
|
title: t('error.saveQueueFailed'),
|
||||||
} catch (error) {
|
});
|
||||||
toast.error({
|
|
||||||
message: (error as Error).message,
|
|
||||||
title: t('error.saveQueueFailed'),
|
|
||||||
});
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user