Skip to content

Commit

Permalink
refactor: react-query 적용 (professor)
Browse files Browse the repository at this point in the history
  • Loading branch information
SunwooJaeho committed Dec 16, 2024
1 parent 2431352 commit 3b2025d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 28 deletions.
11 changes: 11 additions & 0 deletions apps/community/src/apis/member/professor/professor-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { MOCK_END_POINT } from '~/constants/api';
import type { Professor } from '~/types/professor';
import { http } from '~/utils/http';

class ProfessorService {
getProfessors() {
return http.get<Professor[]>(MOCK_END_POINT.PROFESSORS);
}
}

export default new ProfessorService();
14 changes: 14 additions & 0 deletions apps/community/src/apis/member/professor/queries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import ProfessorService from './professor-service';

const queryKeys = {
all: ['contacts'] as const,
};

const professorQueryOptions = {
all: () => ({
queryKey: queryKeys.all,
queryFn: () => ProfessorService.getProfessors(),
}),
};

export { professorQueryOptions };
27 changes: 16 additions & 11 deletions apps/community/src/app/member/professor/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { Metadata } from 'next';

import { professorQueryOptions } from '~/apis/member/professor/queries';
import { Hydrate, getDehydratedQuery } from '~/utils/react-query';

import { ProfessorCard } from '~/components/member/professor/professor-card';
import { PageHeader } from '~/components/page-header';

import { getProfessors } from './remote';

import * as styles from '~/app/member/professor/page.css';

export const metadata: Metadata = {
Expand All @@ -16,7 +17,9 @@ export const metadata: Metadata = {
export const dynamic = 'force-dynamic';

export default async function ProfessorPage() {
const { data } = await getProfessors();
const { queryKey, queryFn } = professorQueryOptions.all();
const query = await getDehydratedQuery({ queryKey, queryFn });
const { data } = query.state.data ?? {};

return (
<section>
Expand All @@ -25,14 +28,16 @@ export default async function ProfessorPage() {
description="경기대학교 AI컴퓨터공학부의 교수진을 소개해요"
/>

<div className={styles.professorListWrapper}>
{data.map((professor) => (
<ProfessorCard
key={`professor-${professor.id}`}
professor={professor}
/>
))}
</div>
<Hydrate state={{ query }}>
<div className={styles.professorListWrapper}>
{data?.map((professor) => (
<ProfessorCard
key={`professor-${professor.id}`}
professor={professor}
/>
))}
</div>
</Hydrate>
</section>
);
}
17 changes: 0 additions & 17 deletions apps/community/src/app/member/professor/remote.ts

This file was deleted.

10 changes: 10 additions & 0 deletions apps/community/src/types/professor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
interface Professor {
id: number;
name: string;
img?: string;
type: string;
contact: string;
email: string;
}

export type { Professor };

0 comments on commit 3b2025d

Please sign in to comment.