-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): add cancel all except current queue item functionality
- Loading branch information
Showing
6 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
.../src/features/queue/components/CancelAllExceptCurrentQueueItemConfirmationAlertDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { ConfirmationAlertDialog, Text } from '@invoke-ai/ui-library'; | ||
import { useAssertSingleton } from 'common/hooks/useAssertSingleton'; | ||
import { buildUseBoolean } from 'common/hooks/useBoolean'; | ||
import { useCancelAllExceptCurrentQueueItem } from 'features/queue/hooks/useCancelAllExceptCurrentQueueItem'; | ||
import { memo } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
const [useCancelAllExceptCurrentQueueItemConfirmationAlertDialog] = buildUseBoolean(false); | ||
|
||
export const useCancelAllExceptCurrentQueueItemDialog = () => { | ||
const dialog = useCancelAllExceptCurrentQueueItemConfirmationAlertDialog(); | ||
const { cancelAllExceptCurrentQueueItem, isLoading, isDisabled, queueStatus } = useCancelAllExceptCurrentQueueItem(); | ||
|
||
return { | ||
cancelAllExceptCurrentQueueItem, | ||
isOpen: dialog.isTrue, | ||
openDialog: dialog.setTrue, | ||
closeDialog: dialog.setFalse, | ||
isLoading, | ||
queueStatus, | ||
isDisabled, | ||
}; | ||
}; | ||
|
||
export const CancelAllExceptCurrentQueueItemConfirmationAlertDialog = memo(() => { | ||
useAssertSingleton('CancelAllExceptCurrentQueueItemConfirmationAlertDialog'); | ||
const { t } = useTranslation(); | ||
const cancelAllExceptCurrentQueueItem = useCancelAllExceptCurrentQueueItemDialog(); | ||
|
||
return ( | ||
<ConfirmationAlertDialog | ||
isOpen={cancelAllExceptCurrentQueueItem.isOpen} | ||
onClose={cancelAllExceptCurrentQueueItem.closeDialog} | ||
title={t('queue.cancelAllExceptCurrentTooltip')} | ||
acceptCallback={cancelAllExceptCurrentQueueItem.cancelAllExceptCurrentQueueItem} | ||
acceptButtonText={t('queue.confirm')} | ||
useInert={false} | ||
> | ||
<Text>{t('queue.cancelAllExceptCurrentQueueItemAlertDialog')}</Text> | ||
<br /> | ||
<Text>{t('queue.cancelAllExceptCurrentQueueItemAlertDialog2')}</Text> | ||
</ConfirmationAlertDialog> | ||
); | ||
}); | ||
|
||
CancelAllExceptCurrentQueueItemConfirmationAlertDialog.displayName = | ||
'CancelAllExceptCurrentQueueItemConfirmationAlertDialog'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
invokeai/frontend/web/src/features/queue/hooks/useCancelAllExceptCurrentQueueItem.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { useStore } from '@nanostores/react'; | ||
import { toast } from 'features/toast/toast'; | ||
import { useCallback, useMemo } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useCancelAllExceptCurrentMutation, useGetQueueStatusQuery } from 'services/api/endpoints/queue'; | ||
import { $isConnected } from 'services/events/stores'; | ||
|
||
export const useCancelAllExceptCurrentQueueItem = () => { | ||
const { t } = useTranslation(); | ||
const { data: queueStatus } = useGetQueueStatusQuery(); | ||
const isConnected = useStore($isConnected); | ||
const [trigger, { isLoading }] = useCancelAllExceptCurrentMutation({ | ||
fixedCacheKey: 'cancelAllExceptCurrent', | ||
}); | ||
|
||
const cancelAllExceptCurrentQueueItem = useCallback(async () => { | ||
if (!queueStatus?.queue.pending) { | ||
return; | ||
} | ||
|
||
try { | ||
await trigger().unwrap(); | ||
toast({ | ||
id: 'QUEUE_CANCEL_SUCCEEDED', | ||
title: t('queue.cancelSucceeded'), | ||
status: 'success', | ||
}); | ||
} catch { | ||
toast({ | ||
id: 'QUEUE_CANCEL_FAILED', | ||
title: t('queue.cancelFailed'), | ||
status: 'error', | ||
}); | ||
} | ||
}, [queueStatus?.queue.pending, trigger, t]); | ||
|
||
const isDisabled = useMemo( | ||
() => !isConnected || !queueStatus?.queue.pending, | ||
[isConnected, queueStatus?.queue.pending] | ||
); | ||
|
||
return { | ||
cancelAllExceptCurrentQueueItem, | ||
isLoading, | ||
queueStatus, | ||
isDisabled, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters