Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updates: prevent update banner from showing multiple times #3234

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading