-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Minor : 스타일링 체인지 * Minor : 사용하지 않는 모듈제거, 포매팅 * Refactor : 술 리스트 컴포넌트, 페이지네이션 분리 * Refactor : 술 리스트 컴포넌트, 페이지네이션 분리 * Refactor : 키워드가 입력되지 않았을 경우 처리 * New : 로컬스토리지 키를 상수로 관리 * New : UX개선을 위한 스켈레톤 표시 딜레이 타이머 추가 * New : 술 검색기능 구현
- Loading branch information
1 parent
8de995b
commit 7ea46c0
Showing
16 changed files
with
347 additions
and
72 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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Button, Stack, StackProps, Typography } from "@mui/material"; | ||
import { useCallback, useState } from "react"; | ||
import XIcon from "@/assets/icons/XIcon.svg"; | ||
|
||
interface SearchHistoryProps extends Omit<StackProps, "onClick"> { | ||
storageKey: string; | ||
onClick: () => void; | ||
} | ||
|
||
const SearchHistory = ({ storageKey, onClick }: SearchHistoryProps) => { | ||
const getItems = useCallback(() => { | ||
return JSON.parse(localStorage.getItem(storageKey) ?? "[]") as string[]; | ||
}, [storageKey]); | ||
|
||
const [searchHistory, setSearchHistory] = useState<string[]>(getItems()); | ||
|
||
const removeAll = useCallback(() => { | ||
localStorage.setItem(storageKey, "[]"); | ||
setSearchHistory(getItems()); | ||
}, [storageKey]); | ||
|
||
const removeByKeyword = useCallback( | ||
(keyword: string) => { | ||
const filteredHistory = searchHistory.filter( | ||
(prevKeyword) => prevKeyword !== keyword | ||
); | ||
localStorage.setItem(storageKey, JSON.stringify(filteredHistory)); | ||
setSearchHistory(getItems()); | ||
}, | ||
[storageKey] | ||
); | ||
|
||
return searchHistory.length > 0 ? ( | ||
<> | ||
<Stack direction="row" justifyContent="space-between"> | ||
<Typography variant="subtitle1" fontWeight="bold"> | ||
최근 검색어 | ||
</Typography> | ||
<Button onClick={removeAll} variant="text" sx={{ fontWeight: "bold" }}> | ||
전체 삭제 | ||
</Button> | ||
</Stack> | ||
<Stack> | ||
{searchHistory.map((keyword) => ( | ||
<Stack | ||
key={keyword} | ||
onClick={onClick} | ||
direction="row" | ||
justifyContent="space-between" | ||
alignItems="center" | ||
> | ||
<Typography variant="subtitle2">{keyword}</Typography> | ||
<Button | ||
onClick={(e) => { | ||
e.stopPropagation(); | ||
removeByKeyword(keyword); | ||
}} | ||
variant="text" | ||
sx={{ justifyContent: "end" }} | ||
> | ||
<XIcon /> | ||
</Button> | ||
</Stack> | ||
))} | ||
</Stack> | ||
</> | ||
) : ( | ||
<></> | ||
); | ||
}; | ||
|
||
export default SearchHistory; |
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,40 +1,29 @@ | ||
"use client"; | ||
import AlcoholNameTag from "@/components/wiki/AlcoholNameTag"; | ||
import useGetAlcoholListQuery from "@/queries/alcohol/useGetAlcoholListQuery"; | ||
import { Box, Pagination, Skeleton, Stack } from "@mui/material"; | ||
import { AlcoholDetailInterface } from "@/types/alcohol/AlcoholInterface"; | ||
import { Typography } from "@mui/material"; | ||
import { memo } from "react"; | ||
|
||
const AlcoholList = () => { | ||
const { data: alcohols } = useGetAlcoholListQuery(); | ||
const AlcoholList = ({ | ||
data: alcohols, | ||
}: { | ||
data: AlcoholDetailInterface[]; | ||
}) => { | ||
return ( | ||
<Stack alignItems="center" gap={2}> | ||
<Stack gap={1} alignItems="center" width={"100%"} height={"232px"}> | ||
{alcohols ? ( | ||
alcohols.list.map((alcohol) => ( | ||
<AlcoholNameTag | ||
key={alcohol.alcoholNo} | ||
alcoholName={alcohol.alcoholName} | ||
alcoholType={alcohol.alcoholType} | ||
/> | ||
)) | ||
) : ( | ||
<AlcoholListSkeleton /> | ||
)} | ||
</Stack> | ||
<Pagination count={alcohols?.totalCount} /> | ||
</Stack> | ||
<> | ||
{alcohols?.length > 0 ? ( | ||
alcohols.map((alcohol) => ( | ||
<AlcoholNameTag | ||
key={alcohol.alcoholNo} | ||
alcoholName={alcohol.alcoholName} | ||
alcoholType={alcohol.alcoholType} | ||
/> | ||
)) | ||
) : ( | ||
<Typography textAlign="center">검색 결과가 없어요</Typography> | ||
)} | ||
</> | ||
); | ||
}; | ||
export default memo(AlcoholList); | ||
|
||
const AlcoholListSkeleton = memo(() => { | ||
return Array.from(new Array(5)).map(() => ( | ||
<Skeleton | ||
variant="rectangular" | ||
width={"100%"} | ||
height={40} | ||
sx={{ borderRadius: 2 }} | ||
/> | ||
)); | ||
}); | ||
|
||
export default AlcoholList; |
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,31 @@ | ||
import { memo } from "react"; | ||
import { Skeleton } from "@mui/material"; | ||
|
||
import useSkeletonTimer from "@/hooks/useSkeletonTimer"; | ||
|
||
interface AlcoholListSkeletonInterface { | ||
size?: number; | ||
disableTimer?: boolean; | ||
} | ||
|
||
const AlcoholListSkeleton = memo( | ||
({ size = 5, disableTimer }: AlcoholListSkeletonInterface) => { | ||
const isOver200ms = !!disableTimer ? true : useSkeletonTimer(); | ||
|
||
return isOver200ms ? ( | ||
Array.from(new Array(size)).map((_e, i) => ( | ||
<Skeleton | ||
key={i} | ||
variant="rectangular" | ||
width={"100%"} | ||
height={40} | ||
sx={{ borderRadius: 2 }} | ||
/> | ||
)) | ||
) : ( | ||
<></> | ||
); | ||
} | ||
); | ||
|
||
export default AlcoholListSkeleton; |
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,24 @@ | ||
"use client"; | ||
import useGetAlcoholListQuery from "@/queries/alcohol/useGetAlcoholListQuery"; | ||
import AlcoholList from "@/components/wiki/AlcoholList"; | ||
import { Pagination, Stack } from "@mui/material"; | ||
import AlcoholListSkeleton from "@/components/wiki/AlcoholListSkeleton"; | ||
|
||
const AlcoholPagenation = () => { | ||
const { data: alcohols, isSuccess } = useGetAlcoholListQuery(); | ||
|
||
return ( | ||
<Stack alignItems="center" gap={2}> | ||
<Stack gap={1} alignItems="center" width={"100%"} height={"232px"}> | ||
{isSuccess ? ( | ||
<AlcoholList data={alcohols?.list} /> | ||
) : ( | ||
<AlcoholListSkeleton disableTimer /> | ||
)} | ||
</Stack> | ||
<Pagination count={alcohols?.totalCount} /> | ||
</Stack> | ||
); | ||
}; | ||
|
||
export default AlcoholPagenation; |
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,15 +1,18 @@ | ||
'use client' | ||
"use client"; | ||
import CustomAppbar from "@/components/CustomAppbar"; | ||
import SearchIcon from "@/assets/icons/SearchIcon.svg"; | ||
import { memo, useContext } from "react"; | ||
import WikiPageContext from "@/store/wiki/WikiPageContext"; | ||
|
||
const WikiAppbar = () => { | ||
const { setIsSearching } = useContext(WikiPageContext); | ||
return ( | ||
<CustomAppbar | ||
title="술백과" | ||
buttonComponent={<SearchIcon />} | ||
onClickButton={() => console.log("눌림")} | ||
onClickButton={() => setIsSearching(true)} | ||
/> | ||
); | ||
}; | ||
|
||
export default WikiAppbar; | ||
export default memo(WikiAppbar); |
Oops, something went wrong.