Skip to content

Commit

Permalink
feat : 검색 기능 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Yujin-Baek committed Nov 23, 2023
1 parent decfa96 commit 72ab841
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
25 changes: 18 additions & 7 deletions frontend/src/components/recruitment/MultipleFilter.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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,
Expand Down Expand Up @@ -57,11 +58,13 @@ export default function MultipleFilter() {

const handleKeywordSubmit = (e: React.FormEvent<HTMLFormElement>) => {
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) => {
Expand All @@ -70,6 +73,11 @@ export default function MultipleFilter() {
)
}

useEffect(() => {
const searchText = sessionStorage.getItem('keyword')
setKeyword(searchText)
}, [])

return (
<div className="w-[900px] h-[80px] mb-8 flex flex-col border-solid border-gray-400 text-lightgray">
<div className="w-full flex h-1/2 text-sm">
Expand Down Expand Up @@ -141,7 +149,10 @@ export default function MultipleFilter() {
</div>
<div className="w-full h-1/2 flex items-center bg-slate-100">
{filter
.filter((item) => item.category !== 'isRecruiting') // isRecruiting이 아닌 아이템들만 필터링
.filter(
(item) =>
item.category !== 'isRecruiting' && item.category !== 'keyword',
)
.map((item) => (
<div
key={item.name}
Expand Down
22 changes: 8 additions & 14 deletions frontend/src/components/recruitment/ToggleButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,26 @@ import '../../../public/css/toggle-button.css'

export default function ToggleButton() {
const [filter, setFilter] = useRecoilState(filterState)

const [isChecked, setIsChecked] = useState(
filter.find((f) => 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 (
<label className="switch">
<input type="checkbox" checked={isChecked} onChange={handleToggle} />
<input type="checkbox" checked={recruiting} onChange={handleToggle} />
<span className="slider round"> </span>
</label>
)
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/utils/atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ const usernameState = atom<string>({
const filterState = atom<FilterType[]>({
key: 'FilterState',
default: [
{
category: 'keyword',
name: '',
},
{
category: 'isRecruiting',
name: 'false',
Expand Down

0 comments on commit 72ab841

Please sign in to comment.