Skip to content

Commit

Permalink
test pwa testing
Browse files Browse the repository at this point in the history
  • Loading branch information
vys69 committed Sep 22, 2024
1 parent 175597d commit 098ebbf
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/components/PWAHandler.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
'use client'

import { useEffect } from 'react';
import { useRouter } from 'next/navigation';

export default function PWAHandler() {
const router = useRouter();

useEffect(() => {
const isPWA = window.matchMedia('(display-mode: standalone)').matches;

if (isPWA) {
window.addEventListener("visibilitychange", function () {
console.log("Visibility changed");
const handleVisibilityChange = () => {
if (document.visibilityState === "visible") {
console.log("APP resumed");
window.location.reload();
const setupSkipped = localStorage.getItem("setupSkipped");
const currency = localStorage.getItem("currency");
const state = localStorage.getItem("state");

if (setupSkipped === "true" || (currency && state)) {
router.push('/cart');
} else {
router.push('/onboarding');
}
}
});
};

document.addEventListener("visibilitychange", handleVisibilityChange);

return () => {
document.removeEventListener("visibilitychange", handleVisibilityChange);
};
}
}, []);
}, [router]);

return null;
}

0 comments on commit 098ebbf

Please sign in to comment.