feat(ui): add board button tooltip when private boards enabled

This commit is contained in:
psychedelicious 2024-07-09 22:51:08 +10:00
parent 2460689c00
commit 476ebd13ae
2 changed files with 18 additions and 7 deletions

View File

@ -17,6 +17,8 @@
},
"boards": {
"addBoard": "Add Board",
"addPrivateBoard": "Add Private Board",
"addSharedBoard": "Add Shared Board",
"archiveBoard": "Archive Board",
"archived": "Archived",
"autoAddBoard": "Auto-Add Board",

View File

@ -1,7 +1,7 @@
import { IconButton } from '@invoke-ai/ui-library';
import { useAppDispatch } from 'app/store/storeHooks';
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
import { boardIdSelected } from 'features/gallery/store/gallerySlice';
import { memo, useCallback } from 'react';
import { memo, useCallback, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { PiPlusBold } from 'react-icons/pi';
import { useCreateBoardMutation } from 'services/api/endpoints/boards';
@ -13,23 +13,32 @@ type Props = {
const AddBoardButton = ({ isPrivateBoard }: Props) => {
const { t } = useTranslation();
const dispatch = useAppDispatch();
const allowPrivateBoards = useAppSelector((s) => s.config.allowPrivateBoards);
const [createBoard, { isLoading }] = useCreateBoardMutation();
const DEFAULT_BOARD_NAME = t('boards.myBoard');
const label = useMemo(() => {
if (!allowPrivateBoards) {
return t('boards.addBoard');
}
if (isPrivateBoard) {
return t('boards.addPrivateBoard');
}
return t('boards.addSharedBoard');
}, [allowPrivateBoards, isPrivateBoard, t]);
const handleCreateBoard = useCallback(async () => {
try {
const board = await createBoard({ board_name: DEFAULT_BOARD_NAME, is_private: isPrivateBoard }).unwrap();
const board = await createBoard({ board_name: t('boards.myBoard'), is_private: isPrivateBoard }).unwrap();
dispatch(boardIdSelected({ boardId: board.board_id }));
} catch {
//no-op
}
}, [createBoard, DEFAULT_BOARD_NAME, isPrivateBoard, dispatch]);
}, [t, createBoard, isPrivateBoard, dispatch]);
return (
<IconButton
icon={<PiPlusBold />}
isLoading={isLoading}
tooltip={t('boards.addBoard')}
aria-label={t('boards.addBoard')}
tooltip={label}
aria-label={label}
onClick={handleCreateBoard}
size="md"
data-testid="add-board-button"