diff --git a/apps/frontend/app/(tabs)/two.tsx b/apps/frontend/app/(tabs)/two.tsx new file mode 100644 index 0000000..3752f9e --- /dev/null +++ b/apps/frontend/app/(tabs)/two.tsx @@ -0,0 +1,85 @@ +import React, { useState } from 'react'; +import { + TextInput, + View as RNView, + TouchableOpacity, + Alert, + ActivityIndicator, +} from 'react-native'; +import { useRouter } from 'expo-router'; +import { Text, View } from '@/components/Themed'; +import { useColorScheme } from '@/components/useColorScheme'; +import Colors from '@/constants/Colors'; +import { usersApi } from '@/lib/api'; +import { Search, User } from 'lucide-react-native'; + +export default function SearchScreen() { + const [searchQuery, setSearchQuery] = useState(''); + const [loading, setLoading] = useState(false); + const colorScheme = useColorScheme(); + const colors = Colors[colorScheme ?? 'light']; + const router = useRouter(); + + const handleSearch = async () => { + const query = searchQuery.trim(); + + if (!query) { + Alert.alert('Ошибка', 'Введите имя пользователя'); + return; + } + + setLoading(true); + try { + const user = await usersApi.getUserByName(query); + // Переходим к профилю пользователя по его ID + router.push(`/user/${user.id}` as any); + setSearchQuery(''); + } catch (error: any) { + Alert.alert('Пользователь не найден', error.message || 'Пользователь с таким именем не существует'); + } finally { + setLoading(false); + } + }; + + return ( + + + + + + {loading ? ( + + ) : ( + + )} + + + + + + Поиск пользователей + + Введите имя пользователя в поле выше и нажмите поиск, чтобы просмотреть его профиль + + + + ); +}