Skip to content

Commit

Permalink
fixup! Add type for versioned group
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlin committed Nov 14, 2024
1 parent 26725ee commit 625203e
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions static-site/src/components/ListResources/useSortAndFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends Group>(
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)
Expand All @@ -45,23 +61,7 @@ export const useSortAndFilter = (
const resourceGroups = sortAndFilter(groups, _sortGroups, _sortResources)
setState(resourceGroups)
}
}, [sortMethod, originalData, setState, sortAndFilter])

function sortAndFilter<T extends Group>(
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])

Check warning on line 64 in static-site/src/components/ListResources/useSortAndFilter.ts

View workflow job for this annotation

GitHub Actions / lint

React Hook useMemo has a missing dependency: '_filterResources'. Either include it or remove the dependency array
}


Expand Down

0 comments on commit 625203e

Please sign in to comment.