1
1
import { IconButton } from '@invoke-ai/ui-library' ;
2
- import { useAppDispatch } from 'app/store/storeHooks' ;
2
+ import { useAppDispatch , useAppSelector } from 'app/store/storeHooks' ;
3
3
import { boardIdSelected } from 'features/gallery/store/gallerySlice' ;
4
- import { memo , useCallback } from 'react' ;
4
+ import { memo , useCallback , useMemo } from 'react' ;
5
5
import { useTranslation } from 'react-i18next' ;
6
6
import { PiPlusBold } from 'react-icons/pi' ;
7
7
import { useCreateBoardMutation } from 'services/api/endpoints/boards' ;
@@ -13,23 +13,32 @@ type Props = {
13
13
const AddBoardButton = ( { isPrivateBoard } : Props ) => {
14
14
const { t } = useTranslation ( ) ;
15
15
const dispatch = useAppDispatch ( ) ;
16
+ const allowPrivateBoards = useAppSelector ( ( s ) => s . config . allowPrivateBoards ) ;
16
17
const [ createBoard , { isLoading } ] = useCreateBoardMutation ( ) ;
17
- const DEFAULT_BOARD_NAME = t ( 'boards.myBoard' ) ;
18
+ const label = useMemo ( ( ) => {
19
+ if ( ! allowPrivateBoards ) {
20
+ return t ( 'boards.addBoard' ) ;
21
+ }
22
+ if ( isPrivateBoard ) {
23
+ return t ( 'boards.addPrivateBoard' ) ;
24
+ }
25
+ return t ( 'boards.addSharedBoard' ) ;
26
+ } , [ allowPrivateBoards , isPrivateBoard , t ] ) ;
18
27
const handleCreateBoard = useCallback ( async ( ) => {
19
28
try {
20
- const board = await createBoard ( { board_name : DEFAULT_BOARD_NAME , is_private : isPrivateBoard } ) . unwrap ( ) ;
29
+ const board = await createBoard ( { board_name : t ( 'boards.myBoard' ) , is_private : isPrivateBoard } ) . unwrap ( ) ;
21
30
dispatch ( boardIdSelected ( { boardId : board . board_id } ) ) ;
22
31
} catch {
23
32
//no-op
24
33
}
25
- } , [ createBoard , DEFAULT_BOARD_NAME , isPrivateBoard , dispatch ] ) ;
34
+ } , [ t , createBoard , isPrivateBoard , dispatch ] ) ;
26
35
27
36
return (
28
37
< IconButton
29
38
icon = { < PiPlusBold /> }
30
39
isLoading = { isLoading }
31
- tooltip = { t ( 'boards.addBoard' ) }
32
- aria-label = { t ( 'boards.addBoard' ) }
40
+ tooltip = { label }
41
+ aria-label = { label }
33
42
onClick = { handleCreateBoard }
34
43
size = "md"
35
44
data-testid = "add-board-button"
0 commit comments