-
Notifications
You must be signed in to change notification settings - Fork 41
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 #112 from pagers-org/carpe/home-popular-tags
feat(home): 홈 페이지의 인기 아티클 태그 목록 실제 데이터를 조회 후 연동하도록 합니다.
- Loading branch information
Showing
5 changed files
with
58 additions
and
20 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
apps/react-world/src/apis/article/PopularArticleTagService.ts
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,19 @@ | ||
import { isAxiosError } from 'axios'; | ||
import { api } from '../apiInstances'; | ||
import type { PopularArticleTagsResponse } from './PopularArticleTagService.types'; | ||
|
||
class PopularArticleTagService { | ||
static async fetchPopularArticleTags(): Promise<PopularArticleTagsResponse> { | ||
try { | ||
const response = await api.get('/tags'); | ||
return response.data; | ||
} catch (error) { | ||
if (isAxiosError(error) && error.response) { | ||
throw error.response.data; | ||
} | ||
throw error; | ||
} | ||
} | ||
} | ||
|
||
export default PopularArticleTagService; |
3 changes: 3 additions & 0 deletions
3
apps/react-world/src/apis/article/PopularArticleTagService.types.ts
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,3 @@ | ||
export interface PopularArticleTagsResponse { | ||
tags: string[]; | ||
} |
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,18 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import PopularArticleTagService from '../apis/article/PopularArticleTagService'; | ||
|
||
export const POPULAR_ARTICLE_TAG_CACHE_KEY = '@article/popular_tags'; | ||
|
||
const usePopularArticleTagsQuery = () => { | ||
PopularArticleTagService; | ||
const queryResult = useQuery([POPULAR_ARTICLE_TAG_CACHE_KEY], () => | ||
PopularArticleTagService.fetchPopularArticleTags(), | ||
); | ||
|
||
return { | ||
popularArticleTags: queryResult.data, | ||
isPopularArticleTagsLoading: queryResult.isLoading, | ||
}; | ||
}; | ||
|
||
export default usePopularArticleTagsQuery; |