mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): disable queue-related buttons when disconnected
This commit is contained in:
parent
8954953eca
commit
2b08d9e53b
@ -12,12 +12,12 @@ type Props = {
|
|||||||
|
|
||||||
const CancelCurrentQueueItemButton = ({ asIconButton, sx }: Props) => {
|
const CancelCurrentQueueItemButton = ({ asIconButton, sx }: Props) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { cancelQueueItem, isLoading, currentQueueItemId } =
|
const { cancelQueueItem, isLoading, isDisabled } =
|
||||||
useCancelCurrentQueueItem();
|
useCancelCurrentQueueItem();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<QueueButton
|
<QueueButton
|
||||||
isDisabled={!currentQueueItemId}
|
isDisabled={isDisabled}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
asIconButton={asIconButton}
|
asIconButton={asIconButton}
|
||||||
label={t('queue.cancel')}
|
label={t('queue.cancel')}
|
||||||
|
@ -13,7 +13,7 @@ type Props = {
|
|||||||
|
|
||||||
const ClearQueueButton = ({ asIconButton, sx }: Props) => {
|
const ClearQueueButton = ({ asIconButton, sx }: Props) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { clearQueue, isLoading, queueStatus } = useClearQueue();
|
const { clearQueue, isLoading, isDisabled } = useClearQueue();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<IAIAlertDialog
|
<IAIAlertDialog
|
||||||
@ -22,7 +22,7 @@ const ClearQueueButton = ({ asIconButton, sx }: Props) => {
|
|||||||
acceptButtonText={t('queue.clear')}
|
acceptButtonText={t('queue.clear')}
|
||||||
triggerComponent={
|
triggerComponent={
|
||||||
<QueueButton
|
<QueueButton
|
||||||
isDisabled={!queueStatus?.queue.total}
|
isDisabled={isDisabled}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
asIconButton={asIconButton}
|
asIconButton={asIconButton}
|
||||||
label={t('queue.clear')}
|
label={t('queue.clear')}
|
||||||
|
@ -10,14 +10,14 @@ type Props = {
|
|||||||
|
|
||||||
const PauseProcessorButton = ({ asIconButton }: Props) => {
|
const PauseProcessorButton = ({ asIconButton }: Props) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { pauseProcessor, isLoading, isStarted } = usePauseProcessor();
|
const { pauseProcessor, isLoading, isDisabled } = usePauseProcessor();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<QueueButton
|
<QueueButton
|
||||||
asIconButton={asIconButton}
|
asIconButton={asIconButton}
|
||||||
label={t('queue.pause')}
|
label={t('queue.pause')}
|
||||||
tooltip={t('queue.pauseTooltip')}
|
tooltip={t('queue.pauseTooltip')}
|
||||||
isDisabled={!isStarted}
|
isDisabled={isDisabled}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
icon={<FaPause />}
|
icon={<FaPause />}
|
||||||
onClick={pauseProcessor}
|
onClick={pauseProcessor}
|
||||||
|
@ -10,11 +10,11 @@ type Props = {
|
|||||||
|
|
||||||
const PruneQueueButton = ({ asIconButton }: Props) => {
|
const PruneQueueButton = ({ asIconButton }: Props) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { pruneQueue, isLoading, finishedCount } = usePruneQueue();
|
const { pruneQueue, isLoading, finishedCount, isDisabled } = usePruneQueue();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<QueueButton
|
<QueueButton
|
||||||
isDisabled={!finishedCount}
|
isDisabled={isDisabled}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
asIconButton={asIconButton}
|
asIconButton={asIconButton}
|
||||||
label={t('queue.prune')}
|
label={t('queue.prune')}
|
||||||
|
@ -10,14 +10,14 @@ type Props = {
|
|||||||
|
|
||||||
const ResumeProcessorButton = ({ asIconButton }: Props) => {
|
const ResumeProcessorButton = ({ asIconButton }: Props) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { resumeProcessor, isLoading, isStarted } = useResumeProcessor();
|
const { resumeProcessor, isLoading, isDisabled } = useResumeProcessor();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<QueueButton
|
<QueueButton
|
||||||
asIconButton={asIconButton}
|
asIconButton={asIconButton}
|
||||||
label={t('queue.resume')}
|
label={t('queue.resume')}
|
||||||
tooltip={t('queue.resumeTooltip')}
|
tooltip={t('queue.resumeTooltip')}
|
||||||
isDisabled={isStarted}
|
isDisabled={isDisabled}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
icon={<FaPlay />}
|
icon={<FaPlay />}
|
||||||
onClick={resumeProcessor}
|
onClick={resumeProcessor}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useAppDispatch } from 'app/store/storeHooks';
|
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||||
import { addToast } from 'features/system/store/systemSlice';
|
import { addToast } from 'features/system/store/systemSlice';
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
@ -8,6 +8,7 @@ import {
|
|||||||
} from 'services/api/endpoints/queue';
|
} from 'services/api/endpoints/queue';
|
||||||
|
|
||||||
export const useCancelBatch = (batch_id: string) => {
|
export const useCancelBatch = (batch_id: string) => {
|
||||||
|
const isConnected = useAppSelector((state) => state.system.isConnected);
|
||||||
const { isCanceled } = useGetBatchStatusQuery(
|
const { isCanceled } = useGetBatchStatusQuery(
|
||||||
{ batch_id },
|
{ batch_id },
|
||||||
{
|
{
|
||||||
@ -49,5 +50,5 @@ export const useCancelBatch = (batch_id: string) => {
|
|||||||
}
|
}
|
||||||
}, [batch_id, dispatch, isCanceled, t, trigger]);
|
}, [batch_id, dispatch, isCanceled, t, trigger]);
|
||||||
|
|
||||||
return { cancelBatch, isLoading, isCanceled };
|
return { cancelBatch, isLoading, isCanceled, isDisabled: !isConnected };
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useAppDispatch } from 'app/store/storeHooks';
|
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||||
import { addToast } from 'features/system/store/systemSlice';
|
import { addToast } from 'features/system/store/systemSlice';
|
||||||
import { useCallback, useMemo } from 'react';
|
import { useCallback, useMemo } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
@ -8,6 +8,7 @@ import {
|
|||||||
} from 'services/api/endpoints/queue';
|
} from 'services/api/endpoints/queue';
|
||||||
|
|
||||||
export const useCancelCurrentQueueItem = () => {
|
export const useCancelCurrentQueueItem = () => {
|
||||||
|
const isConnected = useAppSelector((state) => state.system.isConnected);
|
||||||
const { data: queueStatus } = useGetQueueStatusQuery();
|
const { data: queueStatus } = useGetQueueStatusQuery();
|
||||||
const [trigger, { isLoading }] = useCancelQueueItemMutation();
|
const [trigger, { isLoading }] = useCancelQueueItemMutation();
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
@ -38,5 +39,15 @@ export const useCancelCurrentQueueItem = () => {
|
|||||||
}
|
}
|
||||||
}, [currentQueueItemId, dispatch, t, trigger]);
|
}, [currentQueueItemId, dispatch, t, trigger]);
|
||||||
|
|
||||||
return { cancelQueueItem, isLoading, currentQueueItemId };
|
const isDisabled = useMemo(
|
||||||
|
() => !isConnected || !currentQueueItemId,
|
||||||
|
[isConnected, currentQueueItemId]
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
cancelQueueItem,
|
||||||
|
isLoading,
|
||||||
|
currentQueueItemId,
|
||||||
|
isDisabled,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import { useAppDispatch } from 'app/store/storeHooks';
|
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||||
import { addToast } from 'features/system/store/systemSlice';
|
import { addToast } from 'features/system/store/systemSlice';
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useCancelQueueItemMutation } from 'services/api/endpoints/queue';
|
import { useCancelQueueItemMutation } from 'services/api/endpoints/queue';
|
||||||
|
|
||||||
export const useCancelQueueItem = (item_id: number) => {
|
export const useCancelQueueItem = (item_id: number) => {
|
||||||
|
const isConnected = useAppSelector((state) => state.system.isConnected);
|
||||||
const [trigger, { isLoading }] = useCancelQueueItemMutation();
|
const [trigger, { isLoading }] = useCancelQueueItemMutation();
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@ -27,5 +28,5 @@ export const useCancelQueueItem = (item_id: number) => {
|
|||||||
}
|
}
|
||||||
}, [dispatch, item_id, t, trigger]);
|
}, [dispatch, item_id, t, trigger]);
|
||||||
|
|
||||||
return { cancelQueueItem, isLoading };
|
return { cancelQueueItem, isLoading, isDisabled: !isConnected };
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { useAppDispatch } from 'app/store/storeHooks';
|
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||||
import { addToast } from 'features/system/store/systemSlice';
|
import { addToast } from 'features/system/store/systemSlice';
|
||||||
import { useCallback } from 'react';
|
import { useCallback, useMemo } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import {
|
import {
|
||||||
useClearQueueMutation,
|
useClearQueueMutation,
|
||||||
@ -10,10 +10,9 @@ import { listCursorChanged, listPriorityChanged } from '../store/queueSlice';
|
|||||||
|
|
||||||
export const useClearQueue = () => {
|
export const useClearQueue = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const { data: queueStatus } = useGetQueueStatusQuery();
|
const { data: queueStatus } = useGetQueueStatusQuery();
|
||||||
|
const isConnected = useAppSelector((state) => state.system.isConnected);
|
||||||
const [trigger, { isLoading }] = useClearQueueMutation({
|
const [trigger, { isLoading }] = useClearQueueMutation({
|
||||||
fixedCacheKey: 'clearQueue',
|
fixedCacheKey: 'clearQueue',
|
||||||
});
|
});
|
||||||
@ -43,5 +42,10 @@ export const useClearQueue = () => {
|
|||||||
}
|
}
|
||||||
}, [queueStatus?.queue.total, trigger, dispatch, t]);
|
}, [queueStatus?.queue.total, trigger, dispatch, t]);
|
||||||
|
|
||||||
return { clearQueue, isLoading, queueStatus };
|
const isDisabled = useMemo(
|
||||||
|
() => !isConnected || !queueStatus?.queue.total,
|
||||||
|
[isConnected, queueStatus?.queue.total]
|
||||||
|
);
|
||||||
|
|
||||||
|
return { clearQueue, isLoading, queueStatus, isDisabled };
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useAppDispatch } from 'app/store/storeHooks';
|
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||||
import { addToast } from 'features/system/store/systemSlice';
|
import { addToast } from 'features/system/store/systemSlice';
|
||||||
import { useCallback, useMemo } from 'react';
|
import { useCallback, useMemo } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
@ -10,6 +10,7 @@ import {
|
|||||||
export const usePauseProcessor = () => {
|
export const usePauseProcessor = () => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const isConnected = useAppSelector((state) => state.system.isConnected);
|
||||||
const { data: queueStatus } = useGetQueueStatusQuery();
|
const { data: queueStatus } = useGetQueueStatusQuery();
|
||||||
const [trigger, { isLoading }] = usePauseProcessorMutation({
|
const [trigger, { isLoading }] = usePauseProcessorMutation({
|
||||||
fixedCacheKey: 'pauseProcessor',
|
fixedCacheKey: 'pauseProcessor',
|
||||||
@ -42,5 +43,10 @@ export const usePauseProcessor = () => {
|
|||||||
}
|
}
|
||||||
}, [isStarted, trigger, dispatch, t]);
|
}, [isStarted, trigger, dispatch, t]);
|
||||||
|
|
||||||
return { pauseProcessor, isLoading, isStarted };
|
const isDisabled = useMemo(
|
||||||
|
() => !isConnected || !isStarted,
|
||||||
|
[isConnected, isStarted]
|
||||||
|
);
|
||||||
|
|
||||||
|
return { pauseProcessor, isLoading, isStarted, isDisabled };
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { useAppDispatch } from 'app/store/storeHooks';
|
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||||
import { addToast } from 'features/system/store/systemSlice';
|
import { addToast } from 'features/system/store/systemSlice';
|
||||||
import { useCallback } from 'react';
|
import { useCallback, useMemo } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import {
|
import {
|
||||||
useGetQueueStatusQuery,
|
useGetQueueStatusQuery,
|
||||||
@ -11,6 +11,7 @@ import { listCursorChanged, listPriorityChanged } from '../store/queueSlice';
|
|||||||
export const usePruneQueue = () => {
|
export const usePruneQueue = () => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const isConnected = useAppSelector((state) => state.system.isConnected);
|
||||||
const [trigger, { isLoading }] = usePruneQueueMutation({
|
const [trigger, { isLoading }] = usePruneQueueMutation({
|
||||||
fixedCacheKey: 'pruneQueue',
|
fixedCacheKey: 'pruneQueue',
|
||||||
});
|
});
|
||||||
@ -51,5 +52,10 @@ export const usePruneQueue = () => {
|
|||||||
}
|
}
|
||||||
}, [finishedCount, trigger, dispatch, t]);
|
}, [finishedCount, trigger, dispatch, t]);
|
||||||
|
|
||||||
return { pruneQueue, isLoading, finishedCount };
|
const isDisabled = useMemo(
|
||||||
|
() => !isConnected || !finishedCount,
|
||||||
|
[finishedCount, isConnected]
|
||||||
|
);
|
||||||
|
|
||||||
|
return { pruneQueue, isLoading, finishedCount, isDisabled };
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useAppDispatch } from 'app/store/storeHooks';
|
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||||
import { addToast } from 'features/system/store/systemSlice';
|
import { addToast } from 'features/system/store/systemSlice';
|
||||||
import { useCallback, useMemo } from 'react';
|
import { useCallback, useMemo } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
@ -9,6 +9,7 @@ import {
|
|||||||
|
|
||||||
export const useResumeProcessor = () => {
|
export const useResumeProcessor = () => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
const isConnected = useAppSelector((state) => state.system.isConnected);
|
||||||
const { data: queueStatus } = useGetQueueStatusQuery();
|
const { data: queueStatus } = useGetQueueStatusQuery();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [trigger, { isLoading }] = useResumeProcessorMutation({
|
const [trigger, { isLoading }] = useResumeProcessorMutation({
|
||||||
@ -42,5 +43,10 @@ export const useResumeProcessor = () => {
|
|||||||
}
|
}
|
||||||
}, [isStarted, trigger, dispatch, t]);
|
}, [isStarted, trigger, dispatch, t]);
|
||||||
|
|
||||||
return { resumeProcessor, isLoading, isStarted };
|
const isDisabled = useMemo(
|
||||||
|
() => !isConnected || isStarted,
|
||||||
|
[isConnected, isStarted]
|
||||||
|
);
|
||||||
|
|
||||||
|
return { resumeProcessor, isLoading, isStarted, isDisabled };
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user