import { View, Text, FlatList, ScrollView, TouchableOpacity, Image as NativeImage, } from "react-native"; import React, { useState, useEffect, useRef, useMemo, useCallback, } from "react"; import { useTailwind } from "tailwind-rn"; import Toast from "react-native-toast-message"; import Empty from "../../../components/Empty"; import { ListItem, Icon, SearchBar } from "@rneui/themed"; import { Image } from "expo-image"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import baseRequest from "../../../utils/baseRequest"; import { generateSignature } from "../../../utils/crypto"; import formatTimestamp from "../../../utils/formatTimestamp"; export default function SpaceSearch({ navigation }) { const blurhash = "LcKUTa%gOYWBYRt6xuoJo~s8V@fk"; const tailwind = useTailwind(); const insets = useSafeAreaInsets(); const [data, setData] = useState([]); const [search, setSearch] = useState(""); const [isloading, setIsloading] = useState(false); const searchRef = useRef(null); const getData = async (searchValue) => { if (searchValue == "") { return; } if (/[^0-9]/.test(searchValue)) { Toast.show({ type: "error", text1: "请输入正确的用户ID", topOffset: 60, }); return; } const apiUrl = process.env.EXPO_PUBLIC_API_URL; try { setIsloading(true); const base = await baseRequest(); const body = { member_user_id: Number(searchValue), ...base, }; const signature = await generateSignature(body); const _response = await fetch( `${apiUrl}/api/zone/search_zone_member?signature=${signature}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(body), } ); const _data = await _response.json(); if (_data.ret === -1) { setIsloading(false); Toast.show({ type: "error", text1: _data.msg, topOffset: 60, }); return; } setData(_data.data.list); } catch (error) { console.error(error); } setIsloading(false); }; //进入页面默认focus useEffect(() => { searchRef.current.focus(); }, []); //搜索框文本变化时进行搜索 // useEffect(() => { // if (!search) { // setData([]); // return; // } // let ignore = false; // // getData(search); // return () => { // ignore = true; // }; // }, [search]); const updateSearch = (search) => { setSearch(search); if (!search) return; }; //单个成员组件 const renderItem = useCallback((item, index) => { return ( {item?.account?.name} {item?.is_ironfan == 1 && ( 铁粉 )} {item?.is_superfan == 1 && ( 超粉 )} {item?.account?.user_id} {formatTimestamp(item?.join_ct)} ); }, []); return ( navigation.goBack()} /> <>} showCancel={false} searchIcon={() => <>} showLoading={isloading} onChangeText={updateSearch} value={search} /> getData(search)} > 搜索 {data?.map( (item, index) => renderItem(item, index) // )} {data.length === 0 && } ); }