Skip to content

Commit

Permalink
Merge pull request #3234 from tloncorp/hm/only-pop-update-banner-once
Browse files Browse the repository at this point in the history
updates: prevent update banner from showing multiple times
  • Loading branch information
latter-bolden authored Feb 9, 2024
2 parents e332602 + 817e09a commit 638c836
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions ui/src/logic/useAppUpdates.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createContext, useCallback, useState, useEffect } from 'react';
import { useRegisterSW } from 'virtual:pwa-register/react';
import useKilnState, { usePike } from '@/state/kiln';
import { createContext, useCallback, useEffect, useState } from 'react';
import { useRegisterSW } from 'virtual:pwa-register/react';

const CHECK_FOR_UPDATES_INTERVAL = 10 * 60 * 1000; // 10 minutes

Expand Down Expand Up @@ -56,13 +56,17 @@ export default function useAppUpdates() {
return () => clearInterval(interval);
}, []);

if (pike) {
if (!initialHash) {
setInitialHash(pike.hash);
} else if (initialHash !== pike.hash && !needsUpdate) {
setNeedsUpdate(true);
useEffect(() => {
if (pike) {
if (!initialHash) {
setInitialHash(pike.hash);
} else if (initialHash !== pike.hash && !needsUpdate) {
// wait 5 minutes before showing the update prompt in case there
// are multiple updates in quick succession
setTimeout(() => setNeedsUpdate(true), 5 * 60 * 1000);
}
}
}
}, [pike, initialHash, needsUpdate]);

const triggerUpdate = useCallback(
async (returnToRoot: boolean) => {
Expand All @@ -84,7 +88,7 @@ export default function useAppUpdates() {
);

return {
needsUpdate: needsUpdate || needRefresh,
needsUpdate: needRefresh,
triggerUpdate,
};
}
Expand Down

0 comments on commit 638c836

Please sign in to comment.