Add React components and complete project structure for PlugSnatcher

This commit is contained in:
Rbanh committed 2025-04-01 00:09:51 -04:00
1 parent 340ce3d834
commit 61becf8d22
92 files changed
+8603 -1524

No files matched your search

+59
View File
@@ -0,0 +1,59 @@
import { useState, useCallback, useEffect } from 'react';
import { useUIContext } from '../context/UIContext/useUIContext';
import { checkForAppUpdate as checkForAppUpdateAPI, UpdateInfo } from '../utils/appUpdates';
/**
* Custom hook for managing application updates
*/
export const useAppUpdates = () => {
const [isCheckingAppUpdate, setIsCheckingAppUpdate] = useState<boolean>(false);
const [appUpdateAvailable, setAppUpdateAvailable] = useState<boolean>(false);
const [appUpdateVersion, setAppUpdateVersion] = useState<string | null>(null);
const { showUpdateAvailableMessage } = useUIContext();
// Check for application updates
const checkForAppUpdate = useCallback(async () => {
if (isCheckingAppUpdate) return;
setIsCheckingAppUpdate(true);
try {
console.log('Checking for application updates...');
const updateInfo: UpdateInfo = await checkForAppUpdateAPI();
setAppUpdateAvailable(updateInfo.available);
setAppUpdateVersion(updateInfo.version || null);
if (updateInfo.available && updateInfo.version) {
console.log(`Application update available: ${updateInfo.version}`);
showUpdateAvailableMessage(updateInfo.version);
} else {
console.log('No application updates available');
}
} catch (error) {
console.error('Error checking for app updates:', error);
} finally {
setIsCheckingAppUpdate(false);
}
}, [isCheckingAppUpdate, showUpdateAvailableMessage]);
// Auto-check for updates on initial load
useEffect(() => {
// Wait a moment after initial load before checking
const timer = setTimeout(() => {
checkForAppUpdate();
}, 2000);
return () => clearTimeout(timer);
}, [checkForAppUpdate]);
return {
isCheckingAppUpdate,
appUpdateAvailable,
appUpdateVersion,
checkForAppUpdate
};
};
export default useAppUpdates;