-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.tsx
More file actions
59 lines (51 loc) · 1.58 KB
/
App.tsx
File metadata and controls
59 lines (51 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { useGetArticleDetail, useGetArticleSaved } from '@apis/query/queries';
import { useEffect, useState } from 'react';
import './App.css';
import { usePageMeta } from './hooks/usePageMeta';
import DuplicatePop from './pages/DuplicatePop';
import LogOutPop from './pages/LogOutPop';
import MainPop from './pages/MainPop';
const App = () => {
const { url } = usePageMeta();
const { data: savedArticle } = useGetArticleSaved(url);
const articleId = savedArticle?.data?.id;
const { data: articleDetail } = useGetArticleDetail(articleId!);
const [isDuplicatePop, setIsDuplicatePop] = useState(false);
const [mainPopType, setMainPopType] = useState<'add' | 'edit'>('add');
const [isToken, setIsToken] = useState(false);
useEffect(() => {
chrome.storage.local.get('token', (result) => {
setIsToken(!!result.token);
});
}, []);
// 이미 저장된 아티클이면 DuplicatePop 표시
useEffect(() => {
if (savedArticle?.data) {
setIsDuplicatePop(true);
}
}, [savedArticle]);
const handleDuplicateLeftClick = () => {
setIsDuplicatePop(false);
setMainPopType('edit');
};
const handleDuplicateRightClick = () => {
chrome.tabs.create({ url: 'https://pinback.today/' });
};
return (
<>
{isToken ? (
isDuplicatePop ? (
<DuplicatePop
onLeftClick={handleDuplicateLeftClick}
onRightClick={handleDuplicateRightClick}
/>
) : (
<MainPop type={mainPopType} savedData={articleDetail} />
)
) : (
<LogOutPop />
)}
</>
);
};
export default App;