Skip to content

Commit

Permalink
fix: remove pwa install state (#1683)
Browse files Browse the repository at this point in the history
* fix: remove pwa install state

* fix: use cookies instead
  • Loading branch information
irmannmal authored Jan 30, 2023
1 parent d7c8990 commit 0511378
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/components/PwaWrapper/PwaWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {XIcon} from '@heroicons/react/solid';

import {useState} from 'react';
import {useCookies} from 'react-cookie';
import {usePWAInstall} from 'react-use-pwa-install';

import Image from 'next/image';
Expand All @@ -10,7 +11,10 @@ import Box from '@material-ui/core/Box';
import Snackbar from '@material-ui/core/Snackbar';
import Typography from '@material-ui/core/Typography';

export const HIDE_PWA_INSTALL_POPUP_COOKIE_KEY = 'hide-pwa-install-popup';

const PwaWrapper = () => {
const [cookies, setCookie] = useCookies([HIDE_PWA_INSTALL_POPUP_COOKIE_KEY]);
const [isOpen, setOpen] = useState(true);
const install = usePWAInstall();
const theme = useTheme();
Expand All @@ -23,10 +27,10 @@ const PwaWrapper = () => {

const onClose = () => {
setOpen(false);
localStorage.setItem('hide_pwa_install_popup', 'true');
setCookie(HIDE_PWA_INSTALL_POPUP_COOKIE_KEY, true);
};

if (!isMobileAndTablet || localStorage.getItem('hide_pwa_install_popup') === 'true' || !install)
if (!isMobileAndTablet || Boolean(cookies[HIDE_PWA_INSTALL_POPUP_COOKIE_KEY]) || !install)
return null;

return (
Expand Down

0 comments on commit 0511378

Please sign in to comment.