Skip to content

Commit

Permalink
chore: 메인페이지 rsc suspense 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
bae-sh committed Jan 14, 2024
1 parent 75e2b35 commit 69800f3
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 32 deletions.
19 changes: 0 additions & 19 deletions client/src/app/(home)/components/Loading/index.stories.tsx

This file was deleted.

8 changes: 6 additions & 2 deletions client/src/app/(home)/components/PostsBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import { IPostInformation } from '@/types';
import { PostSummary } from '@/components/Post';
import { LoadingIcon } from '@/components';

function PostsBox() {
const { datas, hasNextPage } = useScroll();
interface PostsBoxProps {
initialData?: { data: IPostInformation[]; nextPageParms?: string };
}

function PostsBox({ initialData }: PostsBoxProps) {
const { datas, hasNextPage } = useScroll({ initialData });

return (
<>
Expand Down
1 change: 0 additions & 1 deletion client/src/app/(home)/components/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { default as Loading } from './Loading';
export { default as PostsBox } from './PostsBox';
export { default as WritePostButton } from './WritePostButton';
8 changes: 7 additions & 1 deletion client/src/app/(home)/hooks/useScroll.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
'use client';

import getAllPosts from '@/service/post/getAllPosts';
import { IPostInformation } from '@/types';
import { useInfiniteQuery } from '@tanstack/react-query';
import { useEffect } from 'react';

function useScroll() {
function useScroll({
initialData,
}: {
initialData?: { data: IPostInformation[]; nextPageParms?: string };
}) {
const { data, fetchNextPage, hasNextPage, isFetching } = useInfiniteQuery({
...(!!initialData && initialData),
queryKey: ['projects'],
queryFn: getAllPosts,
getNextPageParam: (lastPage) => lastPage?.nextPageParms,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import Skeleton from '../../../../components/Skeleton';
import { Skeleton } from '@/components';

function Loading() {
return (
Expand Down
12 changes: 8 additions & 4 deletions client/src/app/(home)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
//core
import React, { Suspense } from 'react';
import { Suspense } from 'react';

//components
import { Advertisement } from '@/components';
import Loading from './loading';

//third party
import { Loading, PostsBox, WritePostButton } from './components';
import { PostsBox, WritePostButton } from './components';
import getAllPosts from '@/service/post/getAllPosts';

export default async function Home() {
const data = await getAllPosts({});

export default function Home() {
return (
<div className="flex justify-between max-w-5xl mx-auto">
<div className="flex flex-col w-full gap-3 md:w-8/12">
<WritePostButton />
<Suspense fallback={<Loading />}>
<PostsBox />
<PostsBox initialData={data} />
</Suspense>
</div>
<Advertisement />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Skeleton } from '@/components';
import React from 'react';
import Skeleton from '../../../../components/Skeleton';

function Loading() {
return (
Expand Down
3 changes: 2 additions & 1 deletion client/src/app/board/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import React, { Suspense } from 'react';

//components
import { Loading, PostContent } from '@/app/board/components';
import { PostContent } from '@/app/board/components';
import Loading from './loading';

//types
import { postManager } from '@/service/post';
Expand Down
1 change: 0 additions & 1 deletion client/src/app/board/components/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { default as PostContent } from './PostContent';
export { default as Loading } from './Loading';
export { default as PostDetail } from './PostDetail';

0 comments on commit 69800f3

Please sign in to comment.