Skip to content

Commit

Permalink
Merge pull request #6 from skedwards88/revert-5-revert-4-revert-3-mov…
Browse files Browse the repository at this point in the history
…eVisited

Revert "Revert "Revert "Move hasVisited logic"""
  • Loading branch information
skedwards88 authored May 6, 2024
2 parents 7b79404 + 460ecd0 commit 775080e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {gameReducer} from "../logic/gameReducer";
import getDailySeed from "../common/getDailySeed";
import {gameIsSolvedQ} from "../logic/gameIsSolvedQ";
import {getInitialState} from "../logic/getInitialState";
import {hasVisitedSince} from "../logic/hasVisitedSince";

function parseUrlQuery() {
const searchParams = new URLSearchParams(document.location.search);
Expand All @@ -32,6 +33,7 @@ function parseUrlQuery() {
export default function App() {
const [seed, difficultyLevel] = parseUrlQuery();

const hasVisited = hasVisitedSince();
const [lastVisited] = React.useState(getDailySeed());
React.useEffect(() => {
window.localStorage.setItem(
Expand All @@ -43,7 +45,9 @@ export default function App() {
const savedDisplay = JSON.parse(
localStorage.getItem("blobbleDisplaySavedStateName"),
);
const [display, setDisplay] = React.useState(getInitialState(savedDisplay));
const [display, setDisplay] = React.useState(
getInitialState(savedDisplay, hasVisited),
);

const [installPromptEvent, setInstallPromptEvent] = React.useState();
const [showInstallButton, setShowInstallButton] = React.useState(true);
Expand Down
5 changes: 1 addition & 4 deletions src/logic/getInitialState.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {hasVisitedSince} from "./hasVisitedSince";

export function getInitialState(savedDisplay) {
const hasVisited = hasVisitedSince();
export function getInitialState(savedDisplay, hasVisited) {
if (!hasVisited) {
return "rules";
}
Expand Down
3 changes: 3 additions & 0 deletions src/logic/hasVisitedSince.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ export function hasVisitedSince() {

const resetDate = convertYYYYMMDDToDate("20240429");

console.log(lastVisitedDate);
console.log(resetDate);
console.log(lastVisitedDate >= resetDate);
return lastVisitedDate >= resetDate;
}

0 comments on commit 775080e

Please sign in to comment.