Skip to content

Commit 70018e6

Browse files
feat: article detail 조회 useMutation으로 변경
1 parent 87fe134 commit 70018e6

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

apps/client/src/pages/myBookmark/MyBookmark.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { useAnchoredMenu } from '@shared/hooks/useAnchoredMenu';
1313
import { belowOf } from '@shared/utils/anchorPosition';
1414
import NoArticles from '@pages/myBookmark/components/NoArticles/NoArticles';
1515
import { Icon } from '@pinback/design-system/icons';
16+
import { useGetArticleDetail } from '@shared/apis/queries';
1617

1718
const MyBookmark = () => {
1819
const [activeBadge, setActiveBadge] = useState<'all' | 'notRead'>('all');
@@ -39,12 +40,14 @@ const MyBookmark = () => {
3940
1,
4041
10
4142
);
43+
const { mutate: getArticleDetail, data: articleDetail } =
44+
useGetArticleDetail();
4245

4346
const articlesToDisplay =
4447
activeBadge === 'all' ? articles?.articles : unreadArticles?.articles;
4548

4649
// 임시 콘솔
47-
console.log('categoryArticles', categoryArticles);
50+
// console.log('categoryArticles', categoryArticles);
4851

4952
const handleBadgeClick = (badgeType: 'all' | 'notRead') => {
5053
setActiveBadge(badgeType);
@@ -110,7 +113,8 @@ const MyBookmark = () => {
110113
containerRef={containerRef}
111114
categoryId={menu.categoryId}
112115
getCategoryName={getBookmarkTitle}
113-
onEdit={() => {
116+
onEdit={(id) => {
117+
getArticleDetail(id);
114118
setIsEditOpen(true);
115119
closeMenu();
116120
}}
@@ -128,7 +132,10 @@ const MyBookmark = () => {
128132
onClick={() => setIsEditOpen(false)}
129133
/>
130134
<div className="absolute inset-0 flex items-center justify-center p-4">
131-
<CardEditModal onClose={() => setIsEditOpen(false)} />
135+
<CardEditModal
136+
onClose={() => setIsEditOpen(false)}
137+
// data={articleDetail}
138+
/>
132139
</div>
133140
</div>
134141
)}

apps/client/src/pages/remind/Remind.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { useGetRemindArticles } from '@pages/remind/apis/queries';
99
import { formatLocalDateTime } from '@shared/utils/formatDateTime';
1010
import NoReadArticles from '@pages/remind/components/noReadArticles/NoReadArticles';
1111
import NoUnreadArticles from '@pages/remind/components/noUnreadArticles/NoUnreadArticles';
12+
import { useGetArticleDetail } from '@shared/apis/queries';
1213

1314
const Remind = () => {
1415
const [isEditOpen, setIsEditOpen] = useState(false);
@@ -32,6 +33,7 @@ const Remind = () => {
3233
1,
3334
10
3435
);
36+
const { mutate: getArticleDetail } = useGetArticleDetail();
3537

3638
const handleBadgeClick = (badgeType: 'read' | 'notRead') => {
3739
setActiveBadge(badgeType);
@@ -85,7 +87,8 @@ const Remind = () => {
8587
containerRef={containerRef}
8688
categoryId={menu.categoryId}
8789
getCategoryName={getItemTitle}
88-
onEdit={() => {
90+
onEdit={(id) => {
91+
getArticleDetail(id);
8992
setIsEditOpen(true);
9093
closeMenu();
9194
}}

apps/client/src/shared/apis/queries.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { useMutation, useQuery, UseQueryResult } from '@tanstack/react-query';
1+
import {
2+
useMutation,
3+
UseMutationResult,
4+
useQuery,
5+
UseQueryResult,
6+
} from '@tanstack/react-query';
27
import {
38
getDashboardCategories,
49
postCategory,
@@ -64,13 +69,13 @@ export const usePostSignUp = () => {
6469
});
6570
};
6671

67-
export const useGetArticleDetail = (
68-
articleId: number
69-
): UseQueryResult<ArticleDetailResponse, AxiosError> => {
70-
return useQuery({
71-
queryKey: ['articleDetail', articleId],
72-
queryFn: () => getArticleDetail(articleId),
73-
enabled: !!articleId,
72+
export const useGetArticleDetail = (): UseMutationResult<
73+
ArticleDetailResponse,
74+
AxiosError,
75+
number
76+
> => {
77+
return useMutation({
78+
mutationFn: (articleId: number) => getArticleDetail(articleId),
7479
});
7580
};
7681

0 commit comments

Comments
 (0)