I have two collections (FutureMK, PastMK). User searchs for smth and gets the result,…
- User
I have two collections (FutureMK, PastMK). User searchs for smth and gets the result, after that they can look into details by clicking Подробнее import { Text, View, Image, Pressable } from 'react-native'; import { gStyle } from '../styles/style'; import React from 'react';
export default function Result({ item }) {
return ( <View style={[gStyle.bookedMK, {flex:1}]}> <View style={{ flexDirection: 'column' }}> {item.name} {item.description.length > 100 ? item.description.substring(0, 100)+'...' : item.description } Подробнее
); }
and i have already have two screens for PastMK import { Text, View, Image, ScrollView, Pressable} from 'react-native'; import { gStyle } from '../styles/style'; import Header from '../components/Header'; import Footer from '../components/Footer'; import { useNavigation } from '@react-navigation/native'; import moment from 'moment'; import { useEffect, useState } from 'react';
export default function PastMKInfo({route}) { const [pastMK, setPastMK]=useState([]); useEffect(()=>{ const pastMKRef=firebase.firestore().collection('PastMK'); pastMKRef.onSnapshot((querySnapshot)=>{ const list=[]; querySnapshot.forEach((doc)=>{ const {name, time, description, image}=doc.data(); list.push({ id:doc.id, name, description, image, time, collection:'PastMK' }) }) setPastMK(list); }); return()=>pastMKRef(); },[]); const navigation = useNavigation(); const {mkData}=route.params; const handleGoBack=()=>{ navigation.goBack(); };
return ( {mkData.name} {new Intl.DateTimeFormat('ru-RU',{ day:'numeric', month:'long', year:'numeric' }).format(mkData.time.toDate())} {mkData.description} Назад ); }
and the FutureMK import { Text, View, Image, Pressable, ScrollView } from 'react-native'; import { gStyle } from '../styles/style'; import React, {useState, useEffect} from 'react'; import Header from '../components/Header'; import Footer from '../components/Footer'; import { Ionicons, MaterialCommunityIcons } from '@expo/vector-icons'; import { useNavigation } from '@react-navigation/native'; import moment from 'moment'; import {firebase} from '../Firebase/firebase'; import 'firebase/compat/auth'; import 'firebase/compat/database'; import 'firebase/compat/firestore';
export default function SignUpForMK({route}) { const [futureMK, setFutureMK]=useState([]); useEffect(()=>{ const futureMKRef = firebase.firestore().collection('FutureMK'); futureMKRef.onSnapshot((querySnapshot)=>{ const list =[]; querySnapshot.forEach((doc)=>{ const {name, time, description, image}=doc.data(); list.push({ id:doc.id, name, time, description, image, collection:'FutureMK' }) }); setFutureMK(list); }); return()=>futureMKRef(); },[]);
code - Assistant
You can use the
useNavigationhook from in the component and pass the collection name and of the item as params to navigate to the corresponding screen.