Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/LikeLion-KNU/knufest into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
junyeokk committed May 20, 2024
2 parents af2a827 + 4e6cbc8 commit 40e49a0
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 444 deletions.
640 changes: 209 additions & 431 deletions src/components/map/Map.tsx

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions src/components/navigation/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Dispatch } from "@reduxjs/toolkit";

export const Pagination: React.FC = () => {
const dispatch: Dispatch = useDispatch();
const { currentPage, page, perPage } = useSelector((state: RootState) => state.page);
const { currentPage, page, perPage, maxPage } = useSelector((state: RootState) => state.page);

const handlePageBtnClick = useCallback(
(e: React.MouseEvent<HTMLButtonElement>) => {
Expand All @@ -29,11 +29,15 @@ export const Pagination: React.FC = () => {
<PaginationContainer>
<PageSkipButton onClick={handlePrevBtnClick}>{"<"}</PageSkipButton>
{Array.from({ length: perPage }, (_, k) => page + k).map((page) => {
return (
<PageButton active={page === currentPage} onClick={handlePageBtnClick}>
{page}
</PageButton>
);
if (page <= maxPage) {
return (
<PageButton active={page === currentPage} onClick={handlePageBtnClick}>
{page}
</PageButton>
);
} else {
return <></>;
}
})}
<PageSkipButton onClick={handleNextBtnClick}>{">"}</PageSkipButton>
</PaginationContainer>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/BoothDetailPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ export default function BoothDetailPage() {
commentInputRef.current.value = "";
}}
>
<input ref={commentInputRef} placeholder="댓글 기능이 현재 비활성화되었습니다." disabled />
<SubBtn type="submit" disabled>
<input ref={commentInputRef} placeholder="댓글을 입력해주세요!" />
<SubBtn type="submit">
<SendImg src={sendImg} />
</SubBtn>
</ContentContainer>
Expand Down
12 changes: 11 additions & 1 deletion src/pages/BoothListPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useCallback, useState } from "react";
import React, { useCallback, useEffect, useState } from "react";
import { useDispatch } from "react-redux";
import { TransformComponent, TransformWrapper } from "react-zoom-pan-pinch";

import { Variants } from "framer-motion";
Expand All @@ -12,6 +13,8 @@ import { Text } from "@/components/typography/Text";
import { useAllBooth } from "@/services/booth/booth.hooks";

import { BoothSearchInput, VisibleList } from "./BoothListPage.styled";
import { pageActions } from "@/store/page.slice";
import { Dispatch } from "@reduxjs/toolkit";

const listVariants: Variants = {
hidden: {
Expand All @@ -34,6 +37,13 @@ const BoothListPage: React.FC = () => {
}, []);

const { isPending, boothList } = useAllBooth();

const dispatch: Dispatch = useDispatch();

useEffect(() => {
dispatch(pageActions.setPage(1));
}, [dispatch]);

return (
<>
<Paragraph size="m" weight="bold" variant="darkpurple">
Expand Down
8 changes: 7 additions & 1 deletion src/services/booth/booth.hooks.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { useCallback, useEffect, useState } from "react";
import { useDispatch } from "react-redux";
import { useParams } from "react-router-dom";

import { useVisitor } from "@/hooks/useVisitor";

import { boothService } from "./booth.service";
import { IBoothItem, IReadBoothByIdResponse } from "./booth.types";
import { pageActions } from "@/store/page.slice";
import { Dispatch } from "@reduxjs/toolkit";

export const useAllBooth = () => {
const [isPending, setIsPending] = useState<boolean>(false);
Expand Down Expand Up @@ -46,6 +49,8 @@ export const useLikes = (initLikeable: boolean, category: string, boothId: numbe
};

export const useBoothDetail = () => {
const dispatch: Dispatch = useDispatch();

const { category, boothId } = useParams();
const { visitorId } = useVisitor();

Expand All @@ -57,12 +62,13 @@ export const useBoothDetail = () => {
boothService
.readBoothById(category as string, parseInt(boothId as string), visitorId as string)
.then((data) => {
dispatch(pageActions.setMaxPage(Math.ceil(data.commentCount / 20)));
setBoothDetail(data);
})
.finally(() => {
setIsPending(false);
});
}, [category, boothId, visitorId]);
}, [category, boothId, visitorId, dispatch]);

return { isPending, boothDetail };
};
1 change: 1 addition & 0 deletions src/services/booth/booth.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ export interface IReadBoothByIdResponse {
urls: string[];
likable: boolean;
boothDescription?: string;
commentCount: number;
}
7 changes: 5 additions & 2 deletions src/services/comment/comment.hooks.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { useCallback, useEffect, useRef, useState } from "react";
import { useSelector } from "react-redux";
import { useDispatch, useSelector } from "react-redux";
import { useParams } from "react-router-dom";

import { useVisitor } from "@/hooks/useVisitor";

import { commentService } from "./comment.service";
import { IComment } from "./comment.types";
import { RootState } from "@/store/store";
import { Dispatch } from "@reduxjs/toolkit";

export const useComment = () => {
const dispatch: Dispatch = useDispatch();

const commentInputRef = useRef<HTMLInputElement>(null);

const { visitorId } = useVisitor();
Expand Down Expand Up @@ -51,7 +54,7 @@ export const useComment = () => {
setIsPending(false);
setRefetch(false);
});
}, [category, currentPage, visitorId, boothId, refetch]);
}, [category, currentPage, visitorId, boothId, refetch, dispatch]);

return { isPending, comments, handleCommentSubmit, handleCommentDelete, commentInputRef };
};
2 changes: 1 addition & 1 deletion src/store/page.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const initialState: IPageState = {
currentPage: 1,
page: 1,
perPage: 5,
maxPage: 20,
maxPage: 0,
};

export const pageSlice = createSlice({
Expand Down

0 comments on commit 40e49a0

Please sign in to comment.