@@ -16,21 +16,25 @@ import {
16
16
} from "@ionic/react"
17
17
import { useHistory } from "react-router"
18
18
import { useQueryClient } from "@tanstack/react-query"
19
- import { useState } from "react"
19
+ import { useRef } from "react"
20
20
import { useAuth } from "@/hooks"
21
21
import { InfoBanners } from "@/components"
22
22
23
23
const SettingsLoginPage : React . FC = ( ) => {
24
24
const queryClient = useQueryClient ( )
25
25
const history = useHistory ( )
26
26
const [ { username, token } , saveAuth ] = useAuth ( )
27
- const [ newUsername , setNewUsername ] = useState < string > ( username ?? "" )
28
- const [ newPassword , setNewPassword ] = useState < string > ( token ?? "" )
29
27
const ionConfig = getConfig ( )
30
28
const currentMode = ionConfig ?. get ( "mode" ) || "ios"
31
29
30
+ const usernameInputRef = useRef < HTMLIonInputElement > ( null )
31
+ const passwordInputRef = useRef < HTMLIonInputElement > ( null )
32
+
32
33
const handleSave = ( ) => {
33
- saveAuth ( newUsername , newPassword )
34
+ const newUsername = ( usernameInputRef . current ?. value as string ) || username
35
+ const newPassword = ( passwordInputRef . current ?. value as string ) || token
36
+
37
+ saveAuth ( newUsername ?? "" , newPassword ?? "" )
34
38
queryClient . clear ( )
35
39
history . push ( "/" )
36
40
window . location . reload ( )
@@ -57,19 +61,10 @@ const SettingsLoginPage: React.FC = () => {
57
61
< IonContent className = "ion-padding" >
58
62
< IonList inset = { true } >
59
63
< IonItem color = { lightMode } >
60
- < IonInput
61
- label = "Username"
62
- value = { newUsername }
63
- onIonChange = { ( e ) => setNewUsername ( `${ e . target . value } ` ) }
64
- />
64
+ < IonInput label = "Username" value = { username } ref = { usernameInputRef } />
65
65
</ IonItem >
66
66
< IonItem color = { lightMode } >
67
- < IonInput
68
- type = "password"
69
- label = "Token"
70
- value = { newPassword }
71
- onIonChange = { ( e ) => setNewPassword ( `${ e . target . value } ` ) }
72
- >
67
+ < IonInput type = "password" label = "Token" value = { token } ref = { passwordInputRef } >
73
68
< IonInputPasswordToggle slot = "end" />
74
69
</ IonInput >
75
70
</ IonItem >
0 commit comments