diff --git a/packages/pl-fe/src/entity-store/reducer.ts b/packages/pl-fe/src/entity-store/reducer.ts index dd52dbd6c..b24dad8ef 100644 --- a/packages/pl-fe/src/entity-store/reducer.ts +++ b/packages/pl-fe/src/entity-store/reducer.ts @@ -2,15 +2,9 @@ import { create, type Immutable, type Draft } from 'mutative'; import { ENTITIES_IMPORT, ENTITIES_TRANSACTION, type EntityAction } from './actions'; import { Entities } from './entities'; -import { createCache, createList, updateStore, updateList } from './utils'; +import { createCache, updateStore } from './utils'; -import type { - EntitiesTransaction, - Entity, - EntityCache, - EntityListState, - ImportPosition, -} from './types'; +import type { EntitiesTransaction, Entity, EntityCache } from './types'; /** Entity reducer state. */ type State = Immutable<{ @@ -18,34 +12,10 @@ type State = Immutable<{ }>; /** Import entities into the cache. */ -const importEntities = ( - draft: Draft, - entityType: Entities, - entities: Entity[], - listKey?: string, - pos?: ImportPosition, - newState?: EntityListState, - overwrite = false, -) => { +const importEntities = (draft: Draft, entityType: Entities, entities: Entity[]) => { const cache = draft[entityType] ?? createCache(); cache.store = updateStore(cache.store, entities); - if (typeof listKey === 'string') { - let list = cache.lists[listKey] ?? createList(); - - if (overwrite) { - list.ids = new Set(); - } - - list = updateList(list, entities, pos); - - if (newState) { - list.state = newState; - } - - cache.lists[listKey] = list; - } - draft[entityType] = cache; }; diff --git a/packages/pl-fe/src/entity-store/types.ts b/packages/pl-fe/src/entity-store/types.ts index 7bf6c6654..cbf50cd38 100644 --- a/packages/pl-fe/src/entity-store/types.ts +++ b/packages/pl-fe/src/entity-store/types.ts @@ -1,5 +1,3 @@ -import type { PaginatedResponse } from 'pl-api'; - /** A Mastodon API entity. */ interface Entity { /** Unique ID for the entity (usually the primary key in the database). */ @@ -11,36 +9,10 @@ interface EntityStore { [id: string]: TEntity | undefined; } -/** List of entity IDs and fetch state. */ -interface EntityList { - /** Set of entity IDs in this list. */ - ids: Set; - /** Server state for this entity list. */ - state: EntityListState; -} - -/** Fetch state for an entity list. */ -interface EntityListState { - /** Next URL for pagination, if any. */ - next: (() => Promise>) | null; - /** Previous URL for pagination, if any. */ - prev: (() => Promise>) | null; - /** Error returned from the API, if any. */ - error: unknown; - /** Whether data has already been fetched */ - fetched: boolean; - /** Whether data for this list is currently being fetched. */ - fetching: boolean; -} - -/** Cache data pertaining to a paritcular entity type.. */ +/** Cache data pertaining to a paritcular entity type. */ interface EntityCache { /** Map of entities of this type. */ store: EntityStore; - /** Lists of entity IDs for a particular purpose. */ - lists: { - [listKey: string]: EntityList | undefined; - }; } /** Whether to import items at the start or end of the list. */ @@ -53,12 +25,4 @@ interface EntitiesTransaction { }; } -export type { - Entity, - EntityStore, - EntityList, - EntityListState, - EntityCache, - ImportPosition, - EntitiesTransaction, -}; +export type { Entity, EntityStore, EntityCache, ImportPosition, EntitiesTransaction }; diff --git a/packages/pl-fe/src/entity-store/utils.ts b/packages/pl-fe/src/entity-store/utils.ts index f536d8a99..d919ad280 100644 --- a/packages/pl-fe/src/entity-store/utils.ts +++ b/packages/pl-fe/src/entity-store/utils.ts @@ -1,11 +1,4 @@ -import type { - Entity, - EntityStore, - EntityList, - EntityCache, - EntityListState, - ImportPosition, -} from './types'; +import type { Entity, EntityStore, EntityCache } from './types'; /** Insert the entities into the store. */ const updateStore = (store: EntityStore, entities: Entity[]): EntityStore => @@ -17,41 +10,9 @@ const updateStore = (store: EntityStore, entities: Entity[]): EntityStore => { ...store }, ); -/** Update the list with new entity IDs. */ -const updateList = ( - list: EntityList, - entities: Entity[], - pos: ImportPosition = 'end', -): EntityList => { - const newIds = entities.map((entity) => entity.id); - const oldIds = Array.from(list.ids); - const ids = new Set(pos === 'start' ? [...newIds, ...oldIds] : [...oldIds, ...newIds]); - - return { - ...list, - ids, - }; -}; - /** Create an empty entity cache. */ const createCache = (): EntityCache => ({ store: {}, - lists: {}, }); -/** Create an empty entity list. */ -const createList = (): EntityList => ({ - ids: new Set(), - state: createListState(), -}); - -/** Create an empty entity list state. */ -const createListState = (): EntityListState => ({ - next: null, - prev: null, - error: null, - fetched: false, - fetching: false, -}); - -export { updateStore, updateList, createCache, createList }; +export { updateStore, createCache };