Skip to content
This repository has been archived by the owner on Dec 15, 2024. It is now read-only.

Commit

Permalink
reset discipline and location filters query on popover close
Browse files Browse the repository at this point in the history
  • Loading branch information
evermake committed Nov 23, 2024
1 parent 581c819 commit ca379fb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions frontend/src/components/filters/DisciplineFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export function DisciplineFilter(
setQ("");
}, [pendingSport]);

useEffect(() => {
if (!open) setQ("");
}, [open]);

const pendingDisciplines = pendingSport
? disciplinesBySport.get(pendingSport)
: null;
Expand Down Expand Up @@ -118,6 +122,7 @@ export function DisciplineFilter(
setPendingSport(null);
return;
}

setOpen(newOpen);
};

Expand Down
12 changes: 10 additions & 2 deletions frontend/src/components/filters/LocationFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { FilterBaseProps } from "./common";
import { $api } from "@/api";
import { BaseFilter } from "./BaseFilter";
import { Filters } from "@/lib/types";
import { useMemo, useState } from "react";
import { useEffect, useMemo, useState } from "react";
import { Badge } from "../ui/badge";
import { useDebounce } from "react-use";
import { cn } from "@/lib/utils";
Expand Down Expand Up @@ -106,6 +106,7 @@ export function LocationFilter(props: FilterBaseProps<Filters["location"]>) {
return flat;
}, [data]);

const [open, setOpen] = useState(false)
const [q, setQ] = useState("");
const [qDeb, setQDeb] = useState("");
useDebounce(
Expand All @@ -116,6 +117,13 @@ export function LocationFilter(props: FilterBaseProps<Filters["location"]>) {
[q, setQDeb],
);

useEffect(() => {
if (!open) {
setQ('')
setQDeb('')
}
}, [open])

const filtered = useMemo(
() =>
all
Expand All @@ -138,7 +146,7 @@ export function LocationFilter(props: FilterBaseProps<Filters["location"]>) {

return (
<BaseFilter {...rest}>
<Popover>
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
<Button
disabled={disabled}
Expand Down

0 comments on commit ca379fb

Please sign in to comment.