mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-02-01 23:35:10 -05:00
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { enqueueRequested } from 'app/store/actions';
|
|
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
|
import { useIsReadyToEnqueue } from 'common/hooks/useIsReadyToEnqueue';
|
|
import { useFeatureStatus } from 'features/system/hooks/useFeatureStatus';
|
|
import { selectActiveTab } from 'features/ui/store/uiSelectors';
|
|
import { useCallback, useMemo } from 'react';
|
|
import { useEnqueueBatchMutation } from 'services/api/endpoints/queue';
|
|
|
|
export const useQueueFront = () => {
|
|
const dispatch = useAppDispatch();
|
|
const tabName = useAppSelector(selectActiveTab);
|
|
const { isReady } = useIsReadyToEnqueue();
|
|
const [_, { isLoading }] = useEnqueueBatchMutation({
|
|
fixedCacheKey: 'enqueueBatch',
|
|
});
|
|
const prependEnabled = useFeatureStatus('prependQueue');
|
|
|
|
const isDisabled = useMemo(() => {
|
|
return !isReady || !prependEnabled;
|
|
}, [isReady, prependEnabled]);
|
|
|
|
const queueFront = useCallback(() => {
|
|
if (isDisabled) {
|
|
return;
|
|
}
|
|
dispatch(enqueueRequested({ tabName, prepend: true }));
|
|
}, [dispatch, isDisabled, tabName]);
|
|
|
|
return { queueFront, isLoading, isDisabled };
|
|
};
|