Skip to content

Commit

Permalink
compare with previous stats
Browse files Browse the repository at this point in the history
  • Loading branch information
pveyes committed Oct 5, 2023
1 parent fe14a5c commit 51bbba8
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default function Home(props: Props) {
return;
}

const hasExistingData = checkExistingData();
const hasExistingData = checkExistingData(data.stats);

let shouldContinue = true;
if (hasExistingData) {
Expand Down Expand Up @@ -216,17 +216,36 @@ export const getStaticProps: GetStaticProps<Props> = async () => {
};
};

const checkExistingData = () => {
const checkExistingData = (newStats: GameStats) => {
if (!LocalStorage.getItem(GAME_STATS_KEY)) {
return false;
}

try {
const stats: GameStats = JSON.parse(
const currentStats: GameStats = JSON.parse(
LocalStorage.getItem(GAME_STATS_KEY) as string
);
const totalPlay = getTotalPlay(stats);
return totalPlay > 0;
const totalPlay = getTotalPlay(currentStats);
const newTotalPlay = getTotalPlay(newStats);
if (totalPlay !== newTotalPlay) {
return true;
}

if (currentStats.maxStreak !== newStats.maxStreak) {
return true;
}

if (currentStats.currentStreak !== newStats.currentStreak) {
return true;
}

for (const v in currentStats.distribution) {
if (currentStats.distribution[v] !== newStats.distribution[v]) {
return true;
}
}

return false;
} catch (err) {
return false;
}
Expand Down

1 comment on commit 51bbba8

@vercel
Copy link

@vercel vercel bot commented on 51bbba8 Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

katla – ./

katla-katla.vercel.app
katla.vercel.app
katla-git-main-katla.vercel.app
katla.id

Please sign in to comment.