mirror of
https://gitea.tendokyu.moe/ppc/amnet.git
synced 2026-09-28 17:58:10 +03:00
add server startup warning message
This commit is contained in:
@@ -1,17 +1,10 @@
|
||||
import {BSON} from "realm";
|
||||
import {fetchServerInfo, getGameName, performCardIn} from "amnet-shared";
|
||||
import React, {useCallback, useEffect, useLayoutEffect, useMemo, useState} from "react";
|
||||
import {ActivityIndicator, Button, Paragraph, Title, useTheme} from "react-native-paper";
|
||||
import {Alert, RefreshControl, ScrollView, Share, StyleSheet, TouchableOpacity, View} from "react-native";
|
||||
import {
|
||||
CircleCheck,
|
||||
CircleDot,
|
||||
CreditCard,
|
||||
Nfc,
|
||||
Plus,
|
||||
SmartphoneNfcIcon,
|
||||
Share as ShareIcon,
|
||||
WifiOff,
|
||||
CircleCheck, CircleDot, CreditCard, Nfc, Plus, SmartphoneNfcIcon,
|
||||
Share as ShareIcon, WifiOff, TvMinimalPlay
|
||||
} from "lucide-react-native";
|
||||
|
||||
import {EmptyStatePlaceholder} from "../components/EmptyStatePlaceholder";
|
||||
@@ -22,6 +15,13 @@ import RealmContext from "../models/RealmContext";
|
||||
import {AMServer} from "../models/AMServer";
|
||||
import {AMCard} from "../models/AMCard";
|
||||
import ObjectId = BSON.ObjectId;
|
||||
import {
|
||||
AMServerConnectionInfo,
|
||||
AMServerInstanceMetrics,
|
||||
fetchServerInfo,
|
||||
getGameName,
|
||||
performCardIn
|
||||
} from "amnet-shared";
|
||||
|
||||
const {useRealm, useQuery, useObject} = RealmContext;
|
||||
|
||||
@@ -61,7 +61,7 @@ export default function ServerCardIn({route, navigation}) {
|
||||
const server = useObject(AMServer, ObjectId.createFromHexString(serverId));
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (!server) {
|
||||
if (server?.isValid() !== true) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -75,16 +75,7 @@ export default function ServerCardIn({route, navigation}) {
|
||||
});
|
||||
}, [navigation, server]);
|
||||
|
||||
// set selected card (once)
|
||||
useEffect(() => {
|
||||
if (selectedCard?.isValid() === true) {
|
||||
return;
|
||||
}
|
||||
|
||||
setSelectedCard(cards.length ? cards[0] : null);
|
||||
}, [realm]);
|
||||
|
||||
// refresh server info (server change or reload request)
|
||||
// card selection, server connection checks
|
||||
useEffect(() => {
|
||||
if (server?.isValid() !== true) {
|
||||
navigation.goBack();
|
||||
@@ -97,6 +88,10 @@ export default function ServerCardIn({route, navigation}) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedCard?.isValid() !== true) {
|
||||
setSelectedCard(cards.length ? cards[0] : null);
|
||||
}
|
||||
|
||||
const abortController = new AbortController();
|
||||
fetchServerInfo(server.serverAddress, abortController.signal).then(r => {
|
||||
if (r) {
|
||||
@@ -143,6 +138,11 @@ export default function ServerCardIn({route, navigation}) {
|
||||
return () => abortController.abort();
|
||||
}, [server, selectedCard]);
|
||||
|
||||
const performRefresh = () => {
|
||||
setServerRefreshing(true);
|
||||
setServerReloadCounter(serverReloadCounter + 1);
|
||||
}
|
||||
|
||||
const gameName = useMemo(() => getGameName(server.gameId), [server.gameId]);
|
||||
const disableCardIn = useMemo(() => cardInCompleted !== null || !connectionTestResult, [cardInCompleted, connectionTestResult]);
|
||||
|
||||
@@ -158,12 +158,7 @@ export default function ServerCardIn({route, navigation}) {
|
||||
return (
|
||||
<ScrollView contentInsetAdjustmentBehavior="automatic"
|
||||
contentContainerStyle={{...styles.container, paddingTop: connectionTestResult ? 0 : 10}}
|
||||
refreshControl={<RefreshControl refreshing={serverRefreshing}
|
||||
tintColor={theme.colors.onSurface}
|
||||
onRefresh={() => {
|
||||
setServerRefreshing(true);
|
||||
setServerReloadCounter(serverReloadCounter + 1);
|
||||
}}/>}>
|
||||
refreshControl={<RefreshControl refreshing={serverRefreshing} tintColor={theme.colors.onSurface} onRefresh={performRefresh}/>}>
|
||||
<StatusAlert server={server} connectionEstablished={connectionTestResult}/>
|
||||
<View style={styles.section}>
|
||||
<Title style={styles.sectionTitle}>{gameName ? `Play ${gameName}` : "Selected Card"}</Title>
|
||||
@@ -218,17 +213,31 @@ export default function ServerCardIn({route, navigation}) {
|
||||
)
|
||||
}
|
||||
|
||||
function StatusAlert(props: {server: AMServer, connectionEstablished: boolean}) {
|
||||
function StatusAlert(props: {
|
||||
server: AMServerConnectionInfo & Partial<AMServerInstanceMetrics>,
|
||||
connectionEstablished: boolean
|
||||
}) {
|
||||
if (!props.connectionEstablished) {
|
||||
return (
|
||||
<AMUIStatusAlert color={"red"} icon={WifiOff} title={"Connection Failed"}>
|
||||
<AMUIStatusAlert color="red" icon={WifiOff} title="Connection Failed">
|
||||
<Paragraph>
|
||||
There was an issue connecting to <Paragraph
|
||||
style={{fontFamily: "JetBrainsMono_400Regular"}}>{props.server.serverAddress}</Paragraph>.
|
||||
Check the network connection and try again.
|
||||
</Paragraph>
|
||||
</AMUIStatusAlert>
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
// don't show if undefined (some older server versions)
|
||||
if (props.server.timeSinceLastPoll === null) {
|
||||
return (
|
||||
<AMUIStatusAlert color="#822eff" icon={TvMinimalPlay} title="Server Startup">
|
||||
<Paragraph>
|
||||
Scanning a card below may not have any effect until the service has fully started up.
|
||||
</Paragraph>
|
||||
</AMUIStatusAlert>
|
||||
)
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -8,8 +8,8 @@ import {AMUICard, AMUICardDetail} from "../components/AMUICard";
|
||||
import TimeAgo from "../components/TimeAgo";
|
||||
|
||||
import RealmContext from "../models/RealmContext";
|
||||
import {getGameName} from "../../amnet-shared";
|
||||
import {AMServer} from "../models/AMServer";
|
||||
import {getGameName} from "amnet-shared";
|
||||
|
||||
const {useRealm, useQuery} = RealmContext;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user