-
Notifications
You must be signed in to change notification settings - Fork 1
Api(client): 아티클 수정 API 연결 #97
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
Changes from all commits
347258f
47d4fdc
00bb250
05c7db6
dca2f4d
d737e8c
01a4e6c
8351962
847c1ed
7b27f46
59788ff
2fbeeec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,10 @@ import { useGetRemindArticles } from '@pages/remind/apis/queries'; | |
| import { formatLocalDateTime } from '@shared/utils/formatDateTime'; | ||
| import NoReadArticles from '@pages/remind/components/noReadArticles/NoReadArticles'; | ||
| import NoUnreadArticles from '@pages/remind/components/noUnreadArticles/NoUnreadArticles'; | ||
| import { usePutArticleReadStatus } from '@shared/apis/queries'; | ||
| import { | ||
| usePutArticleReadStatus, | ||
| useGetArticleDetail, | ||
| } from '@shared/apis/queries'; | ||
| import { useQueryClient } from '@tanstack/react-query'; | ||
|
|
||
| const Remind = () => { | ||
|
|
@@ -37,6 +40,8 @@ const Remind = () => { | |
|
|
||
| const getItemTitle = (id: number | null) => | ||
| id == null ? '' : (REMIND_MOCK_DATA.find((d) => d.id === id)?.title ?? ''); | ||
| const { mutate: getArticleDetail, data: articleDetail } = | ||
| useGetArticleDetail(); | ||
|
|
||
| const handleBadgeClick = (badgeType: 'read' | 'notRead') => { | ||
| setActiveBadge(badgeType); | ||
|
|
@@ -104,7 +109,8 @@ const Remind = () => { | |
| containerRef={containerRef} | ||
| categoryId={menu.categoryId} | ||
| getCategoryName={getItemTitle} | ||
| onEdit={() => { | ||
| onEdit={(id) => { | ||
| getArticleDetail(id); | ||
| setIsEditOpen(true); | ||
|
Comment on lines
+112
to
114
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. onEdit에 넘어오는 id가 articleId가 아닐 가능성 높음 (현재 categoryId를 전달 중) → 잘못된 상세 조회 호출 위험 위쪽 카드 옵션 클릭에서
onEdit={(id) => {
- getArticleDetail(id);
- setIsEditOpen(true);
+ getArticleDetail(id, {
+ onSuccess: () => setIsEditOpen(true),
+ onError: (e) => console.error('failed to load article detail', e),
+ });
closeMenu();
}}
// 현재
onOptionsClick={(e) => openMenu(article.category.categoryId, e.currentTarget)}
// 수정
onOptionsClick={(e) => openMenu(article.articleId, e.currentTarget)}🤖 Prompt for AI Agents |
||
| closeMenu(); | ||
| }} | ||
|
|
@@ -122,7 +128,10 @@ const Remind = () => { | |
| onClick={() => setIsEditOpen(false)} | ||
| /> | ||
| <div className="absolute inset-0 flex items-center justify-center p-4"> | ||
| <CardEditModal onClose={() => setIsEditOpen(false)} /> | ||
| <CardEditModal | ||
| onClose={() => setIsEditOpen(false)} | ||
| prevData={articleDetail} | ||
| /> | ||
| </div> | ||
| </div> | ||
| )} | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,15 +10,19 @@ import { | |||||||||||||||||||||||||||||||||||||||||||||||
| postCategory, | ||||||||||||||||||||||||||||||||||||||||||||||||
| postSignUp, | ||||||||||||||||||||||||||||||||||||||||||||||||
| postSignUpRequest, | ||||||||||||||||||||||||||||||||||||||||||||||||
| putEditArticle, | ||||||||||||||||||||||||||||||||||||||||||||||||
| putCategory, | ||||||||||||||||||||||||||||||||||||||||||||||||
| getAcorns, | ||||||||||||||||||||||||||||||||||||||||||||||||
| putArticleReadStatus, | ||||||||||||||||||||||||||||||||||||||||||||||||
| getArticleDetail, | ||||||||||||||||||||||||||||||||||||||||||||||||
| getAcorns, | ||||||||||||||||||||||||||||||||||||||||||||||||
| } from '@shared/apis/axios'; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import { AxiosError } from 'axios'; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||||||
| DashboardCategoriesResponse, | ||||||||||||||||||||||||||||||||||||||||||||||||
| AcornsResponse, | ||||||||||||||||||||||||||||||||||||||||||||||||
| EditArticleRequest, | ||||||||||||||||||||||||||||||||||||||||||||||||
| ArticleReadStatusResponse, | ||||||||||||||||||||||||||||||||||||||||||||||||
| ArticleDetailResponse, | ||||||||||||||||||||||||||||||||||||||||||||||||
| } from '@shared/types/api'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| export const useGetDashboardCategories = (): UseQueryResult< | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -83,3 +87,25 @@ export const usePutArticleReadStatus = (): UseMutationResult< | |||||||||||||||||||||||||||||||||||||||||||||||
| mutationFn: (articleId: number) => putArticleReadStatus(articleId), | ||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| export const useGetArticleDetail = (): UseMutationResult< | ||||||||||||||||||||||||||||||||||||||||||||||||
| ArticleDetailResponse, | ||||||||||||||||||||||||||||||||||||||||||||||||
| AxiosError, | ||||||||||||||||||||||||||||||||||||||||||||||||
| number | ||||||||||||||||||||||||||||||||||||||||||||||||
| > => { | ||||||||||||||||||||||||||||||||||||||||||||||||
| return useMutation({ | ||||||||||||||||||||||||||||||||||||||||||||||||
| mutationFn: (articleId: number) => getArticleDetail(articleId), | ||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| export const usePutEditArticle = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||
| return useMutation({ | ||||||||||||||||||||||||||||||||||||||||||||||||
| mutationFn: ({ | ||||||||||||||||||||||||||||||||||||||||||||||||
| articleId, | ||||||||||||||||||||||||||||||||||||||||||||||||
| editArticleData, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }: { | ||||||||||||||||||||||||||||||||||||||||||||||||
| articleId: number; | ||||||||||||||||||||||||||||||||||||||||||||||||
| editArticleData: EditArticleRequest; | ||||||||||||||||||||||||||||||||||||||||||||||||
| }) => putEditArticle(articleId, editArticleData), | ||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+101
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 수정 API 훅: 반환값 정규화(.data) 및 후처리 콜백 권장 호출부에서 항상 export const usePutEditArticle = () => {
return useMutation({
- mutationFn: ({
+ mutationFn: ({
articleId,
editArticleData,
}: {
articleId: number;
editArticleData: EditArticleRequest;
- }) => putEditArticle(articleId, editArticleData),
+ }) =>
+ putEditArticle(articleId, editArticleData).then((res) => res.data),
});
};원하시면 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||
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.
🛠️ Refactor suggestion
쿼리 키에 readStatus 파라미터 추가 권장
readStatus파라미터가 함수 시그니처에 추가되었지만, 쿼리 키에는 반영되지 않았습니다. 이로 인해readStatus가 변경되어도 캐시가 무효화되지 않을 수 있습니다.다음과 같이 수정을 권장합니다:
export const useGetCategoryBookmarkArticles = ( categoryId: string | null, readStatus: boolean, page: number, size: number ): UseQueryResult<CategoryBookmarkArticleResponse, AxiosError> => { return useQuery({ - queryKey: ['categoryBookmarkArticles', categoryId, page, size], + queryKey: ['categoryBookmarkArticles', categoryId, readStatus, page, size], queryFn: () => getCategoryBookmarkArticles(categoryId, readStatus, page, size), enabled: !!categoryId, }); };📝 Committable suggestion
🤖 Prompt for AI Agents