Skip to content

Commit

Permalink
feat: profile follower, following list 마크업 및 데이터 연동
Browse files Browse the repository at this point in the history
  • Loading branch information
Jungjjeong committed Aug 27, 2024
1 parent 5250ae2 commit 387fd9c
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
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) {
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';

0 comments on commit 387fd9c

Please sign in to comment.