Skip to content

Commit

Permalink
Merge pull request #86 from dragoni7/versioning
Browse files Browse the repository at this point in the history
Versioning
  • Loading branch information
dragoni7 authored Sep 15, 2024
2 parents d516d26 + fa4eab3 commit 6d2b28d
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 15 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "d2loadouts",
"private": true,
"version": "0.0.0",
"version": "0.0.1",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
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 6d2b28d

Please sign in to comment.