Désactivation du bouton de connexion pendant une connexion
This commit is contained in:
parent
48845c70c2
commit
4da75e310e
@ -7,7 +7,7 @@ import { Appbar, Button, Dialog, Portal, Surface, Text, TextInput } from "react-
|
||||
export default function Login() {
|
||||
const router = useRouter()
|
||||
const [isLoggedIn, setIsLoggedIn] = useState(SecureStore.getItem("apiToken") !== null)
|
||||
console.log(SecureStore.getItem("apiToken"))
|
||||
const [loggingIn, setLoggingIn] = useState(false)
|
||||
const [name, setName] = useState(SecureStore.getItem('apiName') ?? "")
|
||||
const [password, setPassword] = useState("")
|
||||
const [errorDialogVisible, setErrorDialogVisible] = useState(false)
|
||||
@ -20,6 +20,9 @@ export default function Login() {
|
||||
const hideErrorDialog = () => setErrorDialogVisible(false)
|
||||
|
||||
async function login() {
|
||||
if (loggingIn)
|
||||
return
|
||||
setLoggingIn(true)
|
||||
const resp = await fetch("http://192.168.1.198:3000/auth/login/", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
@ -30,6 +33,7 @@ export default function Login() {
|
||||
setErrorDialogVisible(true)
|
||||
setErrorTitle("Erreur")
|
||||
setErrorText("Une erreur inconnue est survenue lors de la connexion. Veuillez réessayer plus tard. " + err)
|
||||
setLoggingIn(false)
|
||||
})
|
||||
if (!resp)
|
||||
return
|
||||
@ -37,8 +41,10 @@ export default function Login() {
|
||||
setErrorDialogVisible(true)
|
||||
setErrorTitle(resp.error)
|
||||
setErrorText(resp.message)
|
||||
setLoggingIn(false)
|
||||
return
|
||||
}
|
||||
setLoggingIn(false)
|
||||
SecureStore.setItem("apiName", name)
|
||||
if (Platform.OS !== "web") {
|
||||
// Le stockage navigateur n'est pas sûr, on évite de stocker un mot de passe à l'intérieur
|
||||
@ -80,7 +86,13 @@ export default function Login() {
|
||||
onSubmitEditing={login}
|
||||
secureTextEntry={true}
|
||||
style={{ margin: 8 }} />
|
||||
<Button onPress={login} mode="contained" icon="login" style={{ margin: 8 }}>
|
||||
<Button
|
||||
key={loggingIn ? "disabledLoginButton" : "loginButton"}
|
||||
onPress={login}
|
||||
mode={"contained"}
|
||||
icon="login"
|
||||
disabled={loggingIn}
|
||||
style={{ margin: 8 }}>
|
||||
Se connecter
|
||||
</Button>
|
||||
<Portal>
|
||||
|
@ -4,15 +4,13 @@ import { Platform } from 'react-native'
|
||||
import { useEffect } from 'react'
|
||||
|
||||
const BACKGROUND_FETCH_TASK = "background-fetch"
|
||||
const BACKGROUND_FETCH_INTERVAL = 20
|
||||
const BACKGROUND_FETCH_INTERVAL = 60
|
||||
|
||||
async function backgroundUpdate() {
|
||||
async () => {
|
||||
const now = Date.now()
|
||||
console.log(`Got background fetch call at date: ${new Date(now).toISOString()}`)
|
||||
// Be sure to return the successful result type!
|
||||
return BackgroundFetch.BackgroundFetchResult.NewData
|
||||
}
|
||||
}
|
||||
|
||||
TaskManager.defineTask(BACKGROUND_FETCH_TASK, backgroundUpdate)
|
||||
|
Loading…
Reference in New Issue
Block a user