Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/components/Alert/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ function Alert({ userId }: AlertProps) {
) : (
<InactiveAlarmIcon className="h-6" />
)}
{/* <AlarmIcon className="h-6" /> */}
</button>
{showDropdown && (
<div
Expand Down
27 changes: 15 additions & 12 deletions src/components/Dropdown/FilterDropdownContent.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ChangeEvent, useMemo, useState } from "react";

import DatePicker from "react-datepicker";
import { useLocation, useSearchParams } from "react-router-dom";

import TextField from "../TextField";

Expand All @@ -23,15 +24,10 @@ function FilterDropdownContent({
onClose,
onClickApplyButton,
}: FilterDropdownContentProps) {
const {
selectedAreas,
startDate,
minPay,
setAreas,
setStartDate,
setMinPay,
reset,
} = useFilterStore();
const { pathname } = useLocation();
const { selectedAreas, startDate, minPay, setFilters, reset } =
useFilterStore();
const [, setSearchParams] = useSearchParams();
const [payFilter, setPayFilter] = useState(minPay);
const [startDateFilter, setStartDateFilter] = useState(startDate);
const [areasFilter, setAreasFilter] = useState<string[]>(selectedAreas);
Expand Down Expand Up @@ -66,9 +62,12 @@ function FilterDropdownContent({
};

const applyButtonHandler = () => {
setMinPay(payFilter);
setStartDate(startDateFilter);
setAreas(areasFilter);
setFilters({
selectedAreas: areasFilter,
startDate: startDateFilter,
minPay: payFilter,
pathname,
});
onClickApplyButton();
};

Expand All @@ -78,6 +77,10 @@ function FilterDropdownContent({
setStartDateFilter(null);
setAreasFilter([]);
refetch();
setSearchParams((prev) => {
prev.set("page", "1");
return prev;
});
};

return (
Expand Down
21 changes: 18 additions & 3 deletions src/components/NoticeSearchResultHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMemo, useRef, useState } from "react";
import { useEffect, useMemo, useRef, useState } from "react";

import { useSearchParams } from "react-router-dom";
import { useLocation, useSearchParams } from "react-router-dom";

import Button from "@/components/Button";
import FilterDropdownContent from "@/components/Dropdown/FilterDropdownContent";
Expand All @@ -26,9 +26,17 @@ export default function NoticeSearchResultHeader({
onChangeSort,
refetch,
}: TotalNoticeSectionProps) {
const { pathname } = useLocation();

const [, setSearchParams] = useSearchParams();
const [showFilter, setShowFilter] = useState<boolean>(false);
const { minPay, selectedAreas, startDate } = useFilterStore();
const {
pathname: filterPathname,
minPay,
selectedAreas,
startDate,
reset,
} = useFilterStore();

const buttonRef = useRef<HTMLButtonElement>(null);
const wrapperRef = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -68,6 +76,13 @@ export default function NoticeSearchResultHeader({
setShowFilter(false);
};

useEffect(() => {
console.log(pathname, filterPathname);
if (pathname !== filterPathname) {
reset();
}
}, [pathname, filterPathname, reset]);

return (
<div>
<div className="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4 sm:gap-0 mb-4 ">
Expand Down
16 changes: 16 additions & 0 deletions src/store/useFilterStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ interface FilterState {
selectedAreas: string[];
startDate: Date | null;
minPay: string | null;
pathname: string | null;
getFilters: () => {
address?: string[] | null;
hourlyPayGte?: number;
startsAtGte?: string;
pathname?: string;
};
setFilters: (filters: {
selectedAreas?: string[];
startDate?: Date | null;
minPay?: string | null;
pathname?: string;
}) => void;
setAreas: (areas: string[]) => void;
setStartDate: (date: Date | null) => void;
setMinPay: (pay: string | null) => void;
Expand All @@ -22,6 +30,7 @@ export const useFilterStore = create<FilterState>((set, get) => ({
selectedAreas: [],
startDate: null,
minPay: null,
pathname: null,

getFilters: () => {
const { selectedAreas, startDate, minPay } = get();
Expand All @@ -43,11 +52,18 @@ export const useFilterStore = create<FilterState>((set, get) => ({
setAreas: (areas) => set({ selectedAreas: areas }),
setStartDate: (date) => set({ startDate: date }),
setMinPay: (pay) => set({ minPay: pay }),
setFilters: (nextFilters) => {
set((filters) => ({
...filters,
...nextFilters,
}));
},

reset: () =>
set({
selectedAreas: [],
startDate: null,
minPay: null,
pathname: null,
}),
}));