mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
(ui) allow auto-add on archived boards, reset to uncategorized if auto-add board is not currently visible due to archived view
This commit is contained in:
parent
5709f82e5f
commit
dc90de600d
@ -51,6 +51,8 @@ import { addUpscaleRequestedListener } from 'app/store/middleware/listenerMiddle
|
|||||||
import { addWorkflowLoadRequestedListener } from 'app/store/middleware/listenerMiddleware/listeners/workflowLoadRequested';
|
import { addWorkflowLoadRequestedListener } from 'app/store/middleware/listenerMiddleware/listeners/workflowLoadRequested';
|
||||||
import type { AppDispatch, RootState } from 'app/store/store';
|
import type { AppDispatch, RootState } from 'app/store/store';
|
||||||
|
|
||||||
|
import { addCheckAutoAddBoardVisibleListener } from './listeners/checkAutoAddBoardVisible';
|
||||||
|
|
||||||
export const listenerMiddleware = createListenerMiddleware();
|
export const listenerMiddleware = createListenerMiddleware();
|
||||||
|
|
||||||
export type AppStartListening = TypedStartListening<RootState, AppDispatch>;
|
export type AppStartListening = TypedStartListening<RootState, AppDispatch>;
|
||||||
@ -116,6 +118,7 @@ addControlNetAutoProcessListener(startAppListening);
|
|||||||
addImageAddedToBoardFulfilledListener(startAppListening);
|
addImageAddedToBoardFulfilledListener(startAppListening);
|
||||||
addImageRemovedFromBoardFulfilledListener(startAppListening);
|
addImageRemovedFromBoardFulfilledListener(startAppListening);
|
||||||
addBoardIdSelectedListener(startAppListening);
|
addBoardIdSelectedListener(startAppListening);
|
||||||
|
addCheckAutoAddBoardVisibleListener(startAppListening);
|
||||||
|
|
||||||
// Node schemas
|
// Node schemas
|
||||||
addGetOpenAPISchemaListener(startAppListening);
|
addGetOpenAPISchemaListener(startAppListening);
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
import type { AppStartListening } from 'app/store/middleware/listenerMiddleware';
|
||||||
|
import { checkAutoAddBoardVisible } from 'features/gallery/store/actions';
|
||||||
|
import { selectListBoardsQueryArgs } from 'features/gallery/store/gallerySelectors';
|
||||||
|
import { autoAddBoardIdChanged } from 'features/gallery/store/gallerySlice';
|
||||||
|
import { boardsApi } from 'services/api/endpoints/boards';
|
||||||
|
|
||||||
|
export const addCheckAutoAddBoardVisibleListener = (startAppListening: AppStartListening) => {
|
||||||
|
startAppListening({
|
||||||
|
actionCreator: checkAutoAddBoardVisible,
|
||||||
|
effect: async (action, { dispatch, getState }) => {
|
||||||
|
const state = getState();
|
||||||
|
const queryArgs = selectListBoardsQueryArgs(state);
|
||||||
|
const queryResult = boardsApi.endpoints.listAllBoards.select(queryArgs)(state);
|
||||||
|
const autoAddBoardId = state.gallery.autoAddBoardId;
|
||||||
|
|
||||||
|
if (!queryResult.data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!queryResult.data.find((board) => board.board_id === autoAddBoardId)) {
|
||||||
|
dispatch(autoAddBoardIdChanged('none'));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
@ -2,8 +2,10 @@ import type { ContextMenuProps } from '@invoke-ai/ui-library';
|
|||||||
import { ContextMenu, MenuGroup, MenuItem, MenuList } from '@invoke-ai/ui-library';
|
import { ContextMenu, MenuGroup, MenuItem, MenuList } from '@invoke-ai/ui-library';
|
||||||
import { createSelector } from '@reduxjs/toolkit';
|
import { createSelector } from '@reduxjs/toolkit';
|
||||||
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||||
|
import { checkAutoAddBoardVisible } from 'features/gallery/store/actions';
|
||||||
import { autoAddBoardIdChanged, selectGallerySlice } from 'features/gallery/store/gallerySlice';
|
import { autoAddBoardIdChanged, selectGallerySlice } from 'features/gallery/store/gallerySlice';
|
||||||
import { useFeatureStatus } from 'features/system/hooks/useFeatureStatus';
|
import { useFeatureStatus } from 'features/system/hooks/useFeatureStatus';
|
||||||
|
import { toast } from 'features/toast/toast';
|
||||||
import { memo, useCallback, useMemo } from 'react';
|
import { memo, useCallback, useMemo } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { PiArchiveBold, PiArchiveFill, PiDownloadBold, PiPlusBold } from 'react-icons/pi';
|
import { PiArchiveBold, PiArchiveFill, PiDownloadBold, PiPlusBold } from 'react-icons/pi';
|
||||||
@ -45,12 +47,20 @@ const BoardContextMenu = ({ board, setBoardToDelete, children }: Props) => {
|
|||||||
bulkDownload({ image_names: [], board_id: board.board_id });
|
bulkDownload({ image_names: [], board_id: board.board_id });
|
||||||
}, [board.board_id, bulkDownload]);
|
}, [board.board_id, bulkDownload]);
|
||||||
|
|
||||||
const handleArchive = useCallback(() => {
|
const handleArchive = useCallback(async () => {
|
||||||
updateBoard({
|
try {
|
||||||
board_id: board.board_id,
|
await updateBoard({
|
||||||
changes: { archived: true },
|
board_id: board.board_id,
|
||||||
});
|
changes: { archived: true },
|
||||||
}, [board.board_id, updateBoard]);
|
}).unwrap();
|
||||||
|
dispatch(checkAutoAddBoardVisible());
|
||||||
|
} catch (error) {
|
||||||
|
toast({
|
||||||
|
status: 'error',
|
||||||
|
title: 'Unable to archive board',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [board.board_id, updateBoard, dispatch]);
|
||||||
|
|
||||||
const handleUnarchive = useCallback(() => {
|
const handleUnarchive = useCallback(() => {
|
||||||
updateBoard({
|
updateBoard({
|
||||||
@ -65,7 +75,7 @@ const BoardContextMenu = ({ board, setBoardToDelete, children }: Props) => {
|
|||||||
<MenuGroup title={boardName}>
|
<MenuGroup title={boardName}>
|
||||||
<MenuItem
|
<MenuItem
|
||||||
icon={<PiPlusBold />}
|
icon={<PiPlusBold />}
|
||||||
isDisabled={isSelectedForAutoAdd || autoAssignBoardOnClick || Boolean(board?.archived)}
|
isDisabled={isSelectedForAutoAdd || autoAssignBoardOnClick}
|
||||||
onClick={handleSetAutoAdd}
|
onClick={handleSetAutoAdd}
|
||||||
>
|
>
|
||||||
{t('boards.menuItemAutoAdd')}
|
{t('boards.menuItemAutoAdd')}
|
||||||
@ -83,7 +93,7 @@ const BoardContextMenu = ({ board, setBoardToDelete, children }: Props) => {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{!board.archived && (
|
{!board.archived && (
|
||||||
<MenuItem icon={<PiArchiveFill />} onClick={handleArchive} isDisabled={isSelectedForAutoAdd}>
|
<MenuItem icon={<PiArchiveFill />} onClick={handleArchive}>
|
||||||
{t('boards.archiveBoard')}
|
{t('boards.archiveBoard')}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
)}
|
)}
|
||||||
|
@ -14,6 +14,7 @@ import {
|
|||||||
Switch,
|
Switch,
|
||||||
} from '@invoke-ai/ui-library';
|
} from '@invoke-ai/ui-library';
|
||||||
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||||
|
import { checkAutoAddBoardVisible } from 'features/gallery/store/actions';
|
||||||
import {
|
import {
|
||||||
alwaysShowImageSizeBadgeChanged,
|
alwaysShowImageSizeBadgeChanged,
|
||||||
autoAssignBoardOnClickChanged,
|
autoAssignBoardOnClickChanged,
|
||||||
@ -66,7 +67,10 @@ const GallerySettingsPopover = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const handleChangeShouldShowArchivedBoardsChanged = useCallback(
|
const handleChangeShouldShowArchivedBoardsChanged = useCallback(
|
||||||
(e: ChangeEvent<HTMLInputElement>) => dispatch(shouldShowArchivedBoardsChanged(e.target.checked)),
|
(e: ChangeEvent<HTMLInputElement>) => {
|
||||||
|
dispatch(shouldShowArchivedBoardsChanged(e.target.checked));
|
||||||
|
dispatch(checkAutoAddBoardVisible());
|
||||||
|
},
|
||||||
[dispatch]
|
[dispatch]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -5,3 +5,5 @@ export const sentImageToCanvas = createAction('gallery/sentImageToCanvas');
|
|||||||
export const sentImageToImg2Img = createAction('gallery/sentImageToImg2Img');
|
export const sentImageToImg2Img = createAction('gallery/sentImageToImg2Img');
|
||||||
|
|
||||||
export const imageDownloaded = createAction('gallery/imageDownloaded');
|
export const imageDownloaded = createAction('gallery/imageDownloaded');
|
||||||
|
|
||||||
|
export const checkAutoAddBoardVisible = createAction('gallery/checkAutoAddBoardVisible');
|
||||||
|
@ -128,6 +128,7 @@ export const gallerySlice = createSlice({
|
|||||||
});
|
});
|
||||||
builder.addMatcher(boardsApi.endpoints.listAllBoards.matchFulfilled, (state, action) => {
|
builder.addMatcher(boardsApi.endpoints.listAllBoards.matchFulfilled, (state, action) => {
|
||||||
const boards = action.payload;
|
const boards = action.payload;
|
||||||
|
|
||||||
if (!state.autoAddBoardId) {
|
if (!state.autoAddBoardId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user