add confirmation before deleting server

This commit is contained in:
ppc
2025-05-08 20:59:41 +01:00
parent 0edd7e13fa
commit 3511efcc04
+27 -10
View File
@@ -1,7 +1,7 @@
import {BSON} from "realm";
import NfcManager from "react-native-nfc-manager";
import React, {useCallback, useEffect, useLayoutEffect, useMemo, useState} from "react";
import {Platform, RefreshControl, ScrollView, Share, StyleSheet, Text, View} from "react-native";
import {Alert, Platform, RefreshControl, ScrollView, Share, StyleSheet, Text, View} from "react-native";
import {ActivityIndicator, Button, IconButton, Paragraph, Title, useTheme} from "react-native-paper";
import {
CircleCheck,
@@ -54,17 +54,30 @@ export default function ServerCardIn({route, navigation}) {
});
// header actions
const menuCallback = useCallback((e: NativeActionEvent) => {
const menuCallback = useCallback(async (e: NativeActionEvent) => {
switch (e.nativeEvent.event) {
case "share":
Share.share({url: server.shareUrl});
break;
case "delete":
realm.write(() => {
realm.delete(server);
navigation.goBack();
});
Alert.alert("Delete Server", "Are you sure you want to delete this server?", [
{
text: "Cancel",
style: "cancel"
},
{
text: "Delete",
style: "destructive",
onPress: () => {
realm.write(() => {
realm.delete(server);
navigation.goBack();
});
}
}
]);
break;
}
}, [realm, server, navigation]);
@@ -249,11 +262,13 @@ 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}>
<Title style={styles.sectionTitle}>{server.gameId ? `Play ${getGameName(server.gameId)}` : "Selected Card"}</Title>
<Title
style={styles.sectionTitle}>{server.gameId ? `Play ${getGameName(server.gameId)}` : "Selected Card"}</Title>
{selectedCard ? <>
<ICCard actionDisabled
card={selectedCard}
@@ -268,7 +283,8 @@ export default function ServerCardIn({route, navigation}) {
mode={serverConnectionSuccess ? "contained" : "outlined"}
buttonColor={cardInCompleted === false ? "red" : "green"}
onPress={() => cardInCallback(selectedCard)}
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 && (
@@ -277,7 +293,8 @@ export default function ServerCardIn({route, navigation}) {
disabled={disableCardIn}
onPress={performPhysicalCardIn}
style={{borderRadius: 10, margin: 0, height: "100%", flex: 0.2}}
icon={() => <SmartphoneNfc color={disableCardIn ? "gray" : theme.colors.onBackground} size={18}/>}/>
icon={() => <SmartphoneNfc
color={disableCardIn ? "gray" : theme.colors.onBackground} size={18}/>}/>
)}
</View>
</>