add server share option to context menu

This commit is contained in:
ppc
2024-09-03 15:02:11 +01:00
parent 15329d5dcd
commit 6acddc2f78
4 changed files with 29 additions and 15 deletions
+5 -4
View File
@@ -26,12 +26,12 @@ function CardEntry(props: { card: AMCard, navigation: any }) {
return;
// edit card
case "1":
case "1,0":
props.navigation.navigate('add-card', {cardId: props.card.code, cardName: props.card.name});
return;
// remove card
case "2,0":
case "1,1":
realm.write(() => realm.delete(props.card));
return;
}
@@ -42,11 +42,12 @@ function CardEntry(props: { card: AMCard, navigation: any }) {
onPress={e => callback(e.nativeEvent?.indexPath)}
actions={[
{title: "Copy Card Number", systemIcon: "doc.on.doc"},
{title: "Edit Card", systemIcon: "square.and.pencil"},
{
title: "",
inlineChildren: true,
actions: [{title: "Delete Card", destructive: true, systemIcon: "trash"}]
actions: [
{title: "Edit Card", systemIcon: "square.and.pencil"},
{title: "Delete Card", destructive: true, systemIcon: "trash"}]
}]}>
<AimeCard card={props.card} showFullCardNumber/>
</ContextMenu>
+1 -1
View File
@@ -57,7 +57,7 @@ export default function ServerCardIn({route, navigation}) {
navigation.setOptions({
title: server.serverName,
headerRight: () => (
<TouchableOpacity onPress={() => Share.share({url: `http://card.ppc.moe/#/servers/add?address=${encodeURIComponent(server.serverAddress)}`})}>
<TouchableOpacity onPress={() => Share.share({url: server.shareUrl})}>
<ShareIcon/>
</TouchableOpacity>
)
+19 -10
View File
@@ -1,7 +1,7 @@
import {Button, Paragraph, useTheme} from "react-native-paper";
import {Globe, History, Plus, ServerOff} from "lucide-react-native";
import {FlatList, NativeSyntheticEvent, Text, View} from "react-native";
import React, {useCallback, useLayoutEffect, useMemo, useState} from "react";
import {FlatList, NativeSyntheticEvent, Share, Text, View} from "react-native";
import ContextMenu, {ContextMenuOnPressNativeEvent} from "react-native-context-menu-view";
import {EmptyStatePlaceholder} from "../components/EmptyStatePlaceholder";
import {AMUICard, AMUICardDetail} from "../components/AMUICard";
@@ -21,23 +21,32 @@ function ServerCard(props: { server: AMServer, navigation: any }) {
}, [props.navigation, props.server]);
const pageContextMenuCallback = useCallback((action: NativeSyntheticEvent<ContextMenuOnPressNativeEvent>) => {
switch (action.nativeEvent.index) {
case 0:
switch (action.nativeEvent.indexPath.toString()) {
case "0":
pageCallback();
break;
return;
case 1:
realm.write(() => {
realm.delete(props.server);
});
break;
case "1,0":
Share.share({url: props.server.shareUrl});
return;
case "1,1":
realm.write(() => realm.delete(props.server));
return;
}
}, [realm, props.server]);
return (
<ContextMenu onPress={pageContextMenuCallback} actions={[
{title: `Select ${props.server.serverName}`, systemIcon: "chevron.right"},
{title: "Delete Server", systemIcon: "trash", destructive: true}
{
title: null,
inlineChildren: true,
actions: [
{title: "Share Server", systemIcon: "square.and.arrow.up"},
{title: "Delete Server", systemIcon: "trash", destructive: true}
]
}
]}>
<AMUICard title={props.server.serverName} onPress={pageCallback}>
<AMUICardDetail>
+4
View File
@@ -12,6 +12,10 @@ export class AMServer extends Realm.Object<AMServer> implements AMServerInfoResp
lastUsed: Date;
createdAt: Date;
get shareUrl() {
return `http://card.ppc.moe/#/servers/add?address=${encodeURIComponent(this.serverAddress)}`;
}
static generate(serverAddress: string) {
return {