Skip to content

Commit

Permalink
Added data refresh on version update. Bumped version.
Browse files Browse the repository at this point in the history
  • Loading branch information
dragoni7 committed Sep 15, 2024
1 parent 2f3e285 commit fa4eab3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/app/routes/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export const Dashboard: React.FC = () => {
}
};

const updateProfile = async () => {
const updateData = async () => {
await updateManifest();
const destinyMembership = await getDestinyMembershipId();
dispatch(updateMembership(destinyMembership));
Expand Down Expand Up @@ -304,7 +304,7 @@ export const Dashboard: React.FC = () => {
dispatch(updateLoadoutCharacter(profileCharacters[targetCharacterIndex]));
};

updateProfile().catch(console.error);
updateData().catch(console.error);
}, []);

const permutations = useMemo(() => {
Expand Down
4 changes: 4 additions & 0 deletions src/app/routes/Landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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');
Expand Down
2 changes: 2 additions & 0 deletions src/lib/bungie_api/authorization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <Navigate to={'/'} replace />;
}
Expand Down
12 changes: 2 additions & 10 deletions src/lib/bungie_api/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
12 changes: 12 additions & 0 deletions src/util/version-check.ts
Original file line number Diff line number Diff line change
@@ -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
);
}
}

0 comments on commit fa4eab3

Please sign in to comment.