mirror of
https://gitea.tendokyu.moe/ppc/amnet.git
synced 2026-10-02 03:37:58 +03:00
defer date changes until card in completes
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import {Alert, RefreshControl, ScrollView, StyleSheet, Text, View} from "react-native";
|
||||
import {BSON} from "realm";
|
||||
import {Alert, RefreshControl, ScrollView, StyleSheet, View} from "react-native";
|
||||
import React, {useCallback, useEffect, useLayoutEffect, useMemo, useState} from "react";
|
||||
import {ActivityIndicator, Button, Card, Paragraph, Title, useTheme} from "react-native-paper";
|
||||
import {CircleCheck, CircleDot, CreditCard, Nfc, Plus, SmartphoneNfcIcon, WifiOff} from "lucide-react-native";
|
||||
import {EmptyStatePlaceholder} from "../components/EmptyStatePlaceholder";
|
||||
import {AimeCard} from "../components/AimeCard";
|
||||
import {BSON} from "realm";
|
||||
|
||||
import RealmContext from "../models/RealmContext";
|
||||
import {AMServer} from "../models/AMServer";
|
||||
@@ -60,6 +60,10 @@ export default function ServerCardIn({route, navigation}) {
|
||||
|
||||
// set selected card (once)
|
||||
useEffect(() => {
|
||||
if (selectedCard?.isValid() === true) {
|
||||
return;
|
||||
}
|
||||
|
||||
setSelectedCard(cards.length ? cards[0] : null);
|
||||
}, [realm]);
|
||||
|
||||
@@ -80,9 +84,7 @@ export default function ServerCardIn({route, navigation}) {
|
||||
server.getInfo(abortController.signal).then(r => {
|
||||
if (r) {
|
||||
setConnectionTestResult(true);
|
||||
|
||||
realm.write(() => {
|
||||
server.lastUsed = new Date();
|
||||
Object.keys(r).forEach(x => server[x] = r[x]);
|
||||
});
|
||||
} else {
|
||||
@@ -103,12 +105,16 @@ export default function ServerCardIn({route, navigation}) {
|
||||
setCardInCompleted(false);
|
||||
|
||||
const abortController = new AbortController();
|
||||
server.submitCard(selectedCard.code, abortController.signal).then(r => {
|
||||
server.submitCard(selectedCard.code, abortController.signal).then(async r => {
|
||||
const now = new Date();
|
||||
|
||||
setCardInCompleted(r);
|
||||
realm.write(() => {
|
||||
selectedCard.lastUsed = new Date();
|
||||
setSelectedCard(selectedCard);
|
||||
server.lastUsed = now;
|
||||
selectedCard.lastUsed = now;
|
||||
});
|
||||
|
||||
setSelectedCard(selectedCard);
|
||||
}).catch(() => {
|
||||
setCardInCompleted(false);
|
||||
}).finally(() => {
|
||||
@@ -119,6 +125,8 @@ export default function ServerCardIn({route, navigation}) {
|
||||
return () => abortController.abort();
|
||||
}, [server, selectedCard]);
|
||||
|
||||
const disableCardIn = useMemo(() => cardInCompleted !== null || !connectionTestResult, [cardInCompleted, connectionTestResult]);
|
||||
|
||||
if (connectionTestResult === null) {
|
||||
return (
|
||||
<View style={{flex: 1, justifyContent: "center", alignItems: "center", gap: 10}}>
|
||||
@@ -128,9 +136,6 @@ export default function ServerCardIn({route, navigation}) {
|
||||
)
|
||||
}
|
||||
|
||||
// cached vars
|
||||
const disableCardIn = cardInCompleted !== null || !connectionTestResult;
|
||||
|
||||
return (
|
||||
<ScrollView contentInsetAdjustmentBehavior="automatic"
|
||||
contentContainerStyle={{...styles.container, paddingTop: connectionTestResult ? 0 : 10}}
|
||||
@@ -148,9 +153,9 @@ export default function ServerCardIn({route, navigation}) {
|
||||
<Title style={{color: theme.colors.secondary}}>Connection Failed</Title>
|
||||
</View>
|
||||
<Paragraph>
|
||||
There was an issue connecting to the AMNet server at <Paragraph
|
||||
There was an issue connecting to <Paragraph
|
||||
style={{fontFamily: "JetBrainsMono_400Regular"}}>{server.serverAddress}</Paragraph>.
|
||||
Check connections and game status and try again.
|
||||
Check the network connection and try again.
|
||||
</Paragraph>
|
||||
</Card.Content>
|
||||
</Card>
|
||||
|
||||
Reference in New Issue
Block a user