Skip to content

Commit

Permalink
fix: timeslot filter item doesn't update. Fixes #427
Browse files Browse the repository at this point in the history
  • Loading branch information
ImJustChew committed Aug 19, 2024
1 parent 3a9e680 commit c263ec0
Showing 1 changed file with 7 additions and 23 deletions.
30 changes: 7 additions & 23 deletions src/app/[lang]/(mods-pages)/courses/TimeslotFilterItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ const TimeslotFilterItem = ({

const [searchValue, setSearchValue] = useState("");
const [searching, setSearching] = useState(false);
const [selected, setSelected] = useState<string[]>([]);

const items = mode == "exact" ? timesItems : separateItems;
const refine = mode == "exact" ? timesRefine : separateRefine;
Expand All @@ -77,15 +76,13 @@ const TimeslotFilterItem = ({
};

useEffect(() => {
if (timeslotValue.length > 0) {
clearRefine();
if (mode == "includes") {
for (let i = 0; i < timeslotValue.length; i++) {
refine(timeslotValue[i]);
}
} else {
refine([...timeslotValue].sort(customSort).join(""));
clearRefine();
if (mode == "includes") {
for (let i = 0; i < timeslotValue.length; i++) {
refine(timeslotValue[i]);
}
} else {
refine([...timeslotValue].sort(customSort).join(""));
}
}, [mode, timeslotValue, clearRefine, refine]);

Expand All @@ -96,7 +93,6 @@ const TimeslotFilterItem = ({
}
if (name == "") {
const refinedItems = items.filter((item) => item.isRefined);
setSelected(refinedItems.map((item) => item.value));
}
};

Expand All @@ -116,21 +112,9 @@ const TimeslotFilterItem = ({

const clear = () => {
setTimeslotValue([]);
setSelected([]);
clearRefine();
};

useEffect(() => {
clearRefine();
if (mode == "includes") {
for (let i = 0; i < timeslotValue.length; i++) {
refine(timeslotValue[i]);
}
} else {
refine([...timeslotValue].sort(customSort).join(""));
}
}, [timeslotValue, mode, refine, clearRefine]);

const handleFillTimes = useCallback(() => {
const timeslots = getSemesterCourses(semester)
.map((course) =>
Expand Down Expand Up @@ -164,7 +148,7 @@ const TimeslotFilterItem = ({
<span className="truncate">
{searching ? (
"Selecting..."
) : selected.length == 0 ? (
) : timeslotValue.length == 0 ? (
"All"
) : (
<div className="flex flex-col gap-1">
Expand Down

0 comments on commit c263ec0

Please sign in to comment.