Skip to content

Commit

Permalink
Final sort fix
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmwatson committed Oct 15, 2024
1 parent 233b694 commit 030d5d8
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/components/attendance/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,16 +461,18 @@ function Attendance() {
}, [data, selectedParliament, grouping]);

useEffect(() => {
filterAttendanceData(dataAttendance);
filterAndSortAttendanceData(dataAttendance);
}, [
dataAttendance,
filteredByParties,
filteredByCommittees,
filteredByHouses,
memberSearch,
sortedField,
sortedDirection,
]);

const filterAttendanceData = (data) => {
const filterAndSortAttendanceData = (data) => {
data = data
.filter((row) => {
if (grouping === "members") {
Expand Down Expand Up @@ -498,10 +500,7 @@ function Attendance() {
filteredByHouses.some((house) => row.houses.includes(house))
);
});
setFilteredAttendance(data);
};

const sortAttendanceData = (data) => {
if (sortedDirection === "asc") {
data = data.sort((a, b) => {
if (sortedField === "label" || sortedField === "party") {
Expand All @@ -527,10 +526,6 @@ function Attendance() {
setSortedDirection(sortedDirection === "desc" ? "asc" : "desc");
};

useEffect(() => {
sortAttendanceData(dataAttendance);
}, [sortedField, sortedDirection]);

return (
<Fragment>
<PMHeader />
Expand Down

0 comments on commit 030d5d8

Please sign in to comment.