From 66b0f36bbb001913334dfc7fa4855f7d87423970 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Tue, 14 Feb 2023 11:48:47 +0800 Subject: [PATCH] =?UTF-8?q?feat(rn):=20=E5=A2=9E=E5=8A=A0=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=9C=8D=E5=8A=A1=E5=99=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/mobile/src/Entry.tsx | 33 +++++++++++++++++++-- client/mobile/src/components/ServerCard.tsx | 2 ++ client/mobile/src/store/server.ts | 6 ++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/client/mobile/src/Entry.tsx b/client/mobile/src/Entry.tsx index 277f8b96..7b55a583 100644 --- a/client/mobile/src/Entry.tsx +++ b/client/mobile/src/Entry.tsx @@ -3,14 +3,22 @@ import { Alert, ScrollView, StyleSheet, TextInput } from 'react-native'; import { ServerCard } from './components/ServerCard'; import { useServerStore } from './store/server'; import Dialog from 'react-native-ui-lib/dialog'; -import { Button, PanningProvider, Text, View } from 'react-native-ui-lib'; +import { + Button, + PanningProvider, + Text, + View, + ActionSheet, +} from 'react-native-ui-lib'; import { isValidUrl } from './lib/utils'; export const Entry: React.FC = React.memo(() => { - const { serverList, selectServer, addServer } = useServerStore(); + const { serverList, selectServer, addServer, removeServer } = + useServerStore(); const [dialogVisible, setDialogVisible] = useState(false); const [serverUrl, setServerUrl] = useState(''); const [loading, setLoading] = useState(false); + const [selectedServer, setSelectedServer] = useState(''); return ( @@ -23,12 +31,33 @@ export const Entry: React.FC = React.memo(() => { url={serverInfo.url} version={serverInfo.version} onPress={() => selectServer(serverInfo)} + onLongPress={() => { + if (i !== 0) { + setSelectedServer(serverInfo.url); + } + }} /> ); })} setDialogVisible(true)} /> + setSelectedServer('')} + destructiveButtonIndex={0} + options={[ + { + label: '删除服务器', + onPress: () => { + removeServer(selectedServer); + }, + }, + ]} + showCancelButton={true} + /> + void; + onLongPress?: () => void; } export const ServerCard: React.FC = React.memo((props) => { return ( {props.name} diff --git a/client/mobile/src/store/server.ts b/client/mobile/src/store/server.ts index 554fe987..c4c5a805 100644 --- a/client/mobile/src/store/server.ts +++ b/client/mobile/src/store/server.ts @@ -14,6 +14,7 @@ interface ServerStoreState { selectedServerInfo: ServerInfo | null; serverList: ServerInfo[]; addServer: (url: string) => Promise; + removeServer: (url: string) => void; selectServer: (serverInfo: ServerInfo) => void; } @@ -57,6 +58,11 @@ export const useServerStore = create()( throw err; } }, + removeServer: (url: string) => { + set((state) => { + state.serverList = state.serverList.filter((s) => s.url !== url); + }); + }, selectServer: (serverInfo: ServerInfo) => { set({ selectedServerInfo: serverInfo,