-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from School-of-Company/refector/api
🔀 1차 api 변경 (tanstack query로 변경)
- Loading branch information
Showing
15 changed files
with
383 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from 'react'; | ||
import { Loading } from '../ui'; | ||
|
||
type WithLoadingProps = { | ||
isLoading: boolean; | ||
children: React.ReactNode; | ||
}; | ||
|
||
const withLoading = ({ isLoading, children }: WithLoadingProps) => { | ||
if (isLoading) return <Loading />; | ||
return <>{children}</>; | ||
}; | ||
|
||
export default withLoading; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export interface ExpoDetail { | ||
title: string; | ||
description: string; | ||
startedDay: string; | ||
finishedDay: string; | ||
location: string; | ||
coverImage: string; | ||
x: number; | ||
y: number; | ||
} | ||
|
||
export interface ExpoTrainingDetail { | ||
title: string; | ||
startedAt: string; | ||
endedAt: string; | ||
category: 'ESSENTIAL' | 'CHOICE'; | ||
} | ||
|
||
export interface ExpoTraining { | ||
essential: ExpoTrainingDetail[]; | ||
choice: ExpoTrainingDetail[]; | ||
} | ||
|
||
export interface ExpoStandard { | ||
title: string; | ||
startedAt: string; | ||
endedAt: string; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import axios from 'axios'; | ||
import { | ||
ExpoDetail, | ||
ExpoStandard, | ||
ExpoTrainingDetail, | ||
} from '@/shared/types/expo-detail/type'; | ||
|
||
export const getExpoDetail = async (id: number): Promise<ExpoDetail> => { | ||
const response = await axios.get(`/api/expo/${id}`); | ||
return response.data; | ||
}; | ||
|
||
export const getExpoStandard = async (id: number): Promise<ExpoStandard[]> => { | ||
const response = await axios.get(`/api/standard/program/${id}`); | ||
return response.data; | ||
}; | ||
|
||
export const getExpoTraining = async ( | ||
id: number, | ||
): Promise<ExpoTrainingDetail[]> => { | ||
const response = await axios.get(`/api/training/program/${id}`); | ||
return response.data; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { | ||
ExpoDetail, | ||
ExpoStandard, | ||
ExpoTrainingDetail, | ||
} from '@/shared/types/expo-detail/type'; | ||
import { | ||
getExpoDetail, | ||
getExpoStandard, | ||
getExpoTraining, | ||
} from '../api/getExpoDetail'; | ||
|
||
interface ExpoTraining { | ||
essential: ExpoTrainingDetail[]; | ||
choice: ExpoTrainingDetail[]; | ||
} | ||
|
||
export const useExpoQueries = (id: number) => { | ||
const expoDetailQuery = useQuery<ExpoDetail, Error>({ | ||
queryKey: ['expoDetail', id], | ||
queryFn: () => getExpoDetail(id), | ||
}); | ||
|
||
const expoStandardQuery = useQuery<ExpoStandard[], Error>({ | ||
queryKey: ['expoStandard', id], | ||
queryFn: () => getExpoStandard(id), | ||
}); | ||
|
||
const expoTrainingQuery = useQuery<ExpoTrainingDetail[], Error, ExpoTraining>( | ||
{ | ||
queryKey: ['expoTraining', id], | ||
queryFn: () => getExpoTraining(id), | ||
select: (data) => ({ | ||
essential: data.filter((item) => item.category === 'ESSENTIAL'), | ||
choice: data.filter((item) => item.category === 'CHOICE'), | ||
}), | ||
}, | ||
); | ||
|
||
const isLoading = | ||
expoDetailQuery.isLoading || | ||
expoStandardQuery.isLoading || | ||
expoTrainingQuery.isLoading; | ||
|
||
return { expoDetailQuery, expoStandardQuery, expoTrainingQuery, isLoading }; | ||
}; |
Oops, something went wrong.