Merge branch 'chats-pleroma' into chats

revert-fa4bd20d
Alex Gleason 2022-12-06 14:36:38 -06:00
commit 569296af36
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
2 zmienionych plików z 18 dodań i 3 usunięć

Wyświetl plik

@ -136,9 +136,9 @@ const useChats = (search?: string) => {
const nextPageLink = pageParam?.link;
const uri = nextPageLink || endpoint;
const response = await api.get<IChat[]>(uri, {
params: {
params: search ? {
search,
},
} : undefined,
});
const { data } = response;

Wyświetl plik

@ -8,12 +8,27 @@ export interface PaginatedResult<T> {
link?: string,
}
/** Deduplicate an array of entities by their ID. */
const deduplicate = <T>(entities: T[]): T[] => {
const map = entities.reduce<Map<string, T>>((result, entity) => {
// @ts-expect-error Entity might not have an ID... but it probably does.
return result.set(entity.id, entity);
}, new Map());
return Array.from(map.values());
};
/** Flatten paginated results into a single array. */
const flattenPages = <T>(queryData: InfiniteData<PaginatedResult<T>> | undefined) => {
return queryData?.pages.reduce<T[]>(
const data = queryData?.pages.reduce<T[]>(
// FIXME: Pleroma wants these to be reversed for Chats.
(prev: T[], curr) => [...curr.result, ...prev],
[],
);
if (data) {
return deduplicate<T>(data);
}
};
/** Traverse pages and update the item inside if found. */