From 72ab841934a205361ec6e4986d13aa27bc43dd7e Mon Sep 17 00:00:00 2001 From: rachel4w2 Date: Fri, 24 Nov 2023 03:09:34 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20=EA=B2=80=EC=83=89=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/recruitment/MultipleFilter.tsx | 25 +++++++++++++------ .../components/recruitment/ToggleButton.tsx | 22 ++++++---------- frontend/src/utils/atoms.ts | 4 +++ 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/frontend/src/components/recruitment/MultipleFilter.tsx b/frontend/src/components/recruitment/MultipleFilter.tsx index a45c784..b285358 100644 --- a/frontend/src/components/recruitment/MultipleFilter.tsx +++ b/frontend/src/components/recruitment/MultipleFilter.tsx @@ -1,6 +1,6 @@ 'use client' -import { useState } from 'react' +import { use, useEffect, useState } from 'react' import { useRecoilState } from 'recoil' import Select, { StylesConfig } from 'react-select' import Image from 'next/image' @@ -13,6 +13,7 @@ import { SkillType, FilterType, } from '../../utils/types' +import { set } from 'react-hook-form' const positionOptions = Object.values(Position).map((position) => ({ value: position, @@ -57,11 +58,13 @@ export default function MultipleFilter() { const handleKeywordSubmit = (e: React.FormEvent) => { e.preventDefault() - setFilter((prevFilter) => [ - ...prevFilter, - { category: 'keyword', name: keyword }, - ]) - setKeyword('') + setFilter((prevFilter) => + prevFilter.map((item) => + item.category === 'keyword' ? { ...item, name: keyword } : item, + ), + ) + sessionStorage.setItem('keyword', keyword) + console.log({ filter }) } const removeFilterItem = (itemToRemove: FilterType) => { @@ -70,6 +73,11 @@ export default function MultipleFilter() { ) } + useEffect(() => { + const searchText = sessionStorage.getItem('keyword') + setKeyword(searchText) + }, []) + return (
@@ -141,7 +149,10 @@ export default function MultipleFilter() {
{filter - .filter((item) => item.category !== 'isRecruiting') // isRecruiting이 아닌 아이템들만 필터링 + .filter( + (item) => + item.category !== 'isRecruiting' && item.category !== 'keyword', + ) .map((item) => (
f.category === 'isRecruiting')?.name === 'true', - ) + const [recruiting, setRecruiting] = useState(false) const handleToggle = () => { - const newIsRecruitingValue = String(!isChecked) - + const recuitingFilter = filter.find((f) => f.category === 'isRecruiting') const updatedFilter = filter.map((f) => - f.category === 'isRecruiting' ? { ...f, name: newIsRecruitingValue } : f, + f === recuitingFilter ? { ...f, name: String(!recruiting) } : f, ) - setFilter(updatedFilter) - setIsChecked(!isChecked) + setRecruiting(!recruiting) } useEffect(() => { - const recruitingFilter = filter.find((f) => f.category === 'isRecruiting') - if (recruitingFilter) { - setIsChecked(recruitingFilter.name === 'true') + if (filter.find((f) => f.category === 'isRecruiting')?.name === 'true') { + handleToggle() } - }, [filter]) + }, []) return ( ) diff --git a/frontend/src/utils/atoms.ts b/frontend/src/utils/atoms.ts index 65e47df..758b886 100644 --- a/frontend/src/utils/atoms.ts +++ b/frontend/src/utils/atoms.ts @@ -103,6 +103,10 @@ const usernameState = atom({ const filterState = atom({ key: 'FilterState', default: [ + { + category: 'keyword', + name: '', + }, { category: 'isRecruiting', name: 'false',