-
Notifications
You must be signed in to change notification settings - Fork 7
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
Changes from all commits
f7c1911
2a86d6b
c234433
52a2959
e0caa9e
7153650
7836dda
95bde73
dd998ad
39f9e4f
bca49e1
bca7ac1
91be630
10711ac
58f9b12
ecc8594
389618e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,11 @@ | ||
import { PartCategoryType } from '@src/lib/types/blog'; | ||
import { BlogPostType } from './blog'; | ||
import { BlogPostType, BlogResponse } from './blog'; | ||
|
||
export type GetSampleReviewsResponse = { | ||
reviews: BlogPostType[]; | ||
}; | ||
|
||
export type GetReviewsResponse = { | ||
response: BlogPostType[]; | ||
hasNextPage: boolean; | ||
}; | ||
|
||
export interface ReviewAPI { | ||
getResponse( | ||
majorTab: number, | ||
subTab: PartCategoryType, | ||
page: number, | ||
): Promise<GetReviewsResponse>; | ||
getResponse(majorTab: number, subTab: PartCategoryType, page: number): Promise<BlogResponse>; | ||
getSampleReviews(): Promise<GetSampleReviewsResponse>; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,11 @@ | ||
import { PartCategoryType } from '@src/lib/types/blog'; | ||
import { BlogPostType } from './blog'; | ||
|
||
export type GetSopticlesResponse = { | ||
hasNextPage: boolean; | ||
response: BlogPostType[]; | ||
}; | ||
import { BlogResponse } from './blog'; | ||
|
||
export type PostSopticleLikeResponse = { | ||
currentLike: boolean; | ||
likeChanged: boolean; | ||
}; | ||
export interface SopticleAPI { | ||
getResponse( | ||
majorTab: number, | ||
subTab: PartCategoryType, | ||
page: number, | ||
): Promise<GetSopticlesResponse>; | ||
getResponse(majorTab: number, subTab: PartCategoryType, page: number): Promise<BlogResponse>; | ||
postSopticleLike(sopticleId: number, prevLike: boolean): Promise<PostSopticleLikeResponse>; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
import { css } from '@emotion/react'; | ||
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() { | ||
|
@@ -26,20 +29,26 @@ 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); | ||
|
||
if (!(response._TAG === 'OK' || response._TAG === 'LOADING')) return null; | ||
const showTotalPostList = () => { | ||
setMajorCategory(activeGenerationCategoryList[0]); | ||
setSubCategory(PartCategoryType.ALL); | ||
}; | ||
|
||
return ( | ||
<PageLayout> | ||
<PageLayout | ||
showScrollTopButton | ||
moreStyle={css` | ||
justify-content: space-between; | ||
height: 100vh; | ||
`} | ||
> | ||
<BlogTab | ||
selectedTab={selectedTab} | ||
setSelectedTab={setSelectedTab} | ||
|
@@ -48,16 +57,30 @@ 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 ? ( | ||
<BlogPostSkeletonUI /> | ||
) : ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이전에 코멘트 드렸던 대로 이 부분은 항상 삼항 연산자 밖에 있어도 괜찮을 것 같아요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이번에 작업하면서 다시 안으로 들어갔나봐요....😂 다시 조건문 고민해볼게요!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @SeojinSeojin 서진 ~ 이부분 코멘트 좀 더 자세히 해줄 수 있을까요?
여기서 BlogPostList를 선택적을 띄울 필요가 없는 것은 이해하겠는데, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이전에는 문구가 blogPostList 컴포넌트 아래에 있었는데, 그것의 부모 컴포넌트인 이곳으로 오면 좋겠다는 뜻이었어요..!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아,..! 저렇게 두어도 좋겠다는 뜻이었구뇨! 이해했습니다 !! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 혹시 이 부분 의도하신 흐름에 대해서 말로 풀어서 설명해주실 수 있나요? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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>
)}
</>
)}
</>
)} 이렇게 수정하였습니다! |
||
<> | ||
{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> | ||
)} | ||
</> | ||
)} | ||
</> | ||
)} | ||
</PageLayout> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,18 @@ | ||
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.BlogPostListWrapper> | ||
<S.BlogPostList> | ||
{blogPostList?.map((blogPost) => ( | ||
<BlogPost key={blogPost.id} blogPost={blogPost} selectedTap={selectedTap} /> | ||
))} | ||
</S.BlogPostList> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기 있는거 타입으로 빼면 어떤가요??
BlogPostType을 제너릭 인자로 받아오는 .. 그런 베이스 타입을 선언해두면 나중에 두고두고 쓰기 좋을 것 같아요!!