-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #151 from jihwooon/issue-79
도서 목록 보기 기능 추가 및 쿼리스트링 설정
- Loading branch information
Showing
5 changed files
with
86 additions
and
13 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,63 @@ | ||
import { useEffect } from "react"; | ||
import { FaList, FaTh } from "react-icons/fa"; | ||
import { useSearchParams } from "react-router-dom"; | ||
import { styled } from "styled-components"; | ||
import Button from "../common/Button"; | ||
import { QUERYSTRING } from "../constants/querystring"; | ||
|
||
const viewOptions = [ | ||
{ | ||
value: 'list', | ||
icon: <FaList/> | ||
}, | ||
{ | ||
value: 'grid', | ||
icon: <FaTh/> | ||
} | ||
] | ||
|
||
export type ViewMode = 'grid' | 'list' | ||
|
||
const BooksViewSwitcher = () => { | ||
const [searchParams, setSearchParams] = useSearchParams() | ||
|
||
const handleSwitch = (value: ViewMode) => { | ||
const newSearchParams = new URLSearchParams(searchParams); | ||
|
||
newSearchParams.set(QUERYSTRING.VIEW, value) | ||
setSearchParams(newSearchParams); | ||
} | ||
|
||
useEffect(() => { | ||
if (!searchParams.get(QUERYSTRING.VIEW)) { | ||
handleSwitch('grid'); | ||
} | ||
}, []) | ||
|
||
return ( | ||
<div> | ||
<h1>BooksViewSwitcher</h1> | ||
</div> | ||
<BooksViewSwitcherStyle> | ||
{ | ||
viewOptions.map((option) => ( | ||
<Button | ||
key={option.value} | ||
size="medium" | ||
scheme={searchParams.get(QUERYSTRING.VIEW) === option.value ? "primary" : "normal"} | ||
onClick={() => handleSwitch(option.value as ViewMode)} | ||
> | ||
{option.icon} | ||
</Button> | ||
)) | ||
} | ||
</BooksViewSwitcherStyle> | ||
); | ||
}; | ||
|
||
const BooksViewSwitcherStyled = styled.div``; | ||
const BooksViewSwitcherStyle = styled.div` | ||
display: flex; | ||
gap: 8px; | ||
svg { | ||
fill: #fff; | ||
} | ||
`; | ||
|
||
export default BooksViewSwitcher; |
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,5 +1,6 @@ | ||
export const QUERYSTRING = { | ||
CATEGORY_ID: 'category_id', | ||
NEWS: 'news', | ||
PAGE: 'page' | ||
PAGE: 'page', | ||
VIEW: 'view' | ||
} |
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