-
Notifications
You must be signed in to change notification settings - Fork 8
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
[FE] 검색 기능 구현(#730) #741
Merged
[FE] 검색 기능 구현(#730) #741
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
51ee863
feat: 검색 아이콘 추가
pp449 f8222a8
feat: SearchBar 컴포넌트 생성
pp449 61e262a
feat: 방 검색관련 데이터패칭 로직 추가
pp449 b3c4146
feat: 방 리스트 페이지에 검색창 추가
pp449 e586ea0
fix: 서버통신과 타입이 맞지 않는 문제 해결
pp449 7ba27f8
feat: 검색한 방이 없는경우 토스트가 보이도록 변경
pp449 eea33b4
refactor: Input을 기존에 있던 공통 컴포넌트로 변경
pp449 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
frontend/src/components/common/searchBar/SearchBar.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import SearchBar from "./SearchBar"; | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
|
||
const meta = { | ||
title: "Common/SearchBar", | ||
component: SearchBar, | ||
argTypes: { | ||
placeholder: { | ||
control: { | ||
type: "text", | ||
}, | ||
description: "placeholder", | ||
defaultValue: "방 제목을 검색해주세요", | ||
}, | ||
defaultValue: { | ||
control: { | ||
type: "text", | ||
}, | ||
description: "textarea의 value", | ||
}, | ||
}, | ||
} satisfies Meta<typeof SearchBar>; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
value: "기본 입력창", | ||
handleValue: () => {}, | ||
handleSearch: () => {}, | ||
}, | ||
}; |
28 changes: 28 additions & 0 deletions
28
frontend/src/components/common/searchBar/SearchBar.style.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import styled from "styled-components"; | ||
|
||
export const SearchBarContainer = styled.div` | ||
position: relative; | ||
width: 100%; | ||
height: 100%; | ||
height: 40px; | ||
`; | ||
|
||
export const SearchBar = styled.input` | ||
width: 100%; | ||
height: 100%; | ||
padding: 0.6rem 3rem 0.6rem 0.6rem; | ||
|
||
font: ${({ theme }) => theme.TEXT.small}; | ||
|
||
border: 1px solid ${({ theme }) => theme.COLOR.grey1}; | ||
border-radius: 6px; | ||
`; | ||
|
||
export const SearchIconWrapper = styled.div` | ||
cursor: pointer; | ||
|
||
position: absolute; | ||
top: 50%; | ||
right: 3px; | ||
transform: translate(-50%, -50%); | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as S from "./SearchBar.style"; | ||
import { InputHTMLAttributes } from "react"; | ||
import Icon from "@/components/common/icon/Icon"; | ||
|
||
interface SearchBarProps extends InputHTMLAttributes<HTMLInputElement> { | ||
value: string; | ||
handleValue: (e: React.ChangeEvent<HTMLInputElement>) => void; | ||
handleSearch: () => void; | ||
} | ||
|
||
const SearchBar = ({ value, handleValue, handleSearch, ...props }: SearchBarProps) => { | ||
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => { | ||
if (e.key === "Enter") { | ||
handleSearch(); | ||
} | ||
}; | ||
|
||
return ( | ||
<S.SearchBarContainer> | ||
<S.SearchBar value={value} onChange={handleValue} onKeyDown={handleKeyDown} {...props} /> | ||
<S.SearchIconWrapper onClick={handleSearch}> | ||
<Icon kind="search" /> | ||
</S.SearchIconWrapper> | ||
</S.SearchBarContainer> | ||
); | ||
}; | ||
|
||
export default SearchBar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
import styled from "styled-components"; | ||
|
||
export const DropdownWrapper = styled.div` | ||
export const SearchBarWrapper = styled.div` | ||
width: 180px; | ||
`; | ||
|
||
export const FilterWrapper = styled.div` | ||
display: flex; | ||
justify-content: flex-end; | ||
justify-content: space-between; | ||
margin-bottom: 1rem; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import { ChangeEvent, useEffect, useState } from "react"; | ||
import useToast from "@/hooks/common/useToast"; | ||
import { useFetchSearchRoomList } from "@/hooks/queries/useFetchRooms"; | ||
import ContentSection from "@/components/common/contentSection/ContentSection"; | ||
import Dropdown from "@/components/common/dropdown/Dropdown"; | ||
import SearchBar from "@/components/common/searchBar/SearchBar"; | ||
import * as S from "@/components/main/room/RoomList.style"; | ||
import RoomList from "@/components/shared/roomList/RoomList"; | ||
import { RoomInfo } from "@/@types/roomInfo"; | ||
import { Classification, RoomInfo, RoomStatusCategory } from "@/@types/roomInfo"; | ||
import { dropdownItems } from "@/constants/roomDropdownItems"; | ||
|
||
interface RoomListWithDropdownProps { | ||
|
@@ -12,7 +16,7 @@ interface RoomListWithDropdownProps { | |
hasNextPage: boolean; | ||
onLoadMore: () => void; | ||
isFetchingNextPage: boolean; | ||
roomType: "participated" | "progress" | "opened" | "closed"; | ||
roomType: RoomStatusCategory; | ||
} | ||
|
||
const RoomListWithDropdown = ({ | ||
|
@@ -24,23 +28,65 @@ const RoomListWithDropdown = ({ | |
isFetchingNextPage, | ||
roomType, | ||
}: RoomListWithDropdownProps) => { | ||
const [searchInput, setSearchInput] = useState(""); | ||
const [searchedRooms, setSearchedRooms] = useState<RoomInfo[]>([]); | ||
const { openToast } = useToast(); | ||
|
||
const { refetch: fetchSearch, isLoading } = useFetchSearchRoomList( | ||
roomType, | ||
selectedCategory as Classification, | ||
searchInput, | ||
false, | ||
); | ||
|
||
const handleSearchInput = (e: ChangeEvent<HTMLInputElement>) => { | ||
setSearchInput(e.target.value); | ||
}; | ||
|
||
const handleSearch = async () => { | ||
const { data } = await fetchSearch(); | ||
if (!data || data.rooms.length === 0) { | ||
openToast("검색한 방이 없습니다."); | ||
return; | ||
} | ||
|
||
setSearchedRooms(data.rooms); | ||
}; | ||
|
||
useEffect(() => { | ||
setSearchInput(""); | ||
setSearchedRooms([]); | ||
}, [selectedCategory, roomType]); | ||
|
||
return ( | ||
<ContentSection title=""> | ||
<S.DropdownWrapper> | ||
<S.FilterWrapper> | ||
<Dropdown | ||
name="포지션 분류" | ||
dropdownItems={dropdownItems} | ||
selectedCategory={selectedCategory} | ||
onSelectCategory={handleSelectedCategory} | ||
/> | ||
</S.DropdownWrapper> | ||
<RoomList | ||
roomList={roomList} | ||
hasNextPage={hasNextPage} | ||
onLoadMore={onLoadMore} | ||
isFetchingNextPage={isFetchingNextPage} | ||
roomType={roomType} | ||
/> | ||
<S.SearchBarWrapper> | ||
<SearchBar | ||
value={searchInput} | ||
handleValue={handleSearchInput} | ||
handleSearch={handleSearch} | ||
placeholder="제목을 입력해주세요" | ||
/> | ||
</S.SearchBarWrapper> | ||
</S.FilterWrapper> | ||
{searchedRooms.length === 0 ? ( | ||
<RoomList | ||
roomList={roomList} | ||
hasNextPage={hasNextPage} | ||
onLoadMore={onLoadMore} | ||
isFetchingNextPage={isFetchingNextPage} | ||
roomType={roomType} | ||
/> | ||
) : ( | ||
<RoomList roomList={searchedRooms} isFetchingNextPage={isLoading} roomType={roomType} /> | ||
)} | ||
Comment on lines
+79
to
+89
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 검색 결과가 없을 때도 처리를 해주었네요! 저도 원래 데이터를 그대로 보여주는 게 좋다고 생각합니다👍 |
||
</ContentSection> | ||
); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분이 padding과 height 말고는 Input 컴포넌트와 굉장히 유사하더라고요! 사실 height는 없어도 되는 속성이라
padding-right: 3rem
만 추가면 Input 컴포넌트를 그대로 써도 괜찮을 것 같다고 생각합니다!outline-color: ${({ theme }) => theme.COLOR.black};
를 추가하면 focus 시 outline이 검정색으로 나온답니다😁