mirror of
https://gitea.tendokyu.moe/ppc/amnet.git
synced 2026-09-27 00:50:06 +03:00
add deep link handling
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import {useCallback, useEffect, useLayoutEffect, useState} from "react";
|
||||
import {Card, Paragraph, useTheme} from "react-native-paper";
|
||||
import {TextInput, TouchableOpacity, View} from "react-native";
|
||||
import {useCallback, useEffect, useLayoutEffect, useState} from "react";
|
||||
import {useModalStyles} from "../utils/ModalStyles";
|
||||
|
||||
import RealmContext from "../models/RealmContext";
|
||||
@@ -17,8 +17,8 @@ export default function ServerAddModal({route, navigation}) {
|
||||
|
||||
// add option to add server address when loading a share link
|
||||
useEffect(() => {
|
||||
setServerAddress(route.params?.address || '');
|
||||
}, [route.params]);
|
||||
handleDeepLink(realm, navigation, route, setServerAddress);
|
||||
}, [route]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
navigation.setOptions({
|
||||
@@ -39,7 +39,6 @@ export default function ServerAddModal({route, navigation}) {
|
||||
}
|
||||
|
||||
const themeOptions = urlValid ? modalStyles.headerText : {color: theme.colors.outline};
|
||||
|
||||
navigation.setOptions({
|
||||
headerRight: () => <TouchableOpacity disabled={!urlValid} onPress={() => saveServer()}>
|
||||
<Paragraph style={{...themeOptions, fontWeight: "600"}}>Save</Paragraph>
|
||||
@@ -88,3 +87,24 @@ export default function ServerAddModal({route, navigation}) {
|
||||
</Paragraph>
|
||||
</View>)
|
||||
}
|
||||
|
||||
function handleDeepLink(realm, navigation, route, setAddress: (address: string) => void) {
|
||||
if (!route.params?.serverAddress) {
|
||||
return;
|
||||
}
|
||||
|
||||
const serverUrl = decodeURIComponent(route.params.serverAddress);
|
||||
const item = realm.objects(AMServer).filtered("serverAddress = $0", serverUrl);
|
||||
|
||||
if (item.length) {
|
||||
navigation.goBack();
|
||||
navigation.navigate('server', {
|
||||
serverId: item._id.toHexString()
|
||||
});
|
||||
} else {
|
||||
setAddress(serverUrl);
|
||||
}
|
||||
|
||||
// clear param from route
|
||||
navigation.setParams({serverAddress: null});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user