From 7bbe23610757bb7d85cd5515f458a4a024c7e5a0 Mon Sep 17 00:00:00 2001 From: Mary Hipp Date: Sun, 23 Jun 2024 19:26:04 -0400 Subject: [PATCH] implmenet custom sort to replace images adapter logic --- .../listeners/socketio/socketInvocationComplete.ts | 5 +++-- invokeai/frontend/web/src/services/api/util.ts | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/socketio/socketInvocationComplete.ts b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/socketio/socketInvocationComplete.ts index 55af131c93..dd1535536d 100644 --- a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/socketio/socketInvocationComplete.ts +++ b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/socketio/socketInvocationComplete.ts @@ -15,7 +15,7 @@ import { zNodeStatus } from 'features/nodes/types/invocation'; import { CANVAS_OUTPUT } from 'features/nodes/util/graph/constants'; import { boardsApi } from 'services/api/endpoints/boards'; import { imagesApi } from 'services/api/endpoints/images'; -import { imagesAdapter } from 'services/api/util'; +import { imageListDefaultSort, imagesAdapter } from 'services/api/util'; import { socketInvocationComplete } from 'services/events/actions'; // These nodes output an image, but do not actually *save* an image, so we don't want to handle the gallery logic on them @@ -68,7 +68,8 @@ export const addInvocationCompleteEventListener = (startAppListening: AppStartLi is_intermediate: false }, (draft) => { - const updatedListLength = draft.items.unshift(imageDTO) + const updatedListLength = draft.items.unshift(imageDTO); + draft.items.sort(imageListDefaultSort()) if (updatedListLength > IMAGE_LIMIT) { draft.items.pop() } diff --git a/invokeai/frontend/web/src/services/api/util.ts b/invokeai/frontend/web/src/services/api/util.ts index a7a5d6451e..aa952f51bc 100644 --- a/invokeai/frontend/web/src/services/api/util.ts +++ b/invokeai/frontend/web/src/services/api/util.ts @@ -75,6 +75,19 @@ export const imagesAdapter = createEntityAdapter({ }, }); +export const imageListDefaultSort = () => { + return (a: ImageDTO, b: ImageDTO) => { + if (a.starred && !b.starred) { + return -1; + } + if (!a.starred && b.starred) { + return 1; + } + return dateComparator(b.created_at, a.created_at); + } + +} + // Create selectors for the adapter. export const imagesSelectors = imagesAdapter.getSelectors(undefined, getSelectorsOptions);