-
Notifications
You must be signed in to change notification settings - Fork 2
[feat] 검색 페이지 UI 구현 #44
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8d0356d
feat: 홈페이지 라우트 추가 (#37)
maylh 70c88ae
feat: 인기 검색어 버튼 구현 (#37)
maylh cc09e72
feat: 카테고리 버튼 컴포넌트 구현 (#37)
maylh a3709ee
feat: 검색 페이지 구현 (#37)
maylh fecdb7e
feat: input 컴포넌트 onKeyDown props 추가 (#37)
maylh dcfc068
fix: 네비게이션 바 여러 경로 지원하도록 수정 (#37)
maylh 576cb60
fix: 검색 결과 컴포넌트 검색어 타입 반영 (#37)
maylh 23e6c87
feat: 검색 결과 페이지 구현 (#37)
maylh 79c45e7
fix: 인기 검색어 버튼 태그 변경 (#37)
maylh 3ac7e2c
fix: 검색 결과 클릭 시 해당 플레이리스트 페이지로 이동 (#37)
maylh dfb85da
fix: 검색 결과 클릭 → discover/:id 이동하도록 수정 (#37)
maylh 3793c10
fix: 빈 검색어 네비게이션 방지 (#37)
maylh 92e9921
fix: transient prop()로 수정 (#37)
maylh 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 hidden or 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 hidden or 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 hidden or 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,2 @@ | ||
| export { DotButton } from './DotButton' | ||
| export { default as LoopCarousel } from './LoopCarousel' |
This file contains hidden or 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,112 @@ | ||
| import { useEffect, useState } from 'react' | ||
| import { useLocation, useNavigate } from 'react-router-dom' | ||
|
|
||
| import styled from 'styled-components' | ||
|
|
||
| import { LeftArrow, Search } from '@/assets/icons' | ||
| import { SearchResultItem } from '@/pages/searchPage/ui' | ||
| import { useSingleSelect } from '@/shared/hooks/useSingleSelect' | ||
| import { ContentHeader, Header, Input, SvgButton } from '@/shared/ui' | ||
| import type { SortType } from '@/shared/ui/ContentHeader' | ||
|
|
||
| const SearchResultPage = () => { | ||
| const navigate = useNavigate() | ||
| const location = useLocation() | ||
|
|
||
| const queryParams = new URLSearchParams(location.search) | ||
| const keyword = queryParams.get('keyword') ?? '' | ||
|
|
||
| const [searchValue, setSearchValue] = useState(keyword) | ||
| const { selected, onSelect } = useSingleSelect<SortType>('popular') | ||
|
|
||
| useEffect(() => { | ||
| setSearchValue(keyword) | ||
| }, [keyword]) | ||
|
|
||
| const handleItemClick = (id: number) => { | ||
| navigate(`/discover/${id}`) | ||
| } | ||
| return ( | ||
| <> | ||
| <Header | ||
| left={<SvgButton icon={LeftArrow} onClick={() => navigate(-1)} />} | ||
| center={<span>검색</span>} | ||
| /> | ||
| <Input | ||
| type="search" | ||
| placeholder="플레이리스트명 또는 닉네임으로 검색" | ||
| value={searchValue} | ||
| onChange={(e) => setSearchValue(e.target.value)} | ||
| icon={Search} | ||
| iconPosition="left" | ||
| onKeyDown={(e) => { | ||
| if (e.key === 'Enter') { | ||
| navigate(`/searchResult?keyword=${encodeURIComponent(searchValue)}`) | ||
| } | ||
| }} | ||
| /> | ||
| <Result> | ||
| <ContentHeader | ||
| totalCount={searchResultMockData.length} | ||
| currentSort={selected} | ||
| onSortChange={onSelect} | ||
| /> | ||
| <ResultList> | ||
| {searchResultMockData.map((item) => ( | ||
| <SearchResultItem | ||
| key={item.id} | ||
| type={item.type as 'playlist' | 'user'} | ||
maylh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| searchResult={item.searchResult} | ||
| imageUrl={item.imageUrl} | ||
| userName={item.type === 'playlist' ? item.userName : null} | ||
| onClick={() => handleItemClick(item.id)} | ||
| /> | ||
| ))} | ||
maylh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </ResultList> | ||
| </Result> | ||
| </> | ||
| ) | ||
| } | ||
|
|
||
| export default SearchResultPage | ||
|
|
||
| const Result = styled.section` | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 16px; | ||
| padding-top: 24px; | ||
| ` | ||
|
|
||
| const ResultList = styled.div` | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 20px; | ||
| ` | ||
|
|
||
| export const searchResultMockData = [ | ||
| { | ||
| id: 1, | ||
| type: 'playlist', | ||
| searchResult: '도파민이 필요할 땐 이 노동요를 들어주세요 😎', | ||
| userName: 'deulak', | ||
| }, | ||
| { | ||
| id: 2, | ||
| type: 'playlist', | ||
| searchResult: '카페 재즈 모음', | ||
| userName: 'jazzlover', | ||
| }, | ||
| { | ||
| id: 3, | ||
| type: 'user', | ||
| imageUrl: 'image/url/expample.png', | ||
| searchResult: '김들락', | ||
| }, | ||
|
|
||
| { | ||
| id: 5, | ||
| type: 'playlist', | ||
| searchResult: '새벽감성 인디 플레이리스트', | ||
| userName: 'deulak', | ||
| }, | ||
| ] | ||
maylh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or 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,113 @@ | ||
| import { useState } from 'react' | ||
| import { useNavigate } from 'react-router-dom' | ||
|
|
||
| import styled, { css } from 'styled-components' | ||
|
|
||
| import { LeftArrow, Search } from '@/assets/icons' | ||
| import { TrendKeyword } from '@/pages/searchPage/ui' | ||
| import { CategoryButton, Header, Input, SvgButton } from '@/shared/ui' | ||
|
|
||
| const SearchPage = () => { | ||
| const [searchValue, setSearchValue] = useState('') | ||
| const navigate = useNavigate() | ||
|
|
||
| return ( | ||
| <> | ||
| <Header | ||
| left={<SvgButton icon={LeftArrow} onClick={() => navigate(-1)} />} | ||
| center={<span>검색</span>} | ||
| /> | ||
| <Input | ||
| type="search" | ||
| placeholder="플레이리스트명 또는 닉네임으로 검색" | ||
| value={searchValue} | ||
| onChange={(e) => setSearchValue(e.target.value)} | ||
| icon={Search} | ||
| iconPosition="left" | ||
| onKeyDown={(e) => { | ||
| if (e.key === 'Enter') { | ||
| navigate(`/searchResult?keyword=${encodeURIComponent(searchValue)}`) | ||
| } | ||
| }} | ||
maylh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /> | ||
| <TrendKeywordsSection> | ||
| <h1>인기 검색어</h1> | ||
| <Keywords> | ||
| {trendData.map((item) => ( | ||
| <TrendKeyword key={item.id} text={item.keyword} /> | ||
| ))} | ||
| </Keywords> | ||
| </TrendKeywordsSection> | ||
| <MoodSection> | ||
| <h1>장르와 테마</h1> | ||
| <Category> | ||
| {cateData.map((item) => ( | ||
| <CategoryButton key={item.id} text={item.text} size="small" /> | ||
| ))} | ||
| </Category> | ||
| </MoodSection> | ||
| </> | ||
| ) | ||
| } | ||
|
|
||
| export default SearchPage | ||
|
|
||
| const sectionCommonLayout = css` | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 16px; | ||
|
|
||
| & h1 { | ||
| ${({ theme }) => theme.FONT.headline1}; | ||
| font-weight: 600; | ||
| } | ||
| ` | ||
|
|
||
| const TrendKeywordsSection = styled.section` | ||
| ${sectionCommonLayout} | ||
| padding: 40px 0 32px 0; | ||
| ` | ||
| const Keywords = styled.div` | ||
| display: flex; | ||
| flex-wrap: wrap; | ||
| gap: 8px; | ||
| ` | ||
|
|
||
| const MoodSection = styled.section` | ||
| ${sectionCommonLayout} | ||
| padding: 24px 0 48px 0; | ||
| ` | ||
|
|
||
| const Category = styled.div` | ||
| display: grid; | ||
| grid-template-columns: repeat(2, 1fr); | ||
| gap: 12px; | ||
| ` | ||
|
|
||
| // TODO: api 연동 후 실 데이터로 수정 | ||
| const trendData = [ | ||
| { id: 1, keyword: '여름' }, | ||
| { id: 2, keyword: '바캉스 플리' }, | ||
| { id: 3, keyword: '카페 재즈 플레이리스트' }, | ||
| { id: 4, keyword: '청량' }, | ||
| { id: 5, keyword: '감성 힙합' }, | ||
| { id: 6, keyword: '쇠맛 여자아이돌 모음' }, | ||
| { id: 7, keyword: '드라이브' }, | ||
| { id: 8, keyword: '인디밴드음악' }, | ||
| { id: 9, keyword: 'K-POP' }, | ||
| ] | ||
|
|
||
| const cateData = [ | ||
| { id: 1, text: '발라드' }, | ||
| { id: 2, text: '힙합' }, | ||
| { id: 3, text: 'R&B' }, | ||
| { id: 4, text: '인디' }, | ||
| { id: 5, text: '락' }, | ||
| { id: 6, text: '댄스' }, | ||
| { id: 7, text: 'K-POP' }, | ||
| { id: 8, text: 'POP' }, | ||
| { id: 9, text: '재즈' }, | ||
| { id: 10, text: '클래식' }, | ||
| { id: 11, text: 'ASMR' }, | ||
| { id: 12, text: '기타' }, | ||
| ] | ||
maylh marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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 hidden or 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,25 @@ | ||
| import styled from 'styled-components' | ||
|
|
||
| interface TrendKeywordProps { | ||
| text: string | ||
| } | ||
|
|
||
| const TrendKeyword = ({ text }: TrendKeywordProps) => { | ||
| return <StyledButton>{text}</StyledButton> | ||
| } | ||
|
|
||
| export default TrendKeyword | ||
|
|
||
| const StyledButton = styled.button` | ||
| width: fit-content; | ||
| background-color: ${({ theme }) => theme.COLOR['gray-700']}; | ||
| color: ${({ theme }) => theme.COLOR['gray-50']}; | ||
| padding: 6px 12px; | ||
| border-radius: 99px; | ||
| ${({ theme }) => theme.FONT['body2-normal']}; | ||
|
|
||
| &:active { | ||
| background-color: ${({ theme }) => theme.COLOR['primary-normal']}; | ||
| color: ${({ theme }) => theme.COLOR['gray-900']}; | ||
| } | ||
| ` |
This file contains hidden or 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,2 @@ | ||
| export { default as SearchResultItem } from './SearchResultItem' | ||
| export { default as TrendKeyword } from './TrendKeyword' |
This file contains hidden or 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 hidden or 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,27 @@ | ||
| import styled, { css } from 'styled-components' | ||
|
|
||
| interface CategoryButtonProps { | ||
| text: string | ||
| size: 'small' | 'large' | ||
| } | ||
|
|
||
| const CategoryButton = ({ text, size }: CategoryButtonProps) => { | ||
| return <StyledButton size={size}>{text}</StyledButton> | ||
| } | ||
maylh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export default CategoryButton | ||
|
|
||
| const sizes = { | ||
| small: { width: '100%', height: '80px', borderRadius: '8px', padding: '10px' }, | ||
| large: { width: '160px', height: '200px', borderRadius: '10px', padding: '12px' }, | ||
| } | ||
|
|
||
| const StyledButton = styled.button<{ size: 'small' | 'large' }>` | ||
| display: flex; | ||
| align-items: flex-start; | ||
| justify-content: flex-start; | ||
| background-color: ${({ theme }) => theme.COLOR['gray-700']}; | ||
| color: ${({ theme }) => theme.COLOR['gray-10']}; | ||
|
|
||
| ${({ size }) => css(sizes[size])} | ||
| ` | ||
maylh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.