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

[SP2] 블로그 페이지 스켈레톤 UI, scrollToTop, react-query #251

Merged
merged 17 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 10 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
2 changes: 2 additions & 0 deletions src/components/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ export function Layout({
const Main = styled.div<{ moreStyle?: SerializedStyles }>`
display: flex;
flex-direction: column;
justify-content: space-between;
height: 100vh;
Copy link
Member

@SeojinSeojin SeojinSeojin Nov 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 추가했을 때 다른 페이지들 깨지지 않는지 확인을 부탁드립니다!!!

여럿이 쓰는 스타일이라서 확인이 필요해요..!!

만약 깨진다면, moreStyles에 넣어주셔요~!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 알겠습니다!

`;
4 changes: 2 additions & 2 deletions src/lib/api/remote/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const client = axios.create({
timeout: DEFAULT_TIMEOUT,
});

const getResponse = async (
export const getResponse = async (
majorTab: number,
subTab: PartCategoryType,
pageNo = 1,
Expand All @@ -21,7 +21,7 @@ const getResponse = async (

const { data } = await client.get(`/reviews?${parameter}`);

return { hasNextPage: data.hasNextPage, response: data.data };
return { hasNextPage: data.hasNextPage, response: data.data, currentPage: data.currentPage };
};

const getSampleReviews = async (): Promise<GetSampleReviewsResponse> => {
Expand Down
12 changes: 7 additions & 5 deletions src/lib/api/remote/sopticle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const client = axios.create({
timeout: DEFAULT_TIMEOUT,
});

const getResponse = async (
export const getResponse = async (
majorTab: number,
subTab: PartCategoryType,
pageNo = 1,
Expand All @@ -28,14 +28,16 @@ const getResponse = async (
const sessionId = sessionStorageHandler.getItemOrGenerate('session-id', nanoid);
const parameter = qs.stringify({ ...partParameter, ...pageParameter, ...generationParameter });

const { data } = await client.get<{ hasNextPage: boolean; data: BlogPostType[] }>(
`/sopticle?${parameter}`,
{ headers: { 'session-id': sessionId } },
);
const { data } = await client.get<{
hasNextPage: boolean;
data: BlogPostType[];
currentPage: number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기 있는거 타입으로 빼면 어떤가요??

BlogPostType을 제너릭 인자로 받아오는 .. 그런 베이스 타입을 선언해두면 나중에 두고두고 쓰기 좋을 것 같아요!!

}>(`/sopticle?${parameter}`, { headers: { 'session-id': sessionId } });

return {
hasNextPage: data.hasNextPage,
response: data.data,
currentPage: data.currentPage,
};
};

Expand Down
1 change: 1 addition & 0 deletions src/lib/types/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type GetSampleReviewsResponse = {
export type GetReviewsResponse = {
response: BlogPostType[];
hasNextPage: boolean;
currentPage: number;
};

export interface ReviewAPI {
Expand Down
1 change: 1 addition & 0 deletions src/lib/types/sopticle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { BlogPostType } from './blog';
export type GetSopticlesResponse = {
hasNextPage: boolean;
response: BlogPostType[];
currentPage: number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리뷰 솝티클 모두 위 코멘트와 마찬가지로 response 를 T로 갖는 새 타입 하나 지정해주시고 같이 쓰면 좋을 것 같아요~

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

음 하나의 타입으로 분리해볼게요!

};

export type PostSopticleLikeResponse = {
Expand Down
53 changes: 35 additions & 18 deletions src/views/BlogPage/BlogPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import PageLayout from '@src/components/common/PageLayout';
import useStorage from '@src/hooks/useStorage';
import { activeGenerationCategoryList } from '@src/lib/constants/tabs';
import { PartCategoryType } from '@src/lib/types/blog';
import BlogPostSkeletonUI from '@src/views/BlogPage/components/BlogPostSkeletonUI';
import { OvalSpinner } from '@src/views/ProjectPage/components';
import BlogPostList from './components/BlogPostList';
import BlogTab from './components/BlogTab';
import { BlogTabType } from './components/BlogTab/types';
import useFetch from './hooks/useFetch';
import { useGetResponse } from './hooks/queries/useGetResponse';
import useInfiniteScroll from './hooks/useInfiniteScroll';
import * as S from './style';

export default function BlogPage() {
Expand All @@ -26,17 +28,19 @@ export default function BlogPage() {
PartCategoryType.ALL,
);

const {
state: response,
ref,
canGetMoreResponse,
} = useFetch({
const { response, hasNextPage, fetchNextPage, isFetching } = useGetResponse(
selectedTab,
selectedMajorCategory,
selectedSubCategory,
});
);
const { ref } = useInfiniteScroll(fetchNextPage);

const showTotalPostList = () => {
setMajorCategory(activeGenerationCategoryList[0]);
setSubCategory(PartCategoryType.ALL);
};

if (!(response._TAG === 'OK' || response._TAG === 'LOADING')) return null;
if (!response) return null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null을 return 하다 보니 데이터가 내려오기 전까지 탭을 전환하거나 필터 전환, 새로고침 등을 했을 때 잠깐 검은 화면이 보이게 됩니다. 사용성이 좋지 않다고 느껴져서 개선하면 좋을 것 같습니다!

1.mp4

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분 query 결과로 respons가 undefined가 내려오는 경우를 예외처리한건데ㅔ, v5로 업데이트하면 undefiend가 반환되지 않아서 그때 제거하면 될 거같아요!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

서스펜스쿼리는 그렇다고 알고 있는데 useInfiniteQuery도 데이터가 무조건 define되어서 내려오나요?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

데이터 fetching 전에 undefined 가 뜹니다!
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗 v5로 업데이트 했을 때요!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

공식문서에 return 값에 대한 특징이 useQuery와 동일하게 가져간다고 나와있습니다!
image
v5공식문서

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확인했는데 v5 useQuery도 data 기본값이 undefined인 것 같아요..!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 제가 착각했네요...! 해당 내용말고 useInfiniteQuery와 동일한 기능을하는데 혜준언니가 프로젝트 탭에서 말해준 서스펜스 기능을하는 useSuspenseInfiniteQuery
을 봤습니다!
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

위에 조건문 수정하면서 해당 문제도 수정했습니다!

2023-11-05.11.06.25.mov


return (
<PageLayout>
Expand All @@ -48,16 +52,29 @@ export default function BlogPage() {
selectedSubCategory={selectedSubCategory}
setSubCategory={setSubCategory}
/>
<BlogPostList
selectedTap={selectedTab}
setMajorCategory={setMajorCategory}
setSubCategory={setSubCategory}
blogPostList={response.data}
/>
{(canGetMoreResponse || response._TAG === 'LOADING') && (
<S.SpinnerWrapper ref={canGetMoreResponse ? ref : undefined}>
<OvalSpinner />
</S.SpinnerWrapper>

{response.length === 0 ? (
isFetching ? (
<BlogPostSkeletonUI />
) : (
<S.EmptyBlogPostListWrapper>
<S.EmptyBlogPostList>
{`아직 올라온 ${selectedTab === 'article' ? '아티클이' : '활동후기가'} 없어요`}
</S.EmptyBlogPostList>
<S.Total onClick={showTotalPostList}>{`${
selectedTab === 'article' ? '아티클' : '활동후기'
} 전체 보기`}</S.Total>
</S.EmptyBlogPostListWrapper>
)
) : (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이전에 코멘트 드렸던 대로 이 부분은 항상 삼항 연산자 밖에 있어도 괜찮을 것 같아요!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이번에 작업하면서 다시 안으로 들어갔나봐요....😂 다시 조건문 고민해볼게요!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SeojinSeojin 서진 ~ 이부분 코멘트 좀 더 자세히 해줄 수 있을까요?
위 코멘트도 다시 읽어봤는데...!

저의생각))
BlogPostList를 선택적으로 띄울 필요가 없다!!
왜냐면, 위에서 제가 제안한 대로 '아직 올라온 아티클이/활동후기가 없어요' 부분이 여기로 빠진다면,
-> BlogPostList는 response.data를 띄우는 역할만 할 것이고,
-> 그럼 자연스럽게 response.data.length가 0이면 아무것도 안 보일 것이기 때문에
굳이 패칭 시작해서 data.length가 0이 될 때마다 마운트/언마운트를 시키지 않아도 괜찮을 거라고 생각합니다!!!!!!!!!

여기서 BlogPostList를 선택적을 띄울 필요가 없는 것은 이해하겠는데, 아직 올라온 아티클이/활동후기가 없어요' 게 어디로 빠지면 좋겠다는지 이해가 잘 안돼서요..!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이전에는 문구가 blogPostList 컴포넌트 아래에 있었는데, 그것의 부모 컴포넌트인 이곳으로 오면 좋겠다는 뜻이었어요..!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아,..! 저렇게 두어도 좋겠다는 뜻이었구뇨! 이해했습니다 !!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시 이 부분 의도하신 흐름에 대해서 말로 풀어서 설명해주실 수 있나요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

      {!response ? (
        <BlogPostSkeletonUI />
      ) : (
        <>
          {response.length === 0 ? (
            <S.EmptyBlogPostListWrapper>
              <S.EmptyBlogPostList>
                {`아직 올라온 ${selectedTab === 'article' ? '아티클이' : '활동후기가'} 없어요`}
              </S.EmptyBlogPostList>
              <S.Total onClick={showTotalPostList}>{`${
                selectedTab === 'article' ? '아티클' : '활동후기'
              } 전체 보기`}</S.Total>
            </S.EmptyBlogPostListWrapper>
          ) : (
            <>
              <BlogPostList selectedTap={selectedTab} blogPostList={response} />
              {(hasNextPage || isFetching) && (
                <S.SpinnerWrapper ref={hasNextPage ? ref : undefined}>
                  <OvalSpinner />
                </S.SpinnerWrapper>
              )}
            </>
          )}
        </>
      )}

이렇게 수정하였습니다!
데이터가 ㅐ처음 패칭중일때 undefined를 반환해서 그때는 BlogPostSkeletonUI 를 보여주고
response.length === 0 으로 아티클이 없을때는 없다는 문구가, !== 0으로 있을때는 리스트가 보여지게 됩니다!

<>
<BlogPostList selectedTap={selectedTab} blogPostList={response} />
{(hasNextPage || isFetching) && (
<S.SpinnerWrapper ref={hasNextPage ? ref : undefined}>
<OvalSpinner />
</S.SpinnerWrapper>
)}
</>
)}
</PageLayout>
);
Expand Down
2 changes: 1 addition & 1 deletion src/views/BlogPage/components/BlogPost/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const BlogPost = styled.section`
cursor: pointer;
transition: opacity 0.2s linear;
&:hover {
opacity: 0.8;
opacity: 0.7;
}

/* 모바일 뷰 */
Expand Down
37 changes: 6 additions & 31 deletions src/views/BlogPage/components/BlogPostList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,20 @@
import { activeGenerationCategoryList } from '@src/lib/constants/tabs';
import type { BlogPostType } from '@src/lib/types/blog';
import { PartCategoryType } from '@src/lib/types/blog';
import BlogPost from '@src/views/BlogPage/components/BlogPost';
import * as S from './style';

interface BlogPostListProps {
selectedTap: string; // review || article

blogPostList: BlogPostType[];
setMajorCategory: (newValue: number) => void;
setSubCategory: (newValue: PartCategoryType) => void;
}

export default function BlogPostList({
selectedTap,
blogPostList,
setMajorCategory,
setSubCategory,
}: BlogPostListProps) {
const showTotalPostList = () => {
setMajorCategory(activeGenerationCategoryList[0]);
setSubCategory(PartCategoryType.ALL);
};
export default function BlogPostList({ selectedTap, blogPostList }: BlogPostListProps) {
return (
<S.BlogPostListWrapper>
{blogPostList.length === 0 ? (
<>
<S.EmptyBlogPostList>
{`아직 올라온 ${selectedTap === 'article' ? '아티클이' : '활동후기가'} 없어요`}
</S.EmptyBlogPostList>
<S.Total onClick={showTotalPostList}>{`${
selectedTap === 'article' ? '아티클' : '활동후기'
} 전체 보기`}</S.Total>
</>
) : (
<S.BlogPostList>
{blogPostList?.map((blogPost) => (
<BlogPost key={blogPost.id} blogPost={blogPost} selectedTap={selectedTap} />
))}
</S.BlogPostList>
)}
<S.BlogPostList>
{blogPostList?.map((blogPost) => (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapper이랑 요거랑 하나로 합칠 수 있을 것 같습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혜준언니가 작업한거라 스타일 하나를 수정하면 연달아 다 수정해야할 것 같아서 시도는 해볼게요!

<BlogPost key={blogPost.id} blogPost={blogPost} selectedTap={selectedTap} />
))}
</S.BlogPostList>
</S.BlogPostListWrapper>
);
}
48 changes: 0 additions & 48 deletions src/views/BlogPage/components/BlogPostList/style.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import styled from '@emotion/styled';
import { colors } from '@sopt-makers/colors';

export const BlogPostListWrapper = styled.div`
display: flex;
Expand Down Expand Up @@ -28,50 +27,3 @@ export const BlogPostList = styled.div`
gap: 36px;
}
`;

export const EmptyBlogPostList = styled.section`
color: ${colors.white};
font-size: 32px;
font-weight: 700;
line-height: 48px; /* 150% */
letter-spacing: -0.64px;
margin-top: 108px;
margin-bottom: 24px;

/* 모바일 뷰 */
@media (max-width: 767px) {
font-size: 18px;
line-height: 28px; /* 155.556% */
letter-spacing: -0.36px;
margin-top: 90px;
margin-bottom: 16px;
}
`;

export const Total = styled.button`
background-color: ${colors.gray10};

height: 42px;
padding: 0px 24px;
justify-content: center;
align-items: center;
gap: 10px;
border-radius: 8px;
color: ${colors.gray950};
font-family: SUIT;
font-size: 16px;
font-weight: 600;
line-height: 22px; /* 137.5% */
letter-spacing: -0.32px;

cursor: pointer;

/* 모바일 뷰 */
@media (max-width: 767px) {
height: 36px;
padding: 8px 14px;
font-size: 14px;
line-height: 18px; /* 128.571% */
letter-spacing: -0.28px;
}
`;
30 changes: 30 additions & 0 deletions src/views/BlogPage/components/BlogPostSkeletonUI/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as S from './style';

export default function BlogPostSkeletonUI() {
const BlogPostSkeletonUIList = [0, 1, 2];

return (
<S.BlogPostListWrapper>
<S.BlogPostList>
{BlogPostSkeletonUIList.map((value) => (
<S.BlogPost key={value}>
<S.HeaderWrapper>
<S.Header></S.Header>
<S.Body>
<S.Title />
<S.Description />
</S.Body>
<S.TagList>
<S.Tag />
<S.Tag />
</S.TagList>
</S.HeaderWrapper>
<S.ThumbnailWrapper>
<S.Thumbnail />
</S.ThumbnailWrapper>
</S.BlogPost>
))}
</S.BlogPostList>
</S.BlogPostListWrapper>
);
}
Loading
Loading