Skip to content

Commit 67f79b1

Browse files
authored
Fix(estension): extension api v3 update및 edit error 해결 (#302)
* Feat: check_circle 및 notsave_circle 아이콘 추가 * Feat: Toast 컴포넌트에 아이콘 추가 및 props 수정 * Feat: 아티클 상세 조회 기능 추가 및 MainPop 컴포넌트 수정 * chore: console.log 제거 * chore: 주석제거 * Feat: MainPop에서 아티클 저장 후 토스트 반영후에 창 닫기 기능 추가 * feat: 위치 디테일 수정
1 parent c1518e0 commit 67f79b1

File tree

9 files changed

+61
-25
lines changed

9 files changed

+61
-25
lines changed

apps/extension/src/App.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
import { useGetArticleDetail, useGetArticleSaved } from '@apis/query/queries';
2+
import { useEffect, useState } from 'react';
13
import './App.css';
2-
import DuplicatePop from './pages/DuplicatePop';
3-
import MainPop from './pages/MainPop';
4-
import { useState, useEffect } from 'react';
5-
import { useGetArticleSaved } from '@apis/query/queries';
64
import { usePageMeta } from './hooks/usePageMeta';
5+
import DuplicatePop from './pages/DuplicatePop';
76
import LogOutPop from './pages/LogOutPop';
7+
import MainPop from './pages/MainPop';
8+
89
const App = () => {
910
const { url } = usePageMeta();
10-
const { data: isSaved } = useGetArticleSaved(url);
11+
const { data: savedArticle } = useGetArticleSaved(url);
12+
const articleId = savedArticle?.data?.id;
13+
const { data: articleDetail } = useGetArticleDetail(articleId!);
1114

1215
const [isDuplicatePop, setIsDuplicatePop] = useState(false);
1316
const [mainPopType, setMainPopType] = useState<'add' | 'edit'>('add');
@@ -18,11 +21,13 @@ const App = () => {
1821
setIsToken(!!result.token);
1922
});
2023
}, []);
24+
25+
// 이미 저장된 아티클이면 DuplicatePop 표시
2126
useEffect(() => {
22-
if (isSaved?.data) {
27+
if (savedArticle?.data) {
2328
setIsDuplicatePop(true);
2429
}
25-
}, [isSaved]);
30+
}, [savedArticle]);
2631

2732
const handleDuplicateLeftClick = () => {
2833
setIsDuplicatePop(false);
@@ -42,7 +47,7 @@ const App = () => {
4247
onRightClick={handleDuplicateRightClick}
4348
/>
4449
) : (
45-
<MainPop type={mainPopType} />
50+
<MainPop type={mainPopType} savedData={articleDetail} />
4651
)
4752
) : (
4853
<LogOutPop />

apps/extension/src/apis/axios.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ export const putArticle = async (
6565
articleId: number,
6666
data: PutArticleRequest
6767
) => {
68-
const response = await apiRequest.put(`/api/v1/articles/${articleId}`, data);
69-
return response.data;
68+
const response = await apiRequest.put(`/api/v1/articles/${articleId}`, {
69+
...data,
70+
});
71+
return response;
72+
};
73+
74+
export const getArticleDetail = async (articleId: number) => {
75+
const response = await apiRequest.get(`/api/v3/articles/${articleId}`);
76+
return response.data.data;
7077
};

apps/extension/src/apis/query/queries.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
getArticleDetail,
23
getArticleSaved,
34
getCategoriesExtension,
45
getRemindTime,
@@ -61,3 +62,11 @@ export const usePutArticle = () => {
6162
}) => putArticle(articleId, data),
6263
});
6364
};
65+
66+
export const useGetArticleDetail = (articleId?: number) => {
67+
return useQuery({
68+
queryKey: ['articleDetail', articleId],
69+
queryFn: () => getArticleDetail(articleId!),
70+
enabled: !!articleId,
71+
});
72+
};

