From e03c88ce32378349480f59ebaf3fb25dff462a50 Mon Sep 17 00:00:00 2001 From: Josh Corbett Date: Thu, 18 Jan 2024 20:07:56 -0700 Subject: [PATCH] feat: :children_crossing: shift key queue cancellations --- .../queue/components/ClearQueueIconButton.tsx | 57 +++++++++++++++++-- .../components/QueueActionsMenuButton.tsx | 21 ++++--- .../queue/components/QueueControls.tsx | 50 ---------------- 3 files changed, 63 insertions(+), 65 deletions(-) diff --git a/invokeai/frontend/web/src/features/queue/components/ClearQueueIconButton.tsx b/invokeai/frontend/web/src/features/queue/components/ClearQueueIconButton.tsx index 1ec0d22ce8..2d6904e783 100644 --- a/invokeai/frontend/web/src/features/queue/components/ClearQueueIconButton.tsx +++ b/invokeai/frontend/web/src/features/queue/components/ClearQueueIconButton.tsx @@ -2,16 +2,17 @@ import { useDisclosure } from '@chakra-ui/react'; import { InvIconButton } from 'common/components/InvIconButton/InvIconButton'; import type { InvIconButtonProps } from 'common/components/InvIconButton/types'; import ClearQueueConfirmationAlertDialog from 'features/queue/components/ClearQueueConfirmationAlertDialog'; +import { useCancelCurrentQueueItem } from 'features/queue/hooks/useCancelCurrentQueueItem'; 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 { PiTrashSimpleBold } from 'react-icons/pi'; type Props = Omit; -const ClearQueueIconButton = (props: Props) => { +const ClearQueueIconButton = ({ onOpen, ...props }: Props & { onOpen: () => void }) => { const { t } = useTranslation(); - const disclosure = useDisclosure(); const { isLoading, isDisabled } = useClearQueue(); return ( @@ -23,13 +24,57 @@ const ClearQueueIconButton = (props: Props) => { tooltip={t('queue.clearTooltip')} icon={} colorScheme="error" - onClick={disclosure.onOpen} + onClick={onOpen} data-testid={t('queue.clear')} {...props} /> - ); }; -export default memo(ClearQueueIconButton); +const ClearSingleQueueItemIconButton = (props: Props) => { + const { t } = useTranslation(); + const { + cancelQueueItem, + isLoading, + isDisabled, + } = useCancelCurrentQueueItem(); + + return ( + <> + } + 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 + ? + : + } + + + ) +} + +export default ClearQueueButton; diff --git a/invokeai/frontend/web/src/features/queue/components/QueueActionsMenuButton.tsx b/invokeai/frontend/web/src/features/queue/components/QueueActionsMenuButton.tsx index e2d4d8e532..8d7d1315bc 100644 --- a/invokeai/frontend/web/src/features/queue/components/QueueActionsMenuButton.tsx +++ b/invokeai/frontend/web/src/features/queue/components/QueueActionsMenuButton.tsx @@ -10,7 +10,8 @@ import { InvMenuButton, InvMenuDivider, } 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 { useResumeProcessor } from 'features/queue/hooks/useResumeProcessor'; import { useFeatureStatus } from 'features/system/hooks/useFeatureStatus'; @@ -25,6 +26,7 @@ export const QueueActionsMenuButton = memo(() => { const { isOpen, onOpen, onClose } = useDisclosure(); const dispatch = useAppDispatch(); const { t } = useTranslation(); + const clearQueueDisclosure = useDisclosure() const isPauseEnabled = useFeatureStatus('pauseQueue').isFeatureEnabled; const isResumeEnabled = useFeatureStatus('resumeQueue').isFeatureEnabled; const { queueSize } = useGetQueueStatusQuery(undefined, { @@ -35,10 +37,9 @@ export const QueueActionsMenuButton = memo(() => { }), }); const { - cancelQueueItem, - isLoading: isLoadingCancelQueueItem, - isDisabled: isDisabledCancelQueueItem, - } = useCancelCurrentQueueItem(); + isLoading: isLoadingClearQueue, + isDisabled: isDisabledClearQueue, + } = useClearQueue(); const { resumeProcessor, isLoading: isLoadingResumeProcessor, @@ -55,6 +56,8 @@ export const QueueActionsMenuButton = memo(() => { return ( + + { } - onClick={cancelQueueItem} - isLoading={isLoadingCancelQueueItem} - isDisabled={isDisabledCancelQueueItem} + onClick={clearQueueDisclosure.onOpen} + isLoading={isLoadingClearQueue} + isDisabled={isDisabledClearQueue} > - {t('queue.cancelTooltip')} + {t('queue.clearTooltip')} {isResumeEnabled && ( { }; 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 ( -// -// -// -// {hasItems -// ? t('queue.queuedCount', { -// pending, -// }) -// : t('queue.queueEmpty')} -// -// -// ); -// };