mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-02-16 21:41:28 -05:00
fix(ui): fix all circular dependencies
This commit is contained in:
@@ -2,8 +2,7 @@ import { Update } from '@reduxjs/toolkit';
|
||||
import {
|
||||
ASSETS_CATEGORIES,
|
||||
IMAGE_CATEGORIES,
|
||||
boardIdSelected,
|
||||
} from 'features/gallery/store/gallerySlice';
|
||||
} from 'features/gallery/store/types';
|
||||
import {
|
||||
BoardDTO,
|
||||
ImageDTO,
|
||||
|
||||
@@ -5,8 +5,7 @@ import {
|
||||
ASSETS_CATEGORIES,
|
||||
BoardId,
|
||||
IMAGE_CATEGORIES,
|
||||
} from 'features/gallery/store/gallerySlice';
|
||||
import { getCategories } from 'features/gallery/store/util';
|
||||
} from 'features/gallery/store/types';
|
||||
import queryString from 'query-string';
|
||||
import { ApiFullTagDescription, api } from '..';
|
||||
import { components, paths } from '../schema';
|
||||
@@ -16,7 +15,37 @@ import {
|
||||
OffsetPaginatedResults_ImageDTO_,
|
||||
PostUploadAction,
|
||||
} from '../types';
|
||||
import { getIsImageInDateRange } from './util';
|
||||
|
||||
const getIsImageInDateRange = (
|
||||
data: ImageCache | undefined,
|
||||
imageDTO: ImageDTO
|
||||
) => {
|
||||
if (!data) {
|
||||
return false;
|
||||
}
|
||||
const cacheImageDTOS = imagesSelectors.selectAll(data);
|
||||
|
||||
if (cacheImageDTOS.length > 1) {
|
||||
// Images are sorted by `created_at` DESC
|
||||
// check if the image is newer than the oldest image in the cache
|
||||
const createdDate = new Date(imageDTO.created_at);
|
||||
const oldestDate = new Date(
|
||||
cacheImageDTOS[cacheImageDTOS.length - 1].created_at
|
||||
);
|
||||
return createdDate >= oldestDate;
|
||||
} else if ([0, 1].includes(cacheImageDTOS.length)) {
|
||||
// if there are only 1 or 0 images in the cache, we consider the image to be in the date range
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
const getCategories = (imageDTO: ImageDTO) => {
|
||||
if (IMAGE_CATEGORIES.includes(imageDTO.image_category)) {
|
||||
return IMAGE_CATEGORIES;
|
||||
}
|
||||
return ASSETS_CATEGORIES;
|
||||
};
|
||||
|
||||
export type ListImagesArgs = NonNullable<
|
||||
paths['/api/v1/images/']['get']['parameters']['query']
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
import { ImageDTO } from '../types';
|
||||
import { ImageCache, imagesSelectors } from './images';
|
||||
|
||||
export const getIsImageInDateRange = (
|
||||
data: ImageCache | undefined,
|
||||
imageDTO: ImageDTO
|
||||
) => {
|
||||
if (!data) {
|
||||
return false;
|
||||
}
|
||||
const cacheImageDTOS = imagesSelectors.selectAll(data);
|
||||
|
||||
if (cacheImageDTOS.length > 1) {
|
||||
// Images are sorted by `created_at` DESC
|
||||
// check if the image is newer than the oldest image in the cache
|
||||
const createdDate = new Date(imageDTO.created_at);
|
||||
const oldestDate = new Date(
|
||||
cacheImageDTOS[cacheImageDTOS.length - 1].created_at
|
||||
);
|
||||
return createdDate >= oldestDate;
|
||||
} else if ([0, 1].includes(cacheImageDTOS.length)) {
|
||||
// if there are only 1 or 0 images in the cache, we consider the image to be in the date range
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
// /**
|
||||
// * Determines the action we should take when an image may need to be added or updated in a cache.
|
||||
// */
|
||||
// export const getCacheAction = (
|
||||
// data: ImageCache | undefined,
|
||||
// imageDTO: ImageDTO
|
||||
// ): 'add' | 'update' | 'none' => {
|
||||
// const isInDateRange = getIsImageInDateRange(data, imageDTO);
|
||||
// const isCacheFullyPopulated = data && data.total === data.ids.length;
|
||||
// const shouldUpdateCache =
|
||||
// Boolean(isInDateRange) || Boolean(isCacheFullyPopulated);
|
||||
|
||||
// const isImageInCache = data && data.ids.includes(imageDTO.image_name);
|
||||
|
||||
// if (shouldUpdateCache && isImageInCache) {
|
||||
// return 'update';
|
||||
// }
|
||||
|
||||
// if (shouldUpdateCache && !isImageInCache) {
|
||||
// return 'add';
|
||||
// }
|
||||
|
||||
// return 'none';
|
||||
// };
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BoardId } from 'features/gallery/store/gallerySlice';
|
||||
import { BoardId } from 'features/gallery/store/types';
|
||||
import { useListAllBoardsQuery } from '../endpoints/boards';
|
||||
|
||||
export const useBoardName = (board_id: BoardId | null | undefined) => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useAppSelector } from 'app/store/storeHooks';
|
||||
import { BoardId } from 'features/gallery/store/gallerySlice';
|
||||
import { BoardId } from 'features/gallery/store/types';
|
||||
import { useMemo } from 'react';
|
||||
import {
|
||||
useGetBoardAssetsTotalQuery,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { isAnyOf } from '@reduxjs/toolkit';
|
||||
import { createAppAsyncThunk } from 'app/store/storeUtils';
|
||||
import { createAsyncThunk, isAnyOf } from '@reduxjs/toolkit';
|
||||
import { isObject } from 'lodash-es';
|
||||
import { $client } from 'services/api/client';
|
||||
import { paths } from 'services/api/schema';
|
||||
@@ -25,7 +24,7 @@ type CreateSessionThunkConfig = {
|
||||
/**
|
||||
* `SessionsService.createSession()` thunk
|
||||
*/
|
||||
export const sessionCreated = createAppAsyncThunk<
|
||||
export const sessionCreated = createAsyncThunk<
|
||||
CreateSessionResponse,
|
||||
CreateSessionArg,
|
||||
CreateSessionThunkConfig
|
||||
@@ -63,7 +62,7 @@ const isErrorWithStatus = (error: unknown): error is { status: number } =>
|
||||
/**
|
||||
* `SessionsService.invokeSession()` thunk
|
||||
*/
|
||||
export const sessionInvoked = createAppAsyncThunk<
|
||||
export const sessionInvoked = createAsyncThunk<
|
||||
InvokedSessionResponse,
|
||||
InvokedSessionArg,
|
||||
InvokedSessionThunkConfig
|
||||
@@ -101,7 +100,7 @@ type CancelSessionThunkConfig = {
|
||||
/**
|
||||
* `SessionsService.cancelSession()` thunk
|
||||
*/
|
||||
export const sessionCanceled = createAppAsyncThunk<
|
||||
export const sessionCanceled = createAsyncThunk<
|
||||
CancelSessionResponse,
|
||||
CancelSessionArg,
|
||||
CancelSessionThunkConfig
|
||||
@@ -141,7 +140,7 @@ type ListSessionsThunkConfig = {
|
||||
/**
|
||||
* `SessionsService.listSessions()` thunk
|
||||
*/
|
||||
export const listedSessions = createAppAsyncThunk<
|
||||
export const listedSessions = createAsyncThunk<
|
||||
ListSessionsResponse,
|
||||
ListSessionsArg,
|
||||
ListSessionsThunkConfig
|
||||
|
||||
Reference in New Issue
Block a user