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

feat: 당겨서 새로고침시 새롭게 소식 데이터를 불러오는 기능 추가 #254

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
14 changes: 9 additions & 5 deletions features/news/components/organisms/news-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,24 @@ import { NewsContent } from '../../types';
import { EmptyNews, NewsItemWrapper, NewsItemWrapperProps } from '../molecules';
import { FindMemberButton, FollowingListLinkButton } from '../atoms';
import { useNewsData } from '../../hooks';
import { useQueryClient } from '@tanstack/react-query';

export const NewsList = () => {
const ptrRef = useRef(null);
const queryClient = useQueryClient();
const { data: newsData, fetchNextPage, hasNextPage } = useNewsData();

if (!newsData) return null;

const contents = newsData.pages.flatMap(({ data }) => data.content);
let contents = newsData.pages.flatMap(({ data }) => data.content);
const isEmpty = contents.length === 0;
const lastItemIndex = contents.length - 1;

const handlePullToRefresh = () => {
queryClient.invalidateQueries({ queryKey: ['newsData'] });
queryClient.refetchQueries({ queryKey: ['newsData'], type: 'active' });
};

return isEmpty ? (
<section className={emptySectionStyle}>
<EmptyNews />
Expand All @@ -40,10 +47,7 @@ export const NewsList = () => {
</HeaderBar>

<div className={sectionStyle} ref={ptrRef}>
<PullToRefresh
ref={ptrRef}
onRefresh={() => console.log('refreshing')}
/>
<PullToRefresh ref={ptrRef} onRefresh={handlePullToRefresh} />
<InfiniteScroller
isLastPage={!hasNextPage}
onIntersect={() => fetchNextPage()}
Expand Down
Loading