check for existing entry to select when scanning a physical card

This commit is contained in:
ppc
2025-01-14 22:20:53 +00:00
parent d0c7616ed1
commit 9324b30e7b
+25 -6
View File
@@ -27,7 +27,13 @@ import {AMServer} from "../models/AMServer";
import {AMCard} from "../models/AMCard";
import {felicaCardReadAsync, icCard0008Number, ICType} from "../lib/iccard";
import {AMServerConnectionInfo, AMServerInstanceMetrics, fetchServerInfo, getGameName, performCardIn} from "amnet-shared";
import {
AMServerConnectionInfo,
AMServerInstanceMetrics,
fetchServerInfo,
getGameName,
performCardIn
} from "amnet-shared";
import ObjectId = BSON.ObjectId;
@@ -149,7 +155,10 @@ export default function ServerCardIn({route, navigation}) {
const abortController = new AbortController();
performCardIn(server, {cardId: selectedCard.code, physicalCardIDm: selectedCard.physicalCardData?.cardIDm ?? undefined}, abortController.signal).then(r => {
performCardIn(server, {
cardId: selectedCard.code,
physicalCardIDm: selectedCard.physicalCardData?.cardIDm ?? undefined
}, abortController.signal).then(r => {
const now = new Date();
realm.write(() => {
server.lastUsed = now;
@@ -175,6 +184,14 @@ export default function ServerCardIn({route, navigation}) {
return;
}
const savedCard = cards.find(x => x.physicalCardData?.cardIDm === card.idm);
if (savedCard) {
setUserSelectedCard(savedCard);
cardInCallback();
return;
}
setCardInCompleted(false);
const cardId = card.type !== ICType.Amusement ? icCard0008Number(card.idm) : card.accessCode;
@@ -211,7 +228,8 @@ export default function ServerCardIn({route, navigation}) {
}
return (
<ScrollView contentInsetAdjustmentBehavior="automatic" refreshControl={<RefreshControl refreshing={serverRefreshing} onRefresh={performRefresh}/>}>
<ScrollView contentInsetAdjustmentBehavior="automatic"
refreshControl={<RefreshControl refreshing={serverRefreshing} onRefresh={performRefresh}/>}>
<View style={styles.container}>
<StatusAlert server={server} connectionEstablished={serverConnectionSuccess}/>
<View style={styles.section}>
@@ -231,17 +249,18 @@ export default function ServerCardIn({route, navigation}) {
contentStyle={{flexDirection: 'row-reverse'}}
mode={serverConnectionSuccess ? "contained" : "outlined"}
buttonColor={cardInCompleted === false ? "red" : "green"}
icon={() => <SquareArrowOutUpRight color={disableCardIn ? "gray" : "white"} size={18}/>}>
icon={() => <SquareArrowOutUpRight color={disableCardIn ? "gray" : "white"}
size={18}/>}>
{cardInCompleted === null ? "Card In" : cardInCompleted ? "Card In Success" : "Failed"}
</Button>
{nfcSupported === true && (
<IconButton
mode="outlined"
iconColor="#03a9f4"
disabled={disableCardIn}
onPress={performPhysicalCardIn}
style={{borderRadius: 10, margin: 0, height: "100%", flex: 0.2}}
icon={() => <SmartphoneNfc color={disableCardIn ? "gray" : "white"} size={18}/>}/>
icon={() => <SmartphoneNfc
color={disableCardIn ? "gray" : theme.colors.onBackground} size={18}/>}/>
)}
</View>
</>