mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
fix(ui): queue count badge positioning
This commit is contained in:
parent
cf5fa792a1
commit
22203b8eb0
@ -1,6 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
Badge,
|
Badge,
|
||||||
Box,
|
|
||||||
IconButton,
|
IconButton,
|
||||||
Menu,
|
Menu,
|
||||||
MenuButton,
|
MenuButton,
|
||||||
@ -18,13 +17,18 @@ 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';
|
||||||
import { setActiveTab } from 'features/ui/store/uiSlice';
|
import { setActiveTab } from 'features/ui/store/uiSlice';
|
||||||
|
import type { RefObject } from 'react';
|
||||||
import { memo, useCallback, useEffect, useRef, useState } from 'react';
|
import { memo, useCallback, useEffect, useRef, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { PiPauseFill, PiPlayFill, PiTrashSimpleBold } from 'react-icons/pi';
|
import { PiPauseFill, PiPlayFill, PiTrashSimpleBold } from 'react-icons/pi';
|
||||||
import { RiListCheck, RiPlayList2Fill } from 'react-icons/ri';
|
import { RiListCheck, RiPlayList2Fill } from 'react-icons/ri';
|
||||||
import { useGetQueueStatusQuery } from 'services/api/endpoints/queue';
|
import { useGetQueueStatusQuery } from 'services/api/endpoints/queue';
|
||||||
|
|
||||||
export const QueueActionsMenuButton = memo(() => {
|
type Props = {
|
||||||
|
containerRef: RefObject<HTMLDivElement>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const QueueActionsMenuButton = memo(({ containerRef }: Props) => {
|
||||||
const { isOpen, onOpen, onClose } = useDisclosure();
|
const { isOpen, onOpen, onClose } = useDisclosure();
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@ -54,14 +58,30 @@ export const QueueActionsMenuButton = memo(() => {
|
|||||||
}, [dispatch]);
|
}, [dispatch]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (menuButtonRef.current) {
|
if (!containerRef.current || !menuButtonRef.current) {
|
||||||
const { x, y } = menuButtonRef.current.getBoundingClientRect();
|
return;
|
||||||
setBadgePos({ x: x - 10, y: y - 10 });
|
|
||||||
}
|
}
|
||||||
}, []);
|
|
||||||
|
const container = containerRef.current;
|
||||||
|
const menuButton = menuButtonRef.current;
|
||||||
|
|
||||||
|
const cb = () => {
|
||||||
|
const { x, y } = menuButton.getBoundingClientRect();
|
||||||
|
setBadgePos({ x: x - 10, y: y - 10 });
|
||||||
|
};
|
||||||
|
|
||||||
|
// // update badge position on resize
|
||||||
|
const resizeObserver = new ResizeObserver(cb);
|
||||||
|
resizeObserver.observe(container);
|
||||||
|
cb();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
resizeObserver.disconnect();
|
||||||
|
};
|
||||||
|
}, [containerRef]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box pos="relative">
|
<>
|
||||||
<Menu isOpen={isOpen} onOpen={onOpen} onClose={onClose} placement="bottom-end">
|
<Menu isOpen={isOpen} onOpen={onOpen} onClose={onClose} placement="bottom-end">
|
||||||
<MenuButton ref={menuButtonRef} as={IconButton} aria-label="Queue Actions Menu" icon={<RiListCheck />} />
|
<MenuButton ref={menuButtonRef} as={IconButton} aria-label="Queue Actions Menu" icon={<RiListCheck />} />
|
||||||
<MenuList>
|
<MenuList>
|
||||||
@ -113,7 +133,7 @@ export const QueueActionsMenuButton = memo(() => {
|
|||||||
</Badge>
|
</Badge>
|
||||||
</Portal>
|
</Portal>
|
||||||
)}
|
)}
|
||||||
</Box>
|
</>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -3,20 +3,21 @@ import { ClearQueueIconButton } from 'features/queue/components/ClearQueueIconBu
|
|||||||
import QueueFrontButton from 'features/queue/components/QueueFrontButton';
|
import QueueFrontButton from 'features/queue/components/QueueFrontButton';
|
||||||
import ProgressBar from 'features/system/components/ProgressBar';
|
import ProgressBar from 'features/system/components/ProgressBar';
|
||||||
import { useFeatureStatus } from 'features/system/hooks/useFeatureStatus';
|
import { useFeatureStatus } from 'features/system/hooks/useFeatureStatus';
|
||||||
import { memo } from 'react';
|
import { memo, useRef } from 'react';
|
||||||
|
|
||||||
import { InvokeQueueBackButton } from './InvokeQueueBackButton';
|
import { InvokeQueueBackButton } from './InvokeQueueBackButton';
|
||||||
import { QueueActionsMenuButton } from './QueueActionsMenuButton';
|
import { QueueActionsMenuButton } from './QueueActionsMenuButton';
|
||||||
|
|
||||||
const QueueControls = () => {
|
const QueueControls = () => {
|
||||||
const isPrependEnabled = useFeatureStatus('prependQueue');
|
const isPrependEnabled = useFeatureStatus('prependQueue');
|
||||||
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
return (
|
return (
|
||||||
<Flex w="full" position="relative" borderRadius="base" gap={2} flexDir="column">
|
<Flex ref={containerRef} w="full" position="relative" borderRadius="base" gap={2} flexDir="column">
|
||||||
<ButtonGroup size="lg" isAttached={false}>
|
<ButtonGroup size="lg" isAttached={false}>
|
||||||
{isPrependEnabled && <QueueFrontButton />}
|
{isPrependEnabled && <QueueFrontButton />}
|
||||||
<InvokeQueueBackButton />
|
<InvokeQueueBackButton />
|
||||||
<Spacer />
|
<Spacer />
|
||||||
<QueueActionsMenuButton />
|
<QueueActionsMenuButton containerRef={containerRef} />
|
||||||
<ClearQueueIconButton />
|
<ClearQueueIconButton />
|
||||||
</ButtonGroup>
|
</ButtonGroup>
|
||||||
<ProgressBar />
|
<ProgressBar />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user