Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature/#139/HeaderSearch] 헤더 검색 로직 구현 #143

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Changes from all commits
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
29 changes: 21 additions & 8 deletions src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { useRef } from "react"
import { IoSearch } from "react-icons/io5"
import { useNavigate } from "react-router-dom"

import {
Box,
Expand All @@ -17,12 +19,21 @@ import LoginButton from "./components/LoginButton"
import Menu from "./components/Menu/Menu"

const Header = () => {
const navigate = useNavigate()
const isLoggedIn = useUserInfoData()
const inputRef = useRef<HTMLInputElement>(null)

const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
if (inputRef.current) {
navigate(`/project?search=${inputRef.current.value}`)
inputRef.current.value = ""
}
}

return (
<HeaderContainer>
{/* 로고 */}
<LogoLink logoHeight="7rem" />
{/* 검색창 */}
<Box
pl="1.5rem"
alignSelf="end"
Expand All @@ -35,15 +46,17 @@ const Header = () => {
h="2rem"
/>
</InputRightElement>
<Input
size="lg"
variant="flushed"
placeholder="검색어를 입력하세요"
/>
<form onSubmit={handleSubmit}>
<Input
ref={inputRef}
size="lg"
variant="flushed"
placeholder="검색어를 입력하세요"
/>
</form>
</InputGroup>
</Box>
<Spacer />
{/* 메뉴 */}
{isLoggedIn ? <Menu /> : <LoginButton />}
</HeaderContainer>
)
Expand Down
Loading