mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-02-14 00:04:59 -05:00
- Canvas manages its own progress socket event listeners and progress event data. - Remove cancellations listener jank. - Dip into low-level redux subscription API to watch for queue status changes, clearing the last "global" progress event when the queue has nothing in progress. Could also do this in a useEffect I guess. - Had to shuffle some things around to prevent circular imports, so there are a lot of tiny changes here.
31 lines
987 B
TypeScript
31 lines
987 B
TypeScript
import { useStore } from '@nanostores/react';
|
|
import { toast } from 'features/toast/toast';
|
|
import { useCallback } from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { useCancelQueueItemMutation } from 'services/api/endpoints/queue';
|
|
import { $isConnected } from 'services/events/stores';
|
|
|
|
export const useCancelQueueItem = (item_id: number) => {
|
|
const isConnected = useStore($isConnected);
|
|
const [trigger, { isLoading }] = useCancelQueueItemMutation();
|
|
const { t } = useTranslation();
|
|
const cancelQueueItem = useCallback(async () => {
|
|
try {
|
|
await trigger(item_id).unwrap();
|
|
toast({
|
|
id: 'QUEUE_CANCEL_SUCCEEDED',
|
|
title: t('queue.cancelSucceeded'),
|
|
status: 'success',
|
|
});
|
|
} catch {
|
|
toast({
|
|
id: 'QUEUE_CANCEL_FAILED',
|
|
title: t('queue.cancelFailed'),
|
|
status: 'error',
|
|
});
|
|
}
|
|
}, [item_id, t, trigger]);
|
|
|
|
return { cancelQueueItem, isLoading, isDisabled: !isConnected };
|
|
};
|