Skip to content

Commit

Permalink
Merge pull request #69 from sensasi-delight:sensasi-delight/issue67
Browse files Browse the repository at this point in the history
[TabsBar] list is not updated when opening new tab
  • Loading branch information
sensasi-delight authored May 2, 2024
2 parents b2a365c + 7a867dd commit 26a8a19
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/components/Navbar/TabsBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ export default function TabsBar(): React.ReactElement {
const [tabs, setTabs] = useState<chrome.tabs.Tab[]>([])
const [thisTabId, setThisTabId] = useState<number>()

function getAndSetTabs(): void {
sendToBgScript('getTabs', undefined, (response: chrome.tabs.Tab[]) => {
setTabs(response)
})
}

useEffect(() => {
sendToBgScript(
'getSelfInfo',
Expand All @@ -24,21 +30,11 @@ export default function TabsBar(): React.ReactElement {
setThisTabId(response.tab?.id)
},
)
}, [])

function getAndSetTabs(): void {
sendToBgScript('getTabs', undefined, (response: chrome.tabs.Tab[]) => {
setTabs(response)
})
}

useEffect(() => {
getAndSetTabs()

document.addEventListener('visibilitychange', getAndSetTabs)

return () => {
document.removeEventListener('visibilitychange', getAndSetTabs)
}
}, [])
})

return (
<Stack
Expand Down

0 comments on commit 26a8a19

Please sign in to comment.