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

술백과-페이지네이션-추가 #95

Merged
merged 3 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions client/src/__test__/post/formatTime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe("인스타그램 스타일 시간 포매팅 함수", () => {
const THREE_DAYS_AGO = "Thu Dec 11 2023 00:50:25 GMT+0900 (한국 표준시)";
const EIGHT_DAYS_AGO = "Thu Dec 6 2023 00:50:25 GMT+0900 (한국 표준시)";
const ONE_MONTH_AGO = "Thu Nov 11 2023 00:50:25 GMT+0900 (한국 표준시)";
const THREE_MONTH_AGO = "Thu Sep 11 2023 00:50:25 GMT+0900 (한국 표준시)";
const THREE_MONTH_AGO = "Thu Oct 11 2023 00:50:25 GMT+0900 (한국 표준시)";
const ONE_YEAR_AGO = "Thu Dec 14 2022 00:50:25 GMT+0900 (한국 표준시)";

it("3일 전이 입력되었을때 '3일 전' 이 출력되는지", () => {
Expand All @@ -14,13 +14,13 @@ describe("인스타그램 스타일 시간 포매팅 함수", () => {
it("8일 전이 입력되었을때 '1주 전' 이 출력되는지", () => {
expect(formatTime(EIGHT_DAYS_AGO, MOCK_NOW)).toEqual("1주 전");
});
it("1달전 이 입력되었을때 '1달 전'이 출력되는지 Trim 하는지 여부", () => {
it("1달전 이 입력되었을때 '1달 전'이 출력되는지 여부", () => {
expect(formatTime(ONE_MONTH_AGO, MOCK_NOW)).toEqual("1달 전");
});
it("3달전 이 입력되었을때 '3달 전'이 출력되는지 Trim 하는지 여부", () => {
it("3달전 이 입력되었을때 '3달 전'이 출력되는지 여부", () => {
expect(formatTime(THREE_MONTH_AGO, MOCK_NOW)).toEqual("3달 전");
});
it("1년전 이 입력되었을때 '1년 전'이 출력되는지 Trim 하는지 여부", () => {
it("1년전 이 입력되었을때 '1년 전'이 출력되는지 여부", () => {
expect(formatTime(ONE_YEAR_AGO, MOCK_NOW)).toEqual("1년 전");
});
});
jobkaeHenry marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 9 additions & 0 deletions client/src/assets/icons/Alcohol/AllAlcoholIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 2 additions & 6 deletions client/src/components/layout/CustomContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@ interface CustomContainerInterface extends ContainerProps {
mt?: number;
}

const CustomContainer = ({
sx,
mt,
children,
}: CustomContainerInterface) => {
const CustomContainer = ({ sx, mt, children }: CustomContainerInterface) => {
return (
<Container
sx={{ ...sx, px: { xs: 0, sm: 4 }, mt: mt!==undefined ? mt : 8 }}
sx={{ ...sx, px: { xs: 0, sm: 4 }, mt: mt !== undefined ? mt : 8 }}
maxWidth={"lg"}
>
<Paper
jobkaeHenry marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
4 changes: 3 additions & 1 deletion client/src/components/newpost/SearchAlcoholInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ const SearchAlcoholInput = ({
const [isSearchingAlcohol, setIsSearchingAlCohol] = useState(false);

// 검색결과
const { data, isLoading, isSuccess } = useGetAlcoholListQuery(debouncedValue);
const { data, isLoading, isSuccess } = useGetAlcoholListQuery({
searchKeyword: debouncedValue,
});
// 유저가 검색후 최종적으로 선택한 값
const [selectedAlcohol, setSelectedAlcohol] = useState<
| Pick<AlcoholDetailInterface, "alcoholName" | "alcoholNo" | "alcoholType">
jobkaeHenry marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
8 changes: 7 additions & 1 deletion client/src/components/post/PostCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { postcardContext } from "@/store/post/PostCardContext";
import formatTime from "@/utils/formatTime";
import copyToClipboard from "@/utils/copyToClipboard";
import { useGlobalSnackbarStore } from "@/store/useGlobalSnackbarStore";
import usePushToWikiDetail from "@/hooks/wiki/usePushToWikiDetail";

const PostCard = ({
postAttachUrls,
Expand Down Expand Up @@ -66,6 +67,8 @@ const PostCard = ({
[currentUser]
);

const onClickElementHandler = usePushToWikiDetail();

const CLIENT_BASE_URL = process.env.NEXT_PUBLIC_CLIENT_BASE_URL;
const fireToast = useGlobalSnackbarStore(({ fireToast }) => fireToast);
const copyToClipboardHander = async () => {
Expand Down Expand Up @@ -134,6 +137,9 @@ const PostCard = ({
alcoholNo={alcoholNo}
alcoholName={alcoholName}
alcoholType={alcoholType}
onClick={() => {
onClickElementHandler({ alcoholName, alcoholNo });
}}
/>
)}

Expand All @@ -143,7 +149,7 @@ const PostCard = ({
dangerouslySetInnerHTML={{
__html: sanitize(postContent),
}}
onClick={() => openPostDetailPage(id, String(postNo))}
onClick={() => openPostDetailPage(id, String(postNo))}
></div>
{/* Hash tags */}
<PostHashTagList tags={tagList} />
jobkaeHenry marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
7 changes: 4 additions & 3 deletions client/src/components/wiki/AlcoholList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import { Typography } from "@mui/material";
import { memo } from "react";
import AlcoholListSkeleton from "./AlcoholListSkeleton";

interface AlcoholList {
interface AlcoholListInterface {
data?: AlcoholDetailInterface[];
onClickElement?: (data: AlcoholDetailInterface) => void;
size?:number
}
/**
* 술 정보 Array 를 입력받아 List로 맵핑해주는 컴포넌트
* onClickElement 속성으로 각 엘리먼트 클릭 시 속성을 지정가능
* @returns
*/
const AlcoholList = ({ data: alcohols, onClickElement }: AlcoholList) => {
const AlcoholList = ({ data: alcohols, onClickElement,size=5 }: AlcoholListInterface) => {
return alcohols ? (
<>
{alcohols.length > 0 ? (
Expand All @@ -37,7 +38,7 @@ const AlcoholList = ({ data: alcohols, onClickElement }: AlcoholList) => {
)}
</>
) : (
<AlcoholListSkeleton disableTimer />
<AlcoholListSkeleton size={size} disableTimer/>
);
};
export default memo(AlcoholList);
jobkaeHenry marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions client/src/components/wiki/AlcoholNameTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const WrapperStyle = {
border: "1px solid",
borderColor: "gray.secondary",
backgroundColor: "gray.primary",
cursor: "pointer",
display: "flex",
flexDirection: "row",
alignItems: "center",
jobkaeHenry marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
68 changes: 63 additions & 5 deletions client/src/components/wiki/AlcoholPagination.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,79 @@
"use client";
import useGetAlcoholListQuery from "@/queries/alcohol/useGetAlcoholListQuery";
import useGetAlcoholListQuery, {
AlcohilListQueryKey,
getAlcoholListByKeyword,
} from "@/queries/alcohol/useGetAlcoholListQuery";
import AlcoholList from "@/components/wiki/AlcoholList";
import { Pagination, Stack } from "@mui/material";
import usePushToWikiDetail from "@/hooks/wiki/usePushToWikiDetail";
import { useEffect, useState } from "react";
import { useQueryClient } from "@tanstack/react-query";

const AlcoholPagenation = () => {
const { data: alcohols } = useGetAlcoholListQuery("");
const [currentPage, setCurrentPage] = useState(1);
const size = 10;

const { data: alcohols } = useGetAlcoholListQuery({
searchKeyword: "",
page: currentPage - 1,
size,
});

const [totalCount, setTotalCount] = useState(alcohols?.totalCount);

useEffect(() => {
const isSameWithPreviousValue =
totalCount === alcohols?.totalCount || alcohols?.totalCount === undefined;

if (isSameWithPreviousValue) return;
setTotalCount(alcohols?.totalCount);
}, [alcohols]);

const queryClient = useQueryClient();

useEffect(() => {
const handler = async () => {
const nextPageParams = {
searchKeyword: "",
size,
page: currentPage + 1,
};

const fetchedNextPage = queryClient.getQueryData(
AlcohilListQueryKey.byKeyword(nextPageParams)
);

if (fetchedNextPage) return;
const nextPage = await getAlcoholListByKeyword(nextPageParams);

queryClient.setQueryData(
AlcohilListQueryKey.byKeyword(nextPageParams),
nextPage
);
};

handler();
}, [currentPage]);

const onClickElementHandler = usePushToWikiDetail();

return (
<Stack alignItems="center" gap={2}>
<Stack gap={1} alignItems="center" width={"100%"} height={"232px"}>
<Stack gap={1} alignItems="center" width={"100%"}>
<AlcoholList
data={alcohols?.list}
onClickElement={onClickElementHandler}
size={size}
onClickElement={({ alcoholName, alcoholNo }) =>
onClickElementHandler({ alcoholName, alcoholNo })
}
/>
</Stack>
<Pagination count={alcohols?.totalCount} />
<Pagination
count={(totalCount ?? 0) / size - 1}
page={currentPage}
siblingCount={2}
onChange={(_e, page) => setCurrentPage(page)}
/>
</Stack>
);
};
jobkaeHenry marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
2 changes: 2 additions & 0 deletions client/src/components/wiki/WikiAlcoholSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useState, useCallback, useMemo } from "react";
import { Stack } from "@mui/material";
import WikiAlcoholSelectorBtn from "./WikiAlcoholSelectorBtn";
import WineIcon from "@/assets/icons/Alcohol/WineIcon.svg";
import AllAlcoholIcon from "@/assets/icons/Alcohol/AllAlcoholIcon.svg";
import WiskyIcon from "@/assets/icons/Alcohol/WiskyIcon.svg";
import SpiritsIcon from "@/assets/icons/Alcohol/SpiritsIcon.svg";
import TraditionalAlcoholIcon from "@/assets/icons/Alcohol/TraditionalAlcoholIcon.svg";
Expand All @@ -11,6 +12,7 @@ import SakeIcon from "@/assets/icons/Alcohol/SakeIcon.svg";
const WikiAlcoholSelector = () => {
const btnList = useMemo(
() => [
{ title: "전체", iconComponent: <AllAlcoholIcon /> },
{ title: "포도주", iconComponent: <WineIcon /> },
{ title: "위스키", iconComponent: <WiskyIcon /> },
{ title: "증류주", iconComponent: <SpiritsIcon /> },
jobkaeHenry marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
37 changes: 20 additions & 17 deletions client/src/components/wiki/WikiAlcoholSelectorBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,27 @@ const WikiAlcoholSelectorBtn = ({
...buttonBaseProps
}: WiciAlcoholSelectorBtnProps) => {
return (
<ButtonBase onClick={onClick} {...buttonBaseProps}>
<Stack alignItems="center">
<Stack
justifyContent="center"
alignItems="center"
sx={{
borderRadius: "50%",
width: 56,
height: 56,
backgroundColor: isSelected ? "primary.main" : "#F6EAFB",
transitionDuration: 200,
}}
>
{iconComponent}
</Stack>
<Typography sx={{ py: 1 }}>{title}</Typography>
<Stack
component={ButtonBase}
alignItems="center"
onClick={onClick}
{...buttonBaseProps}
>
<Stack
justifyContent="center"
alignItems="center"
sx={{
borderRadius: "50%",
width: 56,
height: 56,
backgroundColor: isSelected ? "primary.main" : "#F6EAFB",
transitionDuration: 200,
}}
>
{iconComponent}
</Stack>
</ButtonBase>
<Typography sx={{ py: 1 }}>{title}</Typography>
</Stack>
);
};

jobkaeHenry marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
4 changes: 3 additions & 1 deletion client/src/components/wiki/searchDrawer/WikiSerachArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const WikiSerachArea = () => {

const [searchKeyword, setSearchKeyword] = useState("");
const debouncedValue = useDebounce(searchKeyword, 300);
const { data: alcohols } = useGetAlcoholListQuery(debouncedValue);
const { data: alcohols } = useGetAlcoholListQuery({
searchKeyword: debouncedValue,
});

const onClickElementHandler = usePushToWikiDetail();

jobkaeHenry marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
8 changes: 7 additions & 1 deletion client/src/hooks/wiki/usePushToWikiDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import { useCallback } from "react";
import useSearchHistory from "../searchHistory/useSearchHistory";
import { ALCOHOL_SEARCH_HISTORY } from "@/const/localstorageKey";
import { WIKI_DETAIL } from "@/const/clientPath";

interface OnclickElementHandlerInterface {
alcoholName: AlcoholDetailInterface["alcoholName"];
alcoholNo: AlcoholDetailInterface["alcoholNo"];
}

/**
* 검색히스토리에 해당 술을 남기고, 디테일페이지로 이동시키는 함수를 리턴하는 훅
* @returns 해당 callback함수
Expand All @@ -15,7 +21,7 @@ const usePushToWikiDetail = () => {
* 검색히스토리에 해당 술을 남기고, 디테일페이지로 이동시키는 함수를 리턴하는 함수
*/
const onClickElementHandler = useCallback(
({ alcoholName, alcoholNo }: AlcoholDetailInterface) => {
({ alcoholName, alcoholNo }: OnclickElementHandlerInterface) => {
addToSearchHistory(alcoholName);
router.push(WIKI_DETAIL(String(alcoholNo)));
},
jobkaeHenry marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading