From 5de1c3a61d7909fd7bd4f3bb2de8df4a5750d56d Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 13 Dec 2022 15:17:58 -0600 Subject: [PATCH] Revert flattenPages order changes --- app/soapbox/utils/chats.ts | 2 +- app/soapbox/utils/queries.ts | 23 ++++------------------- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/app/soapbox/utils/chats.ts b/app/soapbox/utils/chats.ts index b7f0eb4ec..71a416562 100644 --- a/app/soapbox/utils/chats.ts +++ b/app/soapbox/utils/chats.ts @@ -30,7 +30,7 @@ const reOrderChatListItems = () => { chatA.last_message?.created_at as string, chatB.last_message?.created_at as string, ); - }, 'default'); + }); }; /** diff --git a/app/soapbox/utils/queries.ts b/app/soapbox/utils/queries.ts index e9d44210c..263d2407b 100644 --- a/app/soapbox/utils/queries.ts +++ b/app/soapbox/utils/queries.ts @@ -25,21 +25,10 @@ const deduplicateById = (entities: T[]): T[] => { return Array.from(map.values()); }; -export type SortOrder = 'reverse' | 'default' - /** Flatten paginated results into a single array. */ -const flattenPages = ( - queryData: InfiniteData> | undefined, - order: SortOrder = 'reverse', -) => { +const flattenPages = (queryData: InfiniteData> | undefined) => { const data = queryData?.pages.reduce( - (prev: T[], curr) => { - if (order === 'reverse') { - return [...curr.result, ...prev]; - } else { - return [...prev, ...curr.result]; - } - }, + (prev: T[], curr) => [...prev, ...curr.result], [], ); @@ -101,15 +90,11 @@ const paginateQueryData = (array: T[] | undefined) => { }, []); }; -const sortQueryData = ( - queryKey: QueryKey, - comparator: (a: T, b: T) => number, - order: SortOrder = 'reverse', -) => { +const sortQueryData = (queryKey: QueryKey, comparator: (a: T, b: T) => number) => { queryClient.setQueryData>>(queryKey, (prevResult) => { if (prevResult) { const nextResult = { ...prevResult }; - const flattenedQueryData = flattenPages(nextResult, order); + const flattenedQueryData = flattenPages(nextResult); const sortedQueryData = flattenedQueryData?.sort(comparator); const paginatedPages = paginateQueryData(sortedQueryData); const newPages = paginatedPages.map((page: T, idx: number) => ({