Skip to content

Commit

Permalink
feat: 소식 페이지 헤더 API 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
hjy0951 committed Aug 28, 2024
1 parent 460a23a commit 27254da
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 37 deletions.
13 changes: 13 additions & 0 deletions app/api/friend/following/summary/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { NextResponse } from 'next/server';

import { fetchData } from '@/apis/fetch-data';
import { FollowingSummaryResponse } from '@/features/news';

export async function GET() {
const data = await fetchData<FollowingSummaryResponse>(
'/friend/following/summary',
'GET',
);

return NextResponse.json(data);
}
58 changes: 21 additions & 37 deletions features/news/components/atoms/following-list-link-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,22 @@ import { DefaultProfileIcon, Image, PersonsIcon } from '@/components/atoms';
import { css, cx } from '@/styled-system/css';
import { flex } from '@/styled-system/patterns';

interface FollowingInfo {
memberId: number;
name: string;
introduction: string;
profileUrl?: string;
}

const dummy: { followings: Array<FollowingInfo>; followingCount: number } = {
followings: [
{
memberId: 1,
name: '홍길동',
introduction: '안녕하세요. 홍길동입니다',
},
{
memberId: 2,
name: '홍길동',
introduction: '안녕하세요. 홍길동입니다',
},
{
memberId: 3,
name: '홍길동',
introduction: '안녕하세요. 홍길동입니다',
},
],
followingCount: 12,
};
import { useFollowingSummary } from '../../hooks';

const MAX_NUMBER_OF_PROFILES = 3;

export const FollowingListLinkButton = () => {
const { followings, followingCount } = dummy;
const { data: followingSummaryData } = useFollowingSummary();

if (!followingSummaryData) return null;

const { followings, followingCount } = followingSummaryData.data;
const hasFollowings = followingCount > 0;
const indexOffset = MAX_NUMBER_OF_PROFILES - followings.length;
let nodeList: Array<ReactNode> = [];

if (hasFollowings) {
nodeList = followings.map(({ memberId, profileUrl }, index) => (
nodeList = followings.map(({ memberId, profileImageUrl }, index) => (
<div
key={memberId}
className={cx(
Expand All @@ -51,8 +29,13 @@ export const FollowingListLinkButton = () => {
profileStyles[index + indexOffset],
)}
>
{profileUrl ? (
<Image src={profileUrl} alt="following profiles" />
{profileImageUrl ? (
<Image
src={profileImageUrl}
alt="following profiles"
width={24}
height={24}
/>
) : (
<DefaultProfileIcon width={24} height={24} />
)}
Expand Down Expand Up @@ -95,22 +78,23 @@ const borderStyles = css({
borderColor: 'white',
});

const baseProfileStyle = css({
const baseProfileStyle = flex({
position: 'absolute',
top: '2px',
borderRadius: 'full',
backgroundColor: 'white',
overflow: 'hidden',
});

const profileStyles = [
css({ right: '-96px' }),
css({ right: '-80px' }),
css({ right: '-64px' }),
css({ right: '-98px' }),
css({ right: '-82px' }),
css({ right: '-66px' }),
];

const countStyles = css({
w: '14px',
w: '16px',
h: '16px',
textAlign: 'center',
textStyle: 'caption1',
fontWeight: 'bold',
color: 'primary.swim.총거리.default',
Expand Down
1 change: 1 addition & 0 deletions features/news/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './use-following-summary';
export * from './use-news-data';
22 changes: 22 additions & 0 deletions features/news/hooks/use-following-summary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { keepPreviousData, useQuery } from '@tanstack/react-query';

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

const getFollowingSummary = async () => {
const res = await fetch('/api/friend/following/summary', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});

return res.json();
};

export const useFollowingSummary = () => {
return useQuery<FollowingSummaryResponse>({
queryKey: ['followingSummary'],
queryFn: () => getFollowingSummary(),
placeholderData: keepPreviousData,
});
};
8 changes: 8 additions & 0 deletions features/news/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Response } from '@/apis';
import { TimeLineContent } from '@/features/main';
import { MemberProfile } from '@/types';

import { NewsItemWrapperProps } from '../components';

Expand All @@ -11,3 +12,10 @@ export type NewsResponse = Response<{
cursorId: number;
hasNext: boolean;
}>;

export interface FolowingSummaryData {
followings: Array<MemberProfile>;
followingCount: number;
}

export type FollowingSummaryResponse = Response<FolowingSummaryData>;

0 comments on commit 27254da

Please sign in to comment.