main props
This commit is contained in:
parent
f492f2efb9
commit
a26865508a
@ -13,9 +13,6 @@ function App() {
|
|||||||
const [cardInfo, setCardInfo] = useState([]);
|
const [cardInfo, setCardInfo] = useState([]);
|
||||||
const [userData, setUserData] = useState({});
|
const [userData, setUserData] = useState({});
|
||||||
|
|
||||||
const selectedCity = userData.selectedCity;
|
|
||||||
const identification = userData.unique;
|
|
||||||
|
|
||||||
const handleButtonValue = (value) => {
|
const handleButtonValue = (value) => {
|
||||||
setIsHidden(true);
|
setIsHidden(true);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@ -29,7 +26,6 @@ function App() {
|
|||||||
axios.get('https://easytravel.zetcraft.ru/v1/GetAllCards')
|
axios.get('https://easytravel.zetcraft.ru/v1/GetAllCards')
|
||||||
.then(response => {
|
.then(response => {
|
||||||
setCardInfo(response.data);
|
setCardInfo(response.data);
|
||||||
console.log(cardInfo.length);
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('Error fetching data:', error);
|
console.error('Error fetching data:', error);
|
||||||
@ -39,7 +35,6 @@ function App() {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log(userData);
|
|
||||||
// Загрузка userData из localStorage при монтировании компонента
|
// Загрузка userData из localStorage при монтировании компонента
|
||||||
const savedUserData = JSON.parse(localStorage.getItem('userData'));
|
const savedUserData = JSON.parse(localStorage.getItem('userData'));
|
||||||
if (savedUserData) {
|
if (savedUserData) {
|
||||||
@ -62,7 +57,7 @@ function App() {
|
|||||||
content = <Tinder getValue={handleButtonValue} cardInfo={cardInfo} userData={userData} setUserData={setUserData} />
|
content = <Tinder getValue={handleButtonValue} cardInfo={cardInfo} userData={userData} setUserData={setUserData} />
|
||||||
break;
|
break;
|
||||||
case '/main':
|
case '/main':
|
||||||
content = <Main userData={userData} selectedCity={selectedCity} identification={identification} />
|
content = <Main />
|
||||||
break;
|
break;
|
||||||
case '/city':
|
case '/city':
|
||||||
content = <City getValue={handleButtonValue} setUserData={setUserData} />
|
content = <City getValue={handleButtonValue} setUserData={setUserData} />
|
||||||
@ -75,7 +70,7 @@ function App() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`App ${isHidden ? 'hidden' : ''}`}>
|
<div className={`App ${isHidden ? 'hidden' : ''}`}>
|
||||||
{arrayLength !== 0 ? <Main /> : content }
|
{arrayLength !== 0 ? <Main userData={userData}/> : content}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,8 @@ const City = (props) => {
|
|||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
route('/second')
|
route('/second')
|
||||||
setUserData(prevUserData => ({ ...prevUserData, selectedCity: selectedCity}));
|
setUserData({selectedCity: selectedCity});
|
||||||
|
console.log(selectedCity);
|
||||||
}}
|
}}
|
||||||
className="animated-button"
|
className="animated-button"
|
||||||
style={{
|
style={{
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
import React, {useState, useEffect} from "react";
|
import React, { useEffect } from "react";
|
||||||
|
|
||||||
|
const Main = ({userData}) => {
|
||||||
const Main = (props) => {
|
|
||||||
|
|
||||||
const city = props.selectedCity;
|
|
||||||
const id = props.identification;
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log(city && id);
|
console.log(userData.selectedCity);
|
||||||
|
console.log(userData.unique);
|
||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -44,7 +44,9 @@ const Tinder = (props) => {
|
|||||||
var uniqueIds = [...new Set(allIds)];
|
var uniqueIds = [...new Set(allIds)];
|
||||||
if(uniqueIds.length === cardInfo.length) {
|
if(uniqueIds.length === cardInfo.length) {
|
||||||
route('/main');
|
route('/main');
|
||||||
setUserData(prevUserData => ({ ...prevUserData, unique }));
|
setUserData(prevUserData => ({ ...prevUserData, unique: unique }));
|
||||||
|
console.log(unique);
|
||||||
|
console.log(props.userData);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user