Skip to content

Commit

Permalink
[Brave News]: Refresh stale tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
fallaciousreasoning committed Sep 11, 2024
1 parent 33ed755 commit 00e447e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions components/brave_news/browser/resources/shared/useFeedV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,22 @@ export const useFeedV2 = (enabled: boolean) => {
fetchFeed(feedView).then(setFeedV2)
}, [feedView])

// When we switch back to this tab, if the feed is stale refresh it.
useEffect(() => {
const handler = () => {
if (document.visibilityState !== 'visible') return

if (feedV2 && isTooOld(feedV2)) {
refresh()
}
}

document.addEventListener('visibilitychange', handler)
return () => {
document.removeEventListener('visibilitychange', handler)
}
}, [refresh, feedV2])

// Updates are available if we've been told the latest hash, we have a feed
// and the hashes don't match.
const updatesAvailable = !!(hash && feedV2 && hash !== feedV2.sourceHash)
Expand Down

0 comments on commit 00e447e

Please sign in to comment.