mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-04-23 03:00:31 -04:00
queueSlice cleaned up
This commit is contained in:
committed by
psychedelicious
parent
3c2f654da8
commit
107be8e166
@@ -1,6 +1,4 @@
|
||||
import { useStore } from '@nanostores/react';
|
||||
import { useAppDispatch } from 'app/store/storeHooks';
|
||||
import { listCursorChanged, listPriorityChanged } from 'features/queue/store/queueSlice';
|
||||
import { toast } from 'features/toast/toast';
|
||||
import { useCallback } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
@@ -9,7 +7,6 @@ import { $isConnected } from 'services/events/stores';
|
||||
|
||||
export const useClearQueue = () => {
|
||||
const { t } = useTranslation();
|
||||
const dispatch = useAppDispatch();
|
||||
const { data: queueStatus } = useGetQueueStatusQuery();
|
||||
const isConnected = useStore($isConnected);
|
||||
const [_trigger, { isLoading }] = useClearQueueMutation({
|
||||
@@ -28,8 +25,6 @@ export const useClearQueue = () => {
|
||||
title: t('queue.clearSucceeded'),
|
||||
status: 'success',
|
||||
});
|
||||
dispatch(listCursorChanged(undefined));
|
||||
dispatch(listPriorityChanged(undefined));
|
||||
} catch {
|
||||
toast({
|
||||
id: 'QUEUE_CLEAR_FAILED',
|
||||
@@ -37,7 +32,7 @@ export const useClearQueue = () => {
|
||||
status: 'error',
|
||||
});
|
||||
}
|
||||
}, [queueStatus?.queue.total, _trigger, dispatch, t]);
|
||||
}, [queueStatus?.queue.total, _trigger, t]);
|
||||
|
||||
return { trigger, isLoading, isDisabled: !isConnected || !queueStatus?.queue.total };
|
||||
};
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { useStore } from '@nanostores/react';
|
||||
import { useAppDispatch } from 'app/store/storeHooks';
|
||||
import { listCursorChanged, listPriorityChanged } from 'features/queue/store/queueSlice';
|
||||
import { toast } from 'features/toast/toast';
|
||||
import { useCallback } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
@@ -8,7 +6,6 @@ import { useGetQueueStatusQuery, usePruneQueueMutation } from 'services/api/endp
|
||||
import { $isConnected } from 'services/events/stores';
|
||||
|
||||
export const usePruneQueue = () => {
|
||||
const dispatch = useAppDispatch();
|
||||
const { t } = useTranslation();
|
||||
const isConnected = useStore($isConnected);
|
||||
const finishedCount = useFinishedCount();
|
||||
@@ -24,8 +21,6 @@ export const usePruneQueue = () => {
|
||||
title: t('queue.pruneSucceeded', { item_count: data.deleted }),
|
||||
status: 'success',
|
||||
});
|
||||
dispatch(listCursorChanged(undefined));
|
||||
dispatch(listPriorityChanged(undefined));
|
||||
} catch {
|
||||
toast({
|
||||
id: 'PRUNE_FAILED',
|
||||
@@ -33,7 +28,7 @@ export const usePruneQueue = () => {
|
||||
status: 'error',
|
||||
});
|
||||
}
|
||||
}, [_trigger, dispatch, t]);
|
||||
}, [_trigger, t]);
|
||||
|
||||
return { trigger, isLoading, isDisabled: !isConnected || !finishedCount };
|
||||
};
|
||||
|
||||
@@ -10,38 +10,20 @@ const zSortBy = z.enum(['created_at', 'completed_at']);
|
||||
export type SortBy = z.infer<typeof zSortBy>;
|
||||
|
||||
const zQueueState = z.object({
|
||||
listCursor: z.number().optional(),
|
||||
listPriority: z.number().optional(),
|
||||
selectedQueueItem: z.string().optional(),
|
||||
sortBy: zSortBy,
|
||||
sortOrder: zSQLiteDirection,
|
||||
resumeProcessorOnEnqueue: z.boolean(),
|
||||
});
|
||||
type QueueState = z.infer<typeof zQueueState>;
|
||||
|
||||
const getInitialState = (): QueueState => ({
|
||||
listCursor: undefined,
|
||||
listPriority: undefined,
|
||||
selectedQueueItem: undefined,
|
||||
sortBy: 'created_at',
|
||||
sortOrder: 'DESC',
|
||||
resumeProcessorOnEnqueue: true,
|
||||
});
|
||||
|
||||
const slice = createSlice({
|
||||
name: 'queue',
|
||||
initialState: getInitialState(),
|
||||
reducers: {
|
||||
listCursorChanged: (state, action: PayloadAction<number | undefined>) => {
|
||||
state.listCursor = action.payload;
|
||||
},
|
||||
listPriorityChanged: (state, action: PayloadAction<number | undefined>) => {
|
||||
state.listPriority = action.payload;
|
||||
},
|
||||
listParamsReset: (state) => {
|
||||
state.listCursor = undefined;
|
||||
state.listPriority = undefined;
|
||||
},
|
||||
sortByChanged: (state, action: PayloadAction<SortBy>) => {
|
||||
state.sortBy = action.payload;
|
||||
},
|
||||
@@ -51,7 +33,7 @@ const slice = createSlice({
|
||||
},
|
||||
});
|
||||
|
||||
export const { listCursorChanged, listPriorityChanged, sortByChanged, sortOrderChanged } = slice.actions;
|
||||
export const { sortByChanged, sortOrderChanged } = slice.actions;
|
||||
|
||||
export const queueSliceConfig: SliceConfig<typeof slice> = {
|
||||
slice,
|
||||
|
||||
Reference in New Issue
Block a user