From 625203e9846746bb72472629ed410dc2b81b7bfa Mon Sep 17 00:00:00 2001 From: Victor Lin <13424970+victorlin@users.noreply.github.com> Date: Wed, 13 Nov 2024 17:14:49 -0800 Subject: [PATCH] fixup! Add type for versioned group --- .../ListResources/useSortAndFilter.ts | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/static-site/src/components/ListResources/useSortAndFilter.ts b/static-site/src/components/ListResources/useSortAndFilter.ts index 67c7bdaa1..b58ad6185 100644 --- a/static-site/src/components/ListResources/useSortAndFilter.ts +++ b/static-site/src/components/ListResources/useSortAndFilter.ts @@ -23,6 +23,22 @@ export const useSortAndFilter = ( /* Following console log is really useful for development */ // console.log(`useSortAndFilter() sortMethod "${sortMethod}" ` + (selectedFilterOptions.length ? `filtering to ${selectedFilterOptions.map((el) => el.value).join(", ")}` : '(no filtering)')) + function sortAndFilter( + groups: T[], + sortGroups: (a: T, b: T) => number, + sortResources: (a: Resource, b: Resource) => number, + ): T[] { + return groups + .map((group) => ({ + ...group, + resources: group.resources + .filter(_filterResources) + .sort(sortResources) + })) + .filter((group) => !!group.resources.length) + .sort(sortGroups); + } + if (sortMethod === "lastUpdated") { const groups = originalData.map((group: Group) => convertVersionedGroup(group)) const _sortGroups = (groupA: VersionedGroup, groupB: VersionedGroup) => _newestFirstSort(groupA.lastUpdated, groupB.lastUpdated) @@ -45,23 +61,7 @@ export const useSortAndFilter = ( const resourceGroups = sortAndFilter(groups, _sortGroups, _sortResources) setState(resourceGroups) } - }, [sortMethod, originalData, setState, sortAndFilter]) - - function sortAndFilter( - groups: T[], - sortGroups: (a: T, b: T) => number, - sortResources: (a: Resource, b: Resource) => number, - ): T[] { - return groups - .map((group) => ({ - ...group, - resources: group.resources - .filter(_filterResources) - .sort(sortResources) - })) - .filter((group) => !!group.resources.length) - .sort(sortGroups); - } + }, [sortMethod, originalData, setState]) }