mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): add useBoardTotal hook to get total items in board
actually not using it now, but it's there
This commit is contained in:
parent
d523556558
commit
1e3cebbf42
@ -17,7 +17,7 @@ type GenericBoardProps = {
|
|||||||
badgeCount?: number;
|
badgeCount?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
const formatBadgeCount = (count: number) =>
|
export const formatBadgeCount = (count: number) =>
|
||||||
Intl.NumberFormat('en-US', {
|
Intl.NumberFormat('en-US', {
|
||||||
notation: 'compact',
|
notation: 'compact',
|
||||||
maximumFractionDigits: 1,
|
maximumFractionDigits: 1,
|
||||||
|
@ -4,7 +4,7 @@ import { createSelector } from '@reduxjs/toolkit';
|
|||||||
import { stateSelector } from 'app/store/store';
|
import { stateSelector } from 'app/store/store';
|
||||||
import { useAppSelector } from 'app/store/storeHooks';
|
import { useAppSelector } from 'app/store/storeHooks';
|
||||||
import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions';
|
import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions';
|
||||||
import { memo } from 'react';
|
import { memo, useMemo } from 'react';
|
||||||
import { useBoardName } from 'services/api/hooks/useBoardName';
|
import { useBoardName } from 'services/api/hooks/useBoardName';
|
||||||
|
|
||||||
const selector = createSelector(
|
const selector = createSelector(
|
||||||
@ -26,6 +26,12 @@ const GalleryBoardName = (props: Props) => {
|
|||||||
const { isOpen, onToggle } = props;
|
const { isOpen, onToggle } = props;
|
||||||
const { selectedBoardId } = useAppSelector(selector);
|
const { selectedBoardId } = useAppSelector(selector);
|
||||||
const boardName = useBoardName(selectedBoardId);
|
const boardName = useBoardName(selectedBoardId);
|
||||||
|
const formattedBoardName = useMemo(() => {
|
||||||
|
if (boardName.length > 20) {
|
||||||
|
return `${boardName.substring(0, 20)}...`;
|
||||||
|
}
|
||||||
|
return boardName;
|
||||||
|
}, [boardName]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex
|
<Flex
|
||||||
@ -58,9 +64,7 @@ const GalleryBoardName = (props: Props) => {
|
|||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{boardName.length > 20
|
{formattedBoardName}
|
||||||
? `${boardName.substring(0, 20)}...`
|
|
||||||
: boardName}
|
|
||||||
</Text>
|
</Text>
|
||||||
</Box>
|
</Box>
|
||||||
<Spacer />
|
<Spacer />
|
||||||
|
@ -0,0 +1,53 @@
|
|||||||
|
import { skipToken } from '@reduxjs/toolkit/dist/query';
|
||||||
|
import {
|
||||||
|
ASSETS_CATEGORIES,
|
||||||
|
BoardId,
|
||||||
|
IMAGE_CATEGORIES,
|
||||||
|
INITIAL_IMAGE_LIMIT,
|
||||||
|
} from 'features/gallery/store/gallerySlice';
|
||||||
|
import { useMemo } from 'react';
|
||||||
|
import { ListImagesArgs, useListImagesQuery } from '../endpoints/images';
|
||||||
|
|
||||||
|
const baseQueryArg: ListImagesArgs = {
|
||||||
|
offset: 0,
|
||||||
|
limit: INITIAL_IMAGE_LIMIT,
|
||||||
|
is_intermediate: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
const imagesQueryArg: ListImagesArgs = {
|
||||||
|
categories: IMAGE_CATEGORIES,
|
||||||
|
...baseQueryArg,
|
||||||
|
};
|
||||||
|
|
||||||
|
const assetsQueryArg: ListImagesArgs = {
|
||||||
|
categories: ASSETS_CATEGORIES,
|
||||||
|
...baseQueryArg,
|
||||||
|
};
|
||||||
|
|
||||||
|
const noBoardQueryArg: ListImagesArgs = {
|
||||||
|
board_id: 'none',
|
||||||
|
...baseQueryArg,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useBoardTotal = (board_id: BoardId | null | undefined) => {
|
||||||
|
const queryArg = useMemo(() => {
|
||||||
|
if (!board_id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (board_id === 'images') {
|
||||||
|
return imagesQueryArg;
|
||||||
|
} else if (board_id === 'assets') {
|
||||||
|
return assetsQueryArg;
|
||||||
|
} else if (board_id === 'no_board') {
|
||||||
|
return noBoardQueryArg;
|
||||||
|
} else {
|
||||||
|
return { board_id, ...baseQueryArg };
|
||||||
|
}
|
||||||
|
}, [board_id]);
|
||||||
|
|
||||||
|
const { total } = useListImagesQuery(queryArg ?? skipToken, {
|
||||||
|
selectFromResult: ({ currentData }) => ({ total: currentData?.total }),
|
||||||
|
});
|
||||||
|
|
||||||
|
return total;
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user