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

디스커션 페이지네이션 적용 문제 해결 (issue #731) #734

Merged
merged 17 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import NoContent from './NoContent';
import useMissionInProgress from '@/hooks/useMissionInProgress';
import { usePagination } from '@/hooks/usePagination';
import PageButtons from '@/components/common/PageButtons';
import SpinnerSuspense from '@/components/common/SpinnerSuspense';
import { useDashboardLayoutContext } from '@/pages/DashboardPage/DashBoardPageLayout';

export default function DashBoardMissionList() {
const { path } = useDashboardLayoutContext();
const {
currentPage,
setTotalPages,
Expand All @@ -18,16 +19,18 @@ export default function DashBoardMissionList() {
hasNextGroup,
} = usePagination();
const { missionList, totalPage } = useMissionInProgress({
path,
page: currentPage,
onPageInfoUpdate: (totalPagesFromServer) => {
setTotalPages(totalPagesFromServer);
},
});

console.log('missionList : ', missionList);

return (
<>
<SpinnerSuspense />
{!missionList.length ? (
{!missionList?.length ? (
<NoContent type="inProgress" />
) : (
<S.MissionListContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import media from '@/styles/mediaQueries';

export const HashTagWrapper = styled.div`
display: flex;
flex-wrap: wrap;
margin-bottom: 0.5rem;
`;

Expand All @@ -12,6 +13,11 @@ export const HashTag = styled.span<{ $isTitle?: boolean }>`
border-radius: 2rem;
margin-right: 0.7rem;
background-color: ${(props) => (props.$isTitle ? 'var(--danger-50)' : 'var(--primary-50)')};

${media.medium`
flex-wrap: wrap;
margin-bottom: 0.5rem;
`}
`;

export const ImageWrapper = styled.div`
Expand All @@ -28,7 +34,7 @@ export const Image = styled.img`
`;

export const Container = styled.div`
width: 67.4rem;
width: 100%;
height: 100%;

${media.medium`
Expand All @@ -46,11 +52,12 @@ export const DiscussionWrapper = styled(Link)`
margin-top: 3rem;
margin-bottom: 1.5rem;
cursor: pointer;
justify-content: space-between;

${media.medium`
display: flex;
flex-direction: column;
height: 15rem;
height: 100%;
`}
`;

Expand All @@ -74,20 +81,19 @@ export const ImageCommentWrapper = styled.div`
export const TextWrapper = styled.div`
display: flex;
flex-direction: column;
min-width: 50rem;
`;

export const CommentText = styled.span`
${(props) => props.theme.font.body}
margin-bottom: 0.6rem;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
`;

export const SubText = styled.span`
${(props) => props.theme.font.badge}
color : var(--grey-400)
color : var(--grey-400);
margin-bottom: 0.5rem;
`;

export const CommentCountText = styled(SubText)`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import { usePagination } from '@/hooks/usePagination';
import NoContent from '../DashBoardMissionList/NoContent';
import * as S from './DashboardDiscussion.styled';
import DiscussionItem from './DiscussionItem';
import { useDashboardLayoutContext } from '@/pages/DashboardPage/DashBoardPageLayout';

export default function DashBoardDiscussionList() {
const { path } = useDashboardLayoutContext();

const {
currentPage,
setTotalPages,
Expand All @@ -18,6 +21,7 @@ export default function DashBoardDiscussionList() {
} = usePagination();

const { discussionList, totalPage } = useDashboardDiscussion({
path,
page: currentPage,
onPageInfoUpdate: (totalPagesFromServer) => {
setTotalPages(totalPagesFromServer);
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/DashBoard/DiscussionComment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import * as S from '../MyComments/MyComments.styled';
import useDashboardDiscussionComment from '@/hooks/useDashboardDiscussionComment';
import { usePagination } from '@/hooks/usePagination';
import PageButtons from '@/components/common/PageButtons';
import { useDashboardLayoutContext } from '@/pages/DashboardPage/DashBoardPageLayout';

export default function DiscussionCommentList() {
const { path } = useDashboardLayoutContext();

const {
currentPage,
setTotalPages,
Expand All @@ -17,6 +20,7 @@ export default function DiscussionCommentList() {
hasNextGroup,
} = usePagination();
const { discussionCommentList, totalPage } = useDashboardDiscussionComment({
path,
page: currentPage,
onPageInfoUpdate: (totalPagesFromServer) => {
setTotalPages(totalPagesFromServer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import MyComment from './MyComment';
import useMyComments from '@/hooks/useMyComments';
import PageButtons from '@/components/common/PageButtons';
import { usePagination } from '@/hooks/usePagination';
import { useDashboardLayoutContext } from '@/pages/DashboardPage/DashBoardPageLayout';

export default function MyCommentList() {
const { path } = useDashboardLayoutContext();
const {
currentPage,
setTotalPages,
Expand All @@ -16,7 +18,9 @@ export default function MyCommentList() {
hasPreviousGroup,
hasNextGroup,
} = usePagination();

const { myComments, totalPage } = useMyComments({
path,
page: currentPage,
onPageInfoUpdate: (totalPagesFromServer) => {
setTotalPages(totalPagesFromServer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import useSubmittedSolutions from '@/hooks/useSubmittedSolutions';
import { formatDateString } from '@/utils/formatDateString';
import { usePagination } from '@/hooks/usePagination';
import PageButtons from '@/components/common/PageButtons';
import { useDashboardLayoutContext } from '@/pages/DashboardPage/DashBoardPageLayout';

export default function SubmittedSolutionList() {
const { path } = useDashboardLayoutContext();
const {
currentPage,
setTotalPages,
Expand All @@ -25,6 +27,7 @@ export default function SubmittedSolutionList() {
// });

const { submittedSolutionList, totalPage } = useSubmittedSolutions({
path,
page: currentPage,
onPageInfoUpdate: (totalPagesFromServer) => {
setTotalPages(totalPagesFromServer);
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/components/Mission/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PropsWithChildren } from 'react';
import * as S from './Mission.styled';
import { Link } from 'react-router-dom';

Check failure on line 3 in frontend/src/components/Mission/index.tsx

View workflow job for this annotation

GitHub Actions / FE_CI

'Link' is defined but never used
import type { HashTag } from '@/types';

interface MissionProps extends PropsWithChildren {
Expand All @@ -11,9 +11,12 @@
export default function Mission({ id, type, children }: MissionProps) {
// TODO 솔루션 상세 URL이 아직 정해져 있지 않아서 임시로 해놓습니다.
const targeRoute = type === 'mission' ? '/missions/' : '/solutions/';
const URL = 'https://dev.devel-up.co.kr';
const LOCAL_HOST = 'http://localhost:3000';

Check failure on line 15 in frontend/src/components/Mission/index.tsx

View workflow job for this annotation

GitHub Actions / FE_CI

'LOCAL_HOST' is assigned a value but never used
return (
<S.MissionItemContainer>
<Link to={`${targeRoute}${id}`}>{children}</Link>
<a href={`${URL}${targeRoute}${id}`}>{children}</a>
{/* <Link to={`${targeRoute}${id}`}>{children}</Link> */}
</S.MissionItemContainer>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const Container = styled.div`
height: 2.4rem;
margin: 0 auto;
display: flex;
justify-content: center;
margin-top: 1.5rem;
`;

Expand Down
20 changes: 16 additions & 4 deletions frontend/src/hooks/queries/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

export const missionKeys = {
all: ['missions'],
detail: (id: number) => [...missionKeys.all, id],
detail: (id: number, path: string) => [...missionKeys.all, id, path],
inProgress: ['inProgress'],
} as const;

Expand All @@ -24,7 +24,7 @@ export const solutionKeys = {
all: ['solutions'],
detail: (id: number) => [...solutionKeys.all, id],
summaries: ['solutionSummaries'],
submitted: (page: number) => ['submitted solutions', page],
submitted: (page: number, path: string) => ['submitted solutions', page, path],
};

export const discussionKeys = {
Expand All @@ -47,6 +47,18 @@ export const discussionsKeys = {
export const dashboardKeys = {
default: ['dashboard'],
discussions: () => [...dashboardKeys.default, 'discussions'],
discussionComments: (page: number) => [...dashboardKeys.default, 'discussion', 'comments', page],
solutionComments: (page: number) => [...dashboardKeys.default, 'solution', 'comments', page],
discussionComments: (page: number, path: string) => [
...dashboardKeys.default,
'discussion',
'comments',
page,
path,
],
solutionComments: (page: number, path: string) => [
...dashboardKeys.default,
'solution',
'comments',
page,
path,
],
} as const;
9 changes: 7 additions & 2 deletions frontend/src/hooks/useDashboardDiscussion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
import { useEffect } from 'react';

interface UseDashboardDiscussionOptions {
path: string;
page: number;
onPageInfoUpdate?: (totalPage: number) => void;
}

const useDashboardDiscussion = ({ page, onPageInfoUpdate }: UseDashboardDiscussionOptions) => {
const useDashboardDiscussion = ({
path,
page,
onPageInfoUpdate,
}: UseDashboardDiscussionOptions) => {
const { data: dashboardDiscussionResponse } = useSuspenseQuery({
queryKey: dashboardKeys.discussionComments(page),
queryKey: dashboardKeys.discussionComments(page, path),
queryFn: () => getDashboardDiscussion({ page: page.toString() }),
});

Expand All @@ -20,7 +25,7 @@
if (onPageInfoUpdate) {
onPageInfoUpdate(totalPage);
}
}, [currentPage]);

Check warning on line 28 in frontend/src/hooks/useDashboardDiscussion.ts

View workflow job for this annotation

GitHub Actions / FE_CI

React Hook useEffect has missing dependencies: 'onPageInfoUpdate' and 'totalPage'. Either include them or remove the dependency array. If 'onPageInfoUpdate' changes too often, find the parent component that defines it and wrap that definition in useCallback

return { discussionList: data, currentPageFromServer: currentPage, totalPage };
};
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/hooks/useDashboardDiscussionComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
import { useEffect } from 'react';

interface UseDashboardDiscussionCommentOptions {
path: string;
page: number;
onPageInfoUpdate?: (totalPage: number) => void;
}

const useDashboardDiscussionComment = ({
path,
page,
onPageInfoUpdate,
}: UseDashboardDiscussionCommentOptions) => {
const { data: dashboardDiscussionCommentResponse } = useSuspenseQuery({
queryKey: dashboardKeys.discussionComments(page),
queryKey: dashboardKeys.discussionComments(page, path),
queryFn: () => getDashboardDiscussionComments({ page: page.toString() }),
});

Expand All @@ -23,7 +25,7 @@
if (onPageInfoUpdate) {
onPageInfoUpdate(totalPage);
}
}, [currentPage]);

Check warning on line 28 in frontend/src/hooks/useDashboardDiscussionComment.ts

View workflow job for this annotation

GitHub Actions / FE_CI

React Hook useEffect has missing dependencies: 'onPageInfoUpdate' and 'totalPage'. Either include them or remove the dependency array. If 'onPageInfoUpdate' changes too often, find the parent component that defines it and wrap that definition in useCallback

return { discussionCommentList: data, currentPageFromServer: currentPage, totalPage };
};
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/hooks/useDiscussions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
onPageInfoUpdate,
}: UseDiscussionsOptions) => {
const { data: discussionsResponse } = useSuspenseQuery({
queryKey: [...discussionsKeys.all, mission, hashTag],
queryKey: [...discussionsKeys.all, mission, hashTag, page],
queryFn: () =>
getDiscussions({
mission: mission || HASHTAGS.all,
Expand All @@ -35,7 +35,7 @@
if (onPageInfoUpdate) {
onPageInfoUpdate(totalPage);
}
}, [currentPage]);

Check warning on line 38 in frontend/src/hooks/useDiscussions.ts

View workflow job for this annotation

GitHub Actions / FE_CI

React Hook useEffect has missing dependencies: 'onPageInfoUpdate' and 'totalPage'. Either include them or remove the dependency array. If 'onPageInfoUpdate' changes too often, find the parent component that defines it and wrap that definition in useCallback

return { discussions: data, currentPageFromServer: currentPage, totalPage };
};
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/hooks/useMission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getMissionById } from '@/apis/missionAPI';

const useMission = (id: number) => {
return useSuspenseQuery<MissionWithDescription>({
queryKey: missionKeys.detail(id),
queryKey: missionKeys.detail(id, ''),
queryFn: () => getMissionById(id),
});
};
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/hooks/useMissionInProgress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import { useEffect } from 'react';

interface UseMissionInProgressOptions {
path: string;
page: number;
onPageInfoUpdate?: (totalPage: number) => void;
}

const useMissionInProgress = ({ page, onPageInfoUpdate }: UseMissionInProgressOptions) => {
const useMissionInProgress = ({ path, page, onPageInfoUpdate }: UseMissionInProgressOptions) => {
const { data: missionInProgressResponse } = useSuspenseQuery({
queryKey: missionKeys.detail(page),
queryKey: missionKeys.detail(page, path),
queryFn: () => getMissionInProgress({ page: page.toString() }),
});

Expand All @@ -20,7 +21,7 @@
if (onPageInfoUpdate) {
onPageInfoUpdate(totalPage);
}
}, [currentPage]);

Check warning on line 24 in frontend/src/hooks/useMissionInProgress.ts

View workflow job for this annotation

GitHub Actions / FE_CI

React Hook useEffect has missing dependencies: 'onPageInfoUpdate' and 'totalPage'. Either include them or remove the dependency array. If 'onPageInfoUpdate' changes too often, find the parent component that defines it and wrap that definition in useCallback

return { missionList: data, currentPageFromServer: currentPage, totalPage };
};
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/hooks/useMyComments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { getMyComments } from '@/apis/solutionCommentAPI';
import { useEffect } from 'react';

interface UseMyCommentsOptions {
path: string;
page: number;
onPageInfoUpdate?: (totalPage: number) => void;
}

const useMyComments = ({ page, onPageInfoUpdate }: UseMyCommentsOptions) => {
const useMyComments = ({ path, page, onPageInfoUpdate }: UseMyCommentsOptions) => {
const { data: myCommentsResponse } = useSuspenseQuery({
queryKey: dashboardKeys.solutionComments(page),
queryKey: dashboardKeys.solutionComments(page, path),
queryFn: () => getMyComments({ page: page.toString() }),
});

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/hooks/useSubmitSolutionMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const useSubmitSolutionMutation = ({
mutationFn: postSolutionSubmit,
onSuccess: ({ id }) => {
onSuccessCallback();
queryClient.invalidateQueries({ queryKey: missionKeys.detail(missionId) });
queryClient.invalidateQueries({ queryKey: missionKeys.detail(missionId, '') });
queryClient.invalidateQueries({ queryKey: solutionKeys.summaries });
navigate(ROUTES.solutions + `/${id}`);
},
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/hooks/useSubmittedSolutions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { getSubmittedSolution } from '../apis/solutions';
import { useEffect } from 'react';

interface UseSubmittedSolutionsOptions {
path: string;
page: number;
onPageInfoUpdate?: (totalPage: number) => void;
}

const useSubmittedSolutions = ({ page, onPageInfoUpdate }: UseSubmittedSolutionsOptions) => {
const useSubmittedSolutions = ({ path, page, onPageInfoUpdate }: UseSubmittedSolutionsOptions) => {
const { data: submittedSolutionsResponse } = useSuspenseQuery({
queryKey: solutionKeys.submitted(page),
queryKey: solutionKeys.submitted(page, path),
queryFn: () => getSubmittedSolution({ page: page.toString() }),
});

Expand Down
Loading
Loading