implmenet custom sort to replace images adapter logic

This commit is contained in:
Mary Hipp 2024-06-23 19:26:04 -04:00 committed by psychedelicious
parent 719c066ac4
commit 7bbe236107
2 changed files with 16 additions and 2 deletions

View File

@ -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()
}

View File

@ -75,6 +75,19 @@ export const imagesAdapter = createEntityAdapter<ImageDTO, string>({
},
});
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);