diff --git a/src/app/routes/Dashboard.tsx b/src/app/routes/Dashboard.tsx index d622fa0..e1ff5e1 100644 --- a/src/app/routes/Dashboard.tsx +++ b/src/app/routes/Dashboard.tsx @@ -227,7 +227,7 @@ export const Dashboard: React.FC = () => { } }; - const updateProfile = async () => { + const updateData = async () => { await updateManifest(); const destinyMembership = await getDestinyMembershipId(); dispatch(updateMembership(destinyMembership)); @@ -304,7 +304,7 @@ export const Dashboard: React.FC = () => { dispatch(updateLoadoutCharacter(profileCharacters[targetCharacterIndex])); }; - updateProfile().catch(console.error); + updateData().catch(console.error); }, []); const permutations = useMemo(() => { diff --git a/src/app/routes/Landing.tsx b/src/app/routes/Landing.tsx index ad1a289..3a10762 100644 --- a/src/app/routes/Landing.tsx +++ b/src/app/routes/Landing.tsx @@ -7,6 +7,7 @@ import { Container, Grid, Paper, Box, Typography } from '@mui/material'; import pyramidBackground from '/assets/pyramid.jpg'; import FeatureSlider from '../../components/FeatureSlider'; import { useScramble } from 'use-scramble'; +import { handleVersionUpdate } from '../../util/version-check'; export const LandingRoute: React.FC = () => { const navigate = useNavigate(); @@ -21,9 +22,12 @@ export const LandingRoute: React.FC = () => { }); useEffect(() => { + // version check + handleVersionUpdate(); // if navigated with share link, store the data before authenticating if (window.location.href.includes('d=')) localStorage.setItem('lastShared', window.location.href.split('d=')[1]); + setTimeout(async () => { if (isAuthenticated()) { console.log('Already authenticated'); diff --git a/src/lib/bungie_api/authorization.tsx b/src/lib/bungie_api/authorization.tsx index f90bdc1..643423f 100644 --- a/src/lib/bungie_api/authorization.tsx +++ b/src/lib/bungie_api/authorization.tsx @@ -2,6 +2,7 @@ import { Navigate } from 'react-router-dom'; import { isTokenExpired } from './token-services'; import { getTokens } from '../../store/TokensStore'; import { API_CREDENTIALS } from './constants'; +import { handleVersionUpdate } from '../../util/version-check'; /** * Navigates to the Bungie OAuth url @@ -31,6 +32,7 @@ export function isAuthenticated(): boolean { * Restricts rendering of children if not authenticated */ export const ProtectedRoute = ({ children }: { children: React.ReactNode }) => { + handleVersionUpdate(); if (!isAuthenticated()) { return ; } diff --git a/src/lib/bungie_api/manifest.ts b/src/lib/bungie_api/manifest.ts index e5496dd..9c6a50a 100644 --- a/src/lib/bungie_api/manifest.ts +++ b/src/lib/bungie_api/manifest.ts @@ -18,16 +18,8 @@ export async function updateManifest() { if (response.data.Response) { const currentVersion = localStorage.getItem('manifestVersion'); - if (!currentVersion || currentVersion !== response.data.Response.version) { - await db.manifestArmorDef.clear(); - await db.manifestArmorModDef.clear(); - await db.manifestArmorStatModDef.clear(); - await db.manifestEmblemDef.clear(); - await db.manifestExoticArmorCollection.clear(); - await db.manifestSubclass.clear(); - await db.manifestSubclassModDef.clear(); - await db.manifestSubclassFragmentsDef.clear(); - await db.manifestSubclassAspectsDef.clear(); + if (currentVersion === null || currentVersion !== response.data.Response.version) { + await db.delete({ disableAutoOpen: false }); localStorage.setItem('manifestVersion', response.data.Response.version); const itemInventoryComponent = diff --git a/src/util/version-check.ts b/src/util/version-check.ts new file mode 100644 index 0000000..654d74c --- /dev/null +++ b/src/util/version-check.ts @@ -0,0 +1,12 @@ +import packageJson from '../../package.json'; + +export function handleVersionUpdate() { + const storedVersion = localStorage.getItem('version'); + if (packageJson.version !== storedVersion || storedVersion === null) { + localStorage.clear(); + localStorage.setItem('version', packageJson.version); + console.log( + 'Cleared storage and updated to from version ' + storedVersion + ' to ' + packageJson.version + ); + } +}