import { Button, Card, CardContent, Dialog, DialogActions, DialogContent, DialogTitle, Stack, Typography } from '@mui/material'; import { useState, useEffect, Fragment } from 'react'; import { useNavigationType, useNavigate } from 'react-router'; function StorageDialog() { const navigate = useNavigate(); const close = () => { navigate('..'); } const [bytesUsed, setBytesUsed] = useState(undefined); const [bytesAvailable, setBytesAvailable] = useState(undefined); const [usingPersist, setUsingPersist] = useState(undefined); const [error, setError] = useState(undefined); const [waitingForPersist, setWaitingForPersist] = useState(false); const persistenceSupport = navigator.storage?.persisted !== undefined; const ask = () => { setWaitingForPersist(true); navigator.storage.persist().then((granted: boolean) => { setWaitingForPersist(false); setUsingPersist(granted); }, (reason: any) => { setWaitingForPersist(false); setError(reason); }) } useEffect(() => { navigator.storage.estimate().then((est: StorageEstimate) => { setBytesAvailable(est.quota); setBytesUsed(est.usage); }).catch((reason: any) => { setError(reason); }); navigator.storage.persisted().then((value: boolean) => { setUsingPersist(value); }).catch((reason: any) => { setError(reason); }); }, []); return Browser Storage {error !== undefined && There was an error retrieving storage infomration:

{error}
} {error === undefined && (bytesAvailable === undefined || bytesUsed === undefined || useNavigationType === undefined) && Loading... } {error === undefined && !(bytesAvailable === undefined || bytesUsed === undefined || useNavigationType === undefined) && Using {bytesUsed < 1024*1024 && {Math.round(bytesUsed/1024)} kb}{bytesUsed >= 1024*1024 && bytesUsed < 1024*1024*1024 && {Math.round(bytesUsed/(1024*1024))} mb}{bytesUsed >= 1024*1024*1024 && {Math.round(bytesUsed/(1024*1024*1024))} gb} {bytesAvailable>0 && ({Math.round(bytesUsed/bytesAvailable*100)}%)} out of a maximum of {bytesAvailable >= 1024*1024*1024 && {Math.round(bytesAvailable/(1024*1024*1024))} gb}{bytesAvailable >= 1024*1024 && bytesAvailable < 1024*1024*1024 && {Math.round(bytesAvailable/(1024*1024))} mb}{bytesAvailable < 1024 && {Math.round(bytesAvailable/(1024))} kb}.
{ persistenceSupport && {usingPersist && Persistent storage has been enabled. } {!usingPersist && !waitingForPersist && Persistent storage has not been enabled (your browser may delete your Home at any time). } {!usingPersist && waitingForPersist && Please authorize the use of persistent storage (your browser should be asking for your confirmation now). } }
}
{persistenceSupport && usingPersist !== undefined && !usingPersist && !usingPersist && }
; } export default StorageDialog;