-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(home): 홈 페이지의 인기 아티클 태그 목록 실제 데이터를 조회 후 연동하도록 합니다. #112
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
345679d
feat(home): 홈 페이지에 필요한 '인기 아티클 태그 목록 조회'를 위한 서비스 작성
innocarpe 0a8f578
refactor(home): 기존 아티클 데이터 useQuery 로직에서 좀 더 정확한 네이밍을 쓰도록 리팩토링
innocarpe 70b948d
feat(home): 인기 아티클 태그 목록을 조회하는 useQuery 작성
innocarpe 57f1057
feat(home): 홈 화면에서 실제 인기 아티클 태그 목록을 조회해 렌더링하도록 함
innocarpe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 PR 부터 두 개의 useQuery 를 사용하게 되어서, 네이밍을 좀 더 구체화하는게 가독성을 높힐 수 있다고 생각했습니다.