apps/extension/src/pages/MainPop.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import thumbImg from '@assets/extension_thumb.svg';
88
import { useCategoryManager } from '@hooks/useCategoryManager';
99
import { usePageMeta } from '@hooks/usePageMeta';
1010
import { useSaveBookmark } from '@hooks/useSaveBookmarks';
11+
import { Icon } from '@pinback/design-system/icons';
1112
import {
1213
AutoDismissToast,
1314
Button,
@@ -111,7 +112,7 @@ const MainPop = ({ type, savedData }: MainPopProps) => {
111112
categoryData?.data?.categories?.length
112113
) {
113114
setMemo(savedData.memo ?? '');
114-
setIsArticleId(savedData.id ?? 0);
115+
setIsArticleId(savedData.articleId ?? 0);
115116

116117
if (savedData.remindAt) {
117118
const [rawDate, rawTime] = savedData.remindAt.split('T');
@@ -121,9 +122,10 @@ const MainPop = ({ type, savedData }: MainPopProps) => {
121122
} else {
122123
setIsRemindOn(false);
123124
}
125+
124126
if (savedData.categoryResponse) {
125-
setSelected(savedData.categoryResponse?.categoryId.toString());
126-
setSelectedCategoryName(savedData.categoryResponse?.categoryName);
127+
setSelected(savedData.categoryResponse.categoryId.toString());
128+
setSelectedCategoryName(savedData.categoryResponse.categoryName);
127129
}
128130
}
129131
}, [type, savedData, categoryData?.data?.categories?.length]);
@@ -243,7 +245,9 @@ const MainPop = ({ type, savedData }: MainPopProps) => {
243245
},
244246
{
245247
onSuccess: () => {
246-
window.close();
248+
setTimeout(() => {
249+
window.close();
250+
}, 2000);
247251
},
248252
}
249253
);
@@ -254,13 +258,15 @@ const MainPop = ({ type, savedData }: MainPopProps) => {
254258
<div className="App">
255259
<div className="relative flex h-[56.8rem] w-[31.2rem] items-center justify-center">
256260
{toastIsOpen && (
257-
<div className="absolute bottom-[5rem] left-1/2 -translate-x-1/2">
261+
<div className="absolute bottom-[8rem] left-1/2 -translate-x-1/2">
258262
<AutoDismissToast
259263
duration={1000}
260264
fadeMs={1000}
261265
onClose={() => setToastIsOpen(false)}
262266
>
263-
<Toast text={`수정내용을 저장했어요`} />
267+
<Toast text={`수정내용을 저장했어요`}>
268+
<Icon name="check_circle" size={20} />
269+
</Toast>
264270
</AutoDismissToast>
265271
</div>
266272
)}

apps/extension/src/types/types.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ export interface CategoryResponse {
66

77
export interface ArticleResponse {
88
id: number;
9+
articleId: number;
910
url: string;
1011
memo: string;
11-
remindAt: string | null;
12+
remindAt: string | null;
1213
categoryResponse: CategoryResponse;
13-
createdAt: string;
14+
createdAt: string;
1415
}
1516

1617
export interface Category {
17-
categoryId: number;
18-
categoryName: string;
19-
categoryColor:string;
20-
}
18+
categoryId: number;
19+
categoryName: string;
20+
categoryColor: string;
21+
}
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { cn } from '../../lib/utils';
22

33
export interface ToastProps {
4-
text: string;
4+
text?: string;
5+
children?: React.ReactNode;
56
}
67

7-
export default function Toast({ text }: ToastProps) {
8+
export default function Toast({ text, children }: ToastProps) {
89
return (
910
<div
1011
role="alert"
@@ -15,7 +16,10 @@ export default function Toast({ text }: ToastProps) {
1516
'common-shadow'
1617
)}
1718
>
18-
<p className="caption2-sb whitespace-pre-line">{text}</p>
19+
<div className="flex items-center gap-[0.4rem]">
20+
{children}
21+
{text && <p className="caption2-sb whitespace-nowrap">{text}</p>}
22+
</div>
1923
</div>
2024
);
2125
}

packages/design-system/src/icons/iconNames.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// 이 파일은 자동 생성 파일입니다. (직접 수정 금지)
22
export const iconNames = [
3+
'check_circle',
34
'chippi_profile',
45
'dotori',
56
'ext_home1',
@@ -28,6 +29,7 @@ export const iconNames = [
2829
'logout_chippi.2512',
2930
'main_header_logo',
3031
'main_logo',
32+
'notsave_circle',
3133
'palms',
3234
'saved',
3335
'tooltip_1',
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)