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: follower, following list 마크업 및 데이터 연동 #251

Merged
merged 6 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
36 changes: 36 additions & 0 deletions features/follow/components/follow-virtual-list.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react';
import { Virtuoso } from 'react-virtuoso';

import { ProfileListItem } from '@/components/molecules';

import { ProfileFollowContent } from '../types';

type FollowVirtualList = {
data: ProfileFollowContent[];
fetchNextData: () => void;
};
export const FollowVirtualList = ({
data,
fetchNextData,
}: FollowVirtualList) => {
const handleRangeChanged = (range: { endIndex: number }) => {
const currentContentsLastIndex = data.length - 1;
if (range.endIndex >= currentContentsLastIndex - 3) {
Copy link
Collaborator

@summermong summermong Aug 27, 2024

Choose a reason for hiding this comment

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

근데 왜 이거 -3 까지예요? (궁 금 궁 금)

Copy link
Member Author

Choose a reason for hiding this comment

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

그냥 제가 정한 기준이긴 해요
뷰포트 기준으로 overscan 500px + end index 3개 전에 다음 데이터 불러오는 조건입니다!

void fetchNextData();
}
};

return (
<Virtuoso
data={data}
overscan={300}
useWindowScroll
rangeChanged={handleRangeChanged}
itemContent={(_, item) => <ProfileListItem isFollow={true} {...item} />}
style={{
width: '100%',
height: '100%',
}}
/>
);
};
1 change: 1 addition & 0 deletions features/follow/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './follow-virtual-list';
17 changes: 17 additions & 0 deletions features/follow/sections/follower-section.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use client';

import { useFollowerList } from '../apis';
import { FollowVirtualList } from '../components';

export const FollowerSection = ({ id }: { id: number }) => {
const { flattenData, hasNextPage, isFetchingNextPage, fetchNextPage } =
useFollowerList(id);

const fetchNextData = () => {
if (hasNextPage && !isFetchingNextPage) {
void fetchNextPage();
}
};

return <FollowVirtualList data={flattenData} fetchNextData={fetchNextData} />;
};
17 changes: 17 additions & 0 deletions features/follow/sections/following-section.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use client';

import { useFollowingList } from '../apis';
import { FollowVirtualList } from '../components';

export const FollowingSection = ({ id }: { id: number }) => {
const { flattenData, hasNextPage, isFetchingNextPage, fetchNextPage } =
useFollowingList(id);

const fetchNextData = () => {
if (hasNextPage && !isFetchingNextPage) {
void fetchNextPage();
}
};

return <FollowVirtualList data={flattenData} fetchNextData={fetchNextData} />;
};
2 changes: 2 additions & 0 deletions features/follow/sections/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from './follow-tab';
export * from './follower-section';
export * from './following-section';
Loading