-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.tsx
55 lines (50 loc) · 1.57 KB
/
popup.tsx
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
import { useEffect, useState } from "react"
import { ChakraProvider, Box, VStack, Button, Text } from "@chakra-ui/react"
function IndexPopup() {
const [items, setItems] = useState([])
const [isPanelOpen, setIsPanelOpen] = useState(false);
useEffect(() => {
chrome.storage.local.get(['watchlist'], (result) => {
setItems(result.watchlist || [])
})
}, [])
const openSidePanel = async () => {
try {
const [tab] = await chrome.tabs.query({ active: true, lastFocusedWindow: true });
if (tab) {
if (isPanelOpen) {
// chrome.sidePanel.open();
// await chrome.sidePanel.setOptions({
// tabId: tab.id,
// // path: 'sidepanel-tab.html',
// enabled: false
// });
} else {
// await chrome.sidePanel.setOptions({
// tabId: tab.id,
// // path: 'sidepanel-tab.html',
// enabled: true
// });
chrome.sidePanel.open({ tabId: tab.id } as chrome.sidePanel.OpenOptions);
}
setIsPanelOpen(!isPanelOpen);
}
} catch (error) {
console.error("Error toggling side panel:", error);
}
};
return (
<ChakraProvider>
<Box p={4} width="300px">
<VStack spacing={4}>
<Text fontSize="xl" fontWeight="bold">GMGN Helper</Text>
<Button colorScheme="blue" onClick={openSidePanel} width="100%">
Open Side Panel
</Button>
<Text>Watching {items.length} items</Text>
</VStack>
</Box>
</ChakraProvider>
)
}
export default IndexPopup