hi i need to do that when user clicks on Забронировать they can see lil info about that…
- User
hi i need to do that when user clicks on Забронировать they can see lil info about that post in their profile 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 [userAuthenticated, setUserAuthenticated] = useState(false); useEffect(() => { const unsubscribe = firebase.auth().onAuthStateChanged(user => { if (user) { setUserAuthenticated(true); } else { setUserAuthenticated(false); } });
return unsubscribe; }, []); const {mkData}=route.params; const navigation = useNavigation(); const bookMK=()=>{ const currentUserID=firebase.auth().currentUser.uid; const bookedMKData={ name:mkData.name, time:mkData.time.toDate().toISOString(), image:mkData.image, price:mkData.price }; firebase .database() .ref(`users/${currentUserID}/bookedMK`) .push(bookedMKData) .then(()=>{ navigation.navigate('Profile'); }) }return ( {mkData.name} {moment(mkData.time.toDate()).format('Do MMM YYYY')} Цена: {mkData.price} Р. {mkData.description} {mkData.person} человек {mkData.timeOfMK} час(а) {userAuthenticated ? <Pressable style={gStyle.SupMoreDetails} onPress={()=>navigation.navigate('Profile')} > Забронировать : <Pressable style={gStyle.SupMoreDetails} onPress={()=>navigation.navigate('Auth')} > Забронировать } {/ Забронировать /} ); }
import { Text, View, Image, ScrollView, Pressable } from 'react-native'; import Header from '../components/Header'; import Footer from '../components/Footer'; import { gStyle } from '../styles/style'; import { firebase } from '../Firebase/firebase'; import 'firebase/compat/auth'; import 'firebase/compat/database'; import 'firebase/compat/firestore'; import React, {useState, useEffect} from 'react'; import { useNavigation } from '@react-navigation/native';
export default function Profile() { const navigation = useNavigation(); const [userId, setUserId]=useState(null); const [userData, setUserData] = useState(null); const [bookedMK, setBookedMK] = useState([]); useEffect(()=>{ const unsubscribe=firebase.auth().onAuthStateChanged((user)=>{ if(user){ setUserId(user.uid); }else{ setUserId(null); } }); return()=>unsubscribe(); },[]) useEffect(() => { if(userId){ const userRef=firebase.database().ref(
users/${userId}); userRef.on('value', snapshot=>{ const data = snapshot.val(); setUserData(data); },[userId]); const bookedMKRef = firebase.database().ref(); bookedMKRef.on('value', snapshot => { const data = snapshot.val(); if (data) { const mk = Object.values(data); setBookedMK(mk); } else { setBookedMK([]); } }); - Assistant
- User
- Assistant
The error message "Objects are not valid as a React child" suggests that we cannot directly render a date object in our view. Instead, we need to convert the
mk.timevalue to a string format before displaying it.One way of doing this conversion is by using the
toISOString()method on themk.timeobject and then parsing it to a readable date string. Here's an updated version of the code that includes this conversion:<Text style={gStyle.ProfileDate}>{new Date(mk.time?.seconds * 1000).toLocaleString()}</Text>In this code, we first access the
secondsproperty of themk.timeobject and multiply it by 1000 to get the timestamp in milliseconds. We then create a newDateobject with this timestamp and use thetoLocaleString()method to convert it into a readable date string.By wrapping this code in
new Date(), we create a newDateobject which can be used by thetoLocaleString()method.With this updated code, the date in the
bookedMKobject should now be displayed properly in your component. - User
i need to show only hours and minutes in time
- Assistant
To show only the hours and minutes in the time value of the
bookedMKobject, you can use thetoLocaleTimeString()method instead of thetoLocaleString()method when formatting the date string. Here's an updated version of the code that includes this change:<Text style={gStyle.ProfileDate}>{new Date(mk.time?.seconds * 1000).toLocaleTimeString()}</Text>By using the
toLocaleTimeString()method, we can format the date string to show only the hours and minutes in the time value. - User
how to show day and month?
- Assistant
To show the day and month in the date of the
bookedMKobject, you can use thetoLocaleString()method with the appropriate options to format the date string. Here's an
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.