1
- import { useState } from "react"
1
+ import { useEffect , useState } from "react"
2
2
import {
3
3
IonModal ,
4
4
IonHeader ,
@@ -12,9 +12,11 @@ import {
12
12
IonNote ,
13
13
IonList ,
14
14
IonInputPasswordToggle ,
15
+ IonLabel ,
15
16
} from "@ionic/react"
16
17
import { useQueryClient } from "@tanstack/react-query"
17
18
import { useAuth } from "../hooks"
19
+ import { formatBytes } from "../utils"
18
20
19
21
interface Props {
20
22
open : boolean
@@ -27,6 +29,17 @@ const Settings: React.FC<Props> = ({ open, onClose, onSave }) => {
27
29
const [ { username, token } , saveAuth , clearAuth ] = useAuth ( )
28
30
const [ newUsername , setNewUsername ] = useState < string > ( username ?? "" )
29
31
const [ newPassword , setNewPassword ] = useState < string > ( token ?? "" )
32
+ const [ storageInfo , setStorageInfo ] = useState < { usage : string ; quota : string } | undefined > ( )
33
+
34
+ useEffect ( ( ) => {
35
+ if ( "storage" in navigator && "estimate" in navigator . storage ) {
36
+ navigator . storage . estimate ( ) . then ( ( { usage, quota } ) => {
37
+ if ( usage && quota ) {
38
+ setStorageInfo ( { usage : formatBytes ( usage ) , quota : formatBytes ( quota ) } )
39
+ }
40
+ } )
41
+ }
42
+ } , [ ] )
30
43
31
44
const handleSave = ( ) => {
32
45
saveAuth ( newUsername , newPassword )
@@ -74,6 +87,14 @@ const Settings: React.FC<Props> = ({ open, onClose, onSave }) => {
74
87
< a href = "https://www.discogs.com/settings/developers" > visit the Developer page</ a > and copy your
75
88
token, or click Generate if you do not have one.
76
89
</ IonNote >
90
+ < IonList inset = { true } >
91
+ < IonItem >
92
+ < IonLabel > Storage Used</ IonLabel >
93
+ < IonLabel slot = "end" >
94
+ { storageInfo ?. usage ?? "Unknown" } of { storageInfo ?. quota ?? "Unknown" }
95
+ </ IonLabel >
96
+ </ IonItem >
97
+ </ IonList >
77
98
</ IonContent >
78
99
</ IonModal >
79
100
)
0 commit comments