import { Pressable, Text, TextInput, View, Image, TouchableOpacity, Modal } from…
- User
import { Pressable, Text, TextInput, View, Image, TouchableOpacity, Modal } from ‘react-native’; import { gStyle } from ‘…/styles/style’; import { Feather } from ‘@expo/vector-icons’; import React, { useState, useEffect } from ‘react’; import { useNavigation } from ‘@react-navigation/native’; import { firebase } from ‘…/Firebase/firebase’; import ‘firebase/compat/auth’; import ‘firebase/compat/database’; import ‘firebase/compat/firestore’;
export default function Header() { const [searchTerm, setSearchTerm] = useState(‘’);
const [searchResult, setSearchResult]= useState(‘’);
const handleSearch = async ()=>{ if(!searchTerm.trim()){ setSearchResult([]); return; } const futureMKSnapshot = await firebase .firestore() .collection(‘FutureMK’) .where(‘name’,‘>=’,searchTerm) .where(‘name’,‘<=’,searchTerm + ‘\uf8ff’) .get();
const pastMKSnapshot = await firebase .firestore() .collection(‘PastMK’) .where(‘name’,‘>=’,searchTerm) .where(‘name’,‘<=’,searchTerm + ‘\uf8ff’) .get();
const futureMKData = futureMKSnapshot.docs.map(doc => ({ id: doc.id, …doc.data(), }));
const pastMKData = pastMKSnapshot.docs.map(doc => ({ id: doc.id, …doc.data(), }));
const results = […futureMKData, …pastMKData].filter(item=> item.name.toLowerCase().includes(searchTerm.toLowerCase())); const storage=firebase.storage; const resultWithImages = await Promise.all( results.map(async item=>{ try{ const imagePath=item.image; const imageRef=storage.ref().child(imagePath); const url = await imageRef.getDownloadURL(); return {… item, image:url}; }catch(error){ console.log(‘Ошибка загрузки изображения: ‘, error); return item; } }) ) setSearchResult(resultWithImages); navigation.navigate(‘Search’, { results: resultWithImages }); };
const [userAuthenticated, setUserAuthenticated] = useState(false);
const [isModalVisible, setIsModalVisible] = useState(false);
const showModal = () => { setIsModalVisible(true); };
const hideModal = () => { setIsModalVisible(false); };
const navigation = useNavigation();
useEffect(() => { const unsubscribe = firebase.auth().onAuthStateChanged(user => { if (user) { setUserAuthenticated(true); } else { setUserAuthenticated(false); } });
return unsubscribe; }, []); return ( <Image source={require(’…/assets/logo.png’)} style={gStyle.logoImg} /> Х <TouchableOpacity onPress={()=>navigation.navigate(‘Home’)}
Главная <TouchableOpacity onPress={()=>navigation.navigate(‘AllFutureMK’)}
Будущие мастер-классы <TouchableOpacity onPress={()=>navigation.navigate(‘AllPastMK’)}
Архив мастер-классов <TouchableOpacity onPress={()=>navigation.navigate(‘Sales’)}
Скидки {userAuthenticated ? <TouchableOpacity onPress={()=>navigation.navigate(‘Profile’)}
- Assistant
Based on the provided code, it seems like the issue may be with the
firebase.storageimport and usage. In thehandleSearchfunction, thefirebase.storageis not being initialized with theFirebase/firebaseimport. It needs to be called asfirebase.storage()instead offirebase.storage. Here's an updated version of the code:const handleSearch = async () => { if (!searchTerm.trim()) { setSearchResult([]); return; } const futureMKSnapshot = await firebase .firestore() .collection('FutureMK') .where('name', '>=', searchTerm) .where('name', '<=', searchTerm + '\uf8ff') .get(); const pastMKSnapshot = await firebase .firestore() .collection('PastMK') .where('name', '>=', searchTerm) .where('name', '<=', searchTerm + '\uf8ff') .get(); const futureMKData = futureMKSnapshot.docs.map((doc) => ({ id: doc.id, ...doc.data(), })); const pastMKData = pastMKSnapshot.docs.map((doc) => ({ id: doc.id, ...doc.data(), })); const results = [...futureMKData, ...pastMKData].filter((item) => item.name.toLowerCase().includes(searchTerm.toLowerCase()) ); const resultWithImages = await Promise.all( results.map(async (item) => { try { const imagePath = item.image; const imageRef = firebase.storage().ref().child(imagePath); const url = await imageRef.getDownloadURL(); return { ...item, image: url }; } catch (error) { console.log('Error loading image:', error); return item; } }) ); setSearchResult(resultWithImages); navigation.navigate('Search', { results: resultWithImages }); };
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.