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,