Skip to content

Commit

Permalink
Keep people and gear filters closed by default
Browse files Browse the repository at this point in the history
  • Loading branch information
fpagnoux authored Aug 30, 2022
2 parents ac56d93 + 7c8b54a commit e3bf55c
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/pages/Gear/AllGearPage/AllGearPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export function AllGearPage() {
const [showFilters, setShowFilters] = useState<boolean>(
!isEqual(filters, { retired: false }) // Open the panel if filters are not the default
);
const { gearTypes, broken, missing, retired, q: query } = filters;
const { gearTypes, broken, missing, retired, q } = filters;
const query = q ?? "";
const setQuery = (q: string) => setFilters((filters) => ({ ...filters, q }));

const { gearList, nbPages } = useGearList({
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Gear/AllGearPage/GearFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Select } from "components/Inputs/Select";
import { map } from "lodash";

export type Filters = {
q: string;
q?: string;
gearTypes?: number[];
broken?: boolean;
retired?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Gear/AllGearPage/useGearFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function parse(params: URLSearchParams): Filters {
const q = params.get("q") ?? "";

return {
q,
...(!isEmpty(q) && { q }),
retired,
...(broken != null && { broken }),
...(missing != null && { missing }),
Expand Down
2 changes: 1 addition & 1 deletion src/pages/People/PeoplePage/PeopleFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Checkbox } from "components/Inputs/Checkbox";
import { GroupSelect } from "components/GroupSelect";

export type Filters = {
q: string;
q?: string;
openRentals?: boolean;
groups?: number[];
};
Expand Down
3 changes: 2 additions & 1 deletion src/pages/People/PeoplePage/PeoplePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export function PeoplePage() {
const [page, setPage] = useState<number>(1);
const { filters, setFilters } = usePeopleFilters();
const [showFilters, setShowFilters] = useState<boolean>(!isEmpty(filters));
const { openRentals, groups, q: query } = filters;
const { openRentals, groups, q } = filters;
const query = q ?? "";
const { personList, nbPages } = usePeopleList({
q: query,
page,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/People/PeoplePage/usePeopleFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function parse(params: URLSearchParams): Filters {
const groups = params.get("groups");
const q = params.get("q") ?? "";
return {
q,
...(!isEmpty(q) && { q }),
...(openRentals === "true" && { openRentals: true }),
...(!isEmpty(groups) && { groups: groups!.split(",").map(Number) }),
};
Expand Down

0 comments on commit e3bf55c

Please sign in to comment.