diff --git a/src/App.js b/src/App.js index 42b350a..ca7553e 100644 --- a/src/App.js +++ b/src/App.js @@ -1,4 +1,4 @@ -import React, {useState, useEffect} from 'react'; +import React, { useState, useEffect } from 'react'; import Start from './components/Start/Start'; import Second from './components/Second/Second'; import Tinder from './components/Tinder/Tinder'; @@ -8,10 +8,13 @@ import axios from 'axios'; import './App.css'; function App() { - const [buttonValue, setButtonValue] = useState(""); const [isHidden, setIsHidden] = useState(false); const [cardInfo, setCardInfo] = useState([]); + const [userData, setUserData] = useState({}); + + const selectedCity = userData.selectedCity; + const identification = userData.unique; const handleButtonValue = (value) => { setIsHidden(true); @@ -35,26 +38,44 @@ function App() { fetchData(); }, []); + useEffect(() => { + console.log(userData); + // Загрузка userData из localStorage при монтировании компонента + const savedUserData = JSON.parse(localStorage.getItem('userData')); + if (savedUserData) { + setUserData(savedUserData); + } + }, []); + + useEffect(() => { + // Сохранение userData в localStorage при изменении + localStorage.setItem('userData', JSON.stringify(userData)); + console.log(userData); + }, [userData]); + let content = null; switch (buttonValue) { case '/second': - content = + content = break; case '/tinder': - content = + content = break; case '/main': - content =
+ content =
break; case '/city': - content = - break; - default: content = + content = + break; + default: + content = } + const arrayLength = userData.unique ? userData.unique.length : 0; + return (
- {content} + {arrayLength !== 0 ?
: content }
); } diff --git a/src/components/City/City.js b/src/components/City/City.js index aabd2c3..f0143bb 100644 --- a/src/components/City/City.js +++ b/src/components/City/City.js @@ -3,6 +3,7 @@ import axios from "axios"; const City = (props) => { const route = props.getValue; + const setUserData = props.setUserData const [cityOptions, setCityOptions] = useState([]); const [filteredCityOptions, setFilteredCityOptions] = useState([]); @@ -71,7 +72,7 @@ const City = (props) => { justifyContent: 'center', width: 304, }}> - # @@ -106,7 +107,10 @@ const City = (props) => { gap: 10, }}>