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) => ({