mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat: 🚸 shift key queue cancellations
This commit is contained in:
parent
b917ffecbe
commit
e03c88ce32
@ -2,16 +2,17 @@ import { useDisclosure } from '@chakra-ui/react';
|
|||||||
import { InvIconButton } from 'common/components/InvIconButton/InvIconButton';
|
import { InvIconButton } from 'common/components/InvIconButton/InvIconButton';
|
||||||
import type { InvIconButtonProps } from 'common/components/InvIconButton/types';
|
import type { InvIconButtonProps } from 'common/components/InvIconButton/types';
|
||||||
import ClearQueueConfirmationAlertDialog from 'features/queue/components/ClearQueueConfirmationAlertDialog';
|
import ClearQueueConfirmationAlertDialog from 'features/queue/components/ClearQueueConfirmationAlertDialog';
|
||||||
|
import { useCancelCurrentQueueItem } from 'features/queue/hooks/useCancelCurrentQueueItem';
|
||||||
import { useClearQueue } from 'features/queue/hooks/useClearQueue';
|
import { useClearQueue } from 'features/queue/hooks/useClearQueue';
|
||||||
import { memo } from 'react';
|
import { useState } from 'react';
|
||||||
|
import { useHotkeys } from 'react-hotkeys-hook'
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { PiTrashSimpleBold } from 'react-icons/pi';
|
import { PiTrashSimpleBold } from 'react-icons/pi';
|
||||||
|
|
||||||
type Props = Omit<InvIconButtonProps, 'aria-label'>;
|
type Props = Omit<InvIconButtonProps, 'aria-label'>;
|
||||||
|
|
||||||
const ClearQueueIconButton = (props: Props) => {
|
const ClearQueueIconButton = ({ onOpen, ...props }: Props & { onOpen: () => void }) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const disclosure = useDisclosure();
|
|
||||||
const { isLoading, isDisabled } = useClearQueue();
|
const { isLoading, isDisabled } = useClearQueue();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -23,13 +24,57 @@ const ClearQueueIconButton = (props: Props) => {
|
|||||||
tooltip={t('queue.clearTooltip')}
|
tooltip={t('queue.clearTooltip')}
|
||||||
icon={<PiTrashSimpleBold size="16px" />}
|
icon={<PiTrashSimpleBold size="16px" />}
|
||||||
colorScheme="error"
|
colorScheme="error"
|
||||||
onClick={disclosure.onOpen}
|
onClick={onOpen}
|
||||||
data-testid={t('queue.clear')}
|
data-testid={t('queue.clear')}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
<ClearQueueConfirmationAlertDialog disclosure={disclosure} />
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default memo(ClearQueueIconButton);
|
const ClearSingleQueueItemIconButton = (props: Props) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const {
|
||||||
|
cancelQueueItem,
|
||||||
|
isLoading,
|
||||||
|
isDisabled,
|
||||||
|
} = useCancelCurrentQueueItem();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<InvIconButton
|
||||||
|
isDisabled={isDisabled}
|
||||||
|
isLoading={isLoading}
|
||||||
|
aria-label={t('queue.cancelTooltip')}
|
||||||
|
tooltip={t('queue.cancelTooltip')}
|
||||||
|
icon={<PiTrashSimpleBold size="16px" />}
|
||||||
|
colorScheme="error"
|
||||||
|
onClick={cancelQueueItem}
|
||||||
|
data-testid={t('queue.clear')}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ClearQueueButton = (props: Props) => {
|
||||||
|
// Show the single item clear button when shift is pressed
|
||||||
|
// Otherwise show the clear queue button
|
||||||
|
const [showSingleItemClear, setShowSingleItemClear] = useState(true)
|
||||||
|
useHotkeys('shift', () => setShowSingleItemClear(false), { keydown: true, keyup: false })
|
||||||
|
useHotkeys('shift', () => setShowSingleItemClear(true), { keydown: false, keyup: true });
|
||||||
|
|
||||||
|
const disclosure = useDisclosure()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{showSingleItemClear
|
||||||
|
? <ClearSingleQueueItemIconButton {...props} />
|
||||||
|
: <ClearQueueIconButton {...props} onOpen={disclosure.onOpen} />
|
||||||
|
}
|
||||||
|
<ClearQueueConfirmationAlertDialog disclosure={disclosure} />
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ClearQueueButton;
|
||||||
|
@ -10,7 +10,8 @@ import {
|
|||||||
InvMenuButton,
|
InvMenuButton,
|
||||||
InvMenuDivider,
|
InvMenuDivider,
|
||||||
} from 'common/components/InvMenu/wrapper';
|
} from 'common/components/InvMenu/wrapper';
|
||||||
import { useCancelCurrentQueueItem } from 'features/queue/hooks/useCancelCurrentQueueItem';
|
import ClearQueueConfirmationAlertDialog from 'features/queue/components/ClearQueueConfirmationAlertDialog';
|
||||||
|
import { useClearQueue } from 'features/queue/hooks/useClearQueue';
|
||||||
import { usePauseProcessor } from 'features/queue/hooks/usePauseProcessor';
|
import { usePauseProcessor } from 'features/queue/hooks/usePauseProcessor';
|
||||||
import { useResumeProcessor } from 'features/queue/hooks/useResumeProcessor';
|
import { useResumeProcessor } from 'features/queue/hooks/useResumeProcessor';
|
||||||
import { useFeatureStatus } from 'features/system/hooks/useFeatureStatus';
|
import { useFeatureStatus } from 'features/system/hooks/useFeatureStatus';
|
||||||
@ -25,6 +26,7 @@ export const QueueActionsMenuButton = memo(() => {
|
|||||||
const { isOpen, onOpen, onClose } = useDisclosure();
|
const { isOpen, onOpen, onClose } = useDisclosure();
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const clearQueueDisclosure = useDisclosure()
|
||||||
const isPauseEnabled = useFeatureStatus('pauseQueue').isFeatureEnabled;
|
const isPauseEnabled = useFeatureStatus('pauseQueue').isFeatureEnabled;
|
||||||
const isResumeEnabled = useFeatureStatus('resumeQueue').isFeatureEnabled;
|
const isResumeEnabled = useFeatureStatus('resumeQueue').isFeatureEnabled;
|
||||||
const { queueSize } = useGetQueueStatusQuery(undefined, {
|
const { queueSize } = useGetQueueStatusQuery(undefined, {
|
||||||
@ -35,10 +37,9 @@ export const QueueActionsMenuButton = memo(() => {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
const {
|
const {
|
||||||
cancelQueueItem,
|
isLoading: isLoadingClearQueue,
|
||||||
isLoading: isLoadingCancelQueueItem,
|
isDisabled: isDisabledClearQueue,
|
||||||
isDisabled: isDisabledCancelQueueItem,
|
} = useClearQueue();
|
||||||
} = useCancelCurrentQueueItem();
|
|
||||||
const {
|
const {
|
||||||
resumeProcessor,
|
resumeProcessor,
|
||||||
isLoading: isLoadingResumeProcessor,
|
isLoading: isLoadingResumeProcessor,
|
||||||
@ -55,6 +56,8 @@ export const QueueActionsMenuButton = memo(() => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Box pos="relative">
|
<Box pos="relative">
|
||||||
|
<ClearQueueConfirmationAlertDialog disclosure={clearQueueDisclosure} />
|
||||||
|
|
||||||
<InvMenu
|
<InvMenu
|
||||||
isOpen={isOpen}
|
isOpen={isOpen}
|
||||||
onOpen={onOpen}
|
onOpen={onOpen}
|
||||||
@ -70,11 +73,11 @@ export const QueueActionsMenuButton = memo(() => {
|
|||||||
<InvMenuItem
|
<InvMenuItem
|
||||||
isDestructive
|
isDestructive
|
||||||
icon={<PiXBold size="16px" />}
|
icon={<PiXBold size="16px" />}
|
||||||
onClick={cancelQueueItem}
|
onClick={clearQueueDisclosure.onOpen}
|
||||||
isLoading={isLoadingCancelQueueItem}
|
isLoading={isLoadingClearQueue}
|
||||||
isDisabled={isDisabledCancelQueueItem}
|
isDisabled={isDisabledClearQueue}
|
||||||
>
|
>
|
||||||
{t('queue.cancelTooltip')}
|
{t('queue.clearTooltip')}
|
||||||
</InvMenuItem>
|
</InvMenuItem>
|
||||||
{isResumeEnabled && (
|
{isResumeEnabled && (
|
||||||
<InvMenuItem
|
<InvMenuItem
|
||||||
|
@ -36,53 +36,3 @@ const QueueControls = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default memo(QueueControls);
|
export default memo(QueueControls);
|
||||||
|
|
||||||
// const QueueCounts = () => {
|
|
||||||
// const { t } = useTranslation();
|
|
||||||
// const dispatch = useAppDispatch();
|
|
||||||
// const { hasItems, pending } = useGetQueueStatusQuery(undefined, {
|
|
||||||
// selectFromResult: ({ data }) => {
|
|
||||||
// if (!data) {
|
|
||||||
// return {
|
|
||||||
// hasItems: false,
|
|
||||||
// pending: 0,
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const { pending, in_progress } = data.queue;
|
|
||||||
|
|
||||||
// return {
|
|
||||||
// hasItems: pending + in_progress > 0,
|
|
||||||
// pending,
|
|
||||||
// };
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
|
|
||||||
// const handleClick = useCallback(() => {
|
|
||||||
// dispatch(setActiveTab('queue'));
|
|
||||||
// }, [dispatch]);
|
|
||||||
|
|
||||||
// return (
|
|
||||||
// <Flex
|
|
||||||
// justifyContent="space-between"
|
|
||||||
// alignItems="center"
|
|
||||||
// pe={1}
|
|
||||||
// data-testid="queue-count"
|
|
||||||
// >
|
|
||||||
// <Spacer />
|
|
||||||
// <InvButton
|
|
||||||
// onClick={handleClick}
|
|
||||||
// size="sm"
|
|
||||||
// variant="link"
|
|
||||||
// opacity={0.7}
|
|
||||||
// fontStyle="oblique 10deg"
|
|
||||||
// >
|
|
||||||
// {hasItems
|
|
||||||
// ? t('queue.queuedCount', {
|
|
||||||
// pending,
|
|
||||||
// })
|
|
||||||
// : t('queue.queueEmpty')}
|
|
||||||
// </InvButton>
|
|
||||||
// </Flex>
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
|
Loading…
Reference in New Issue
Block a user