нормальные роуты
This commit is contained in:
parent
30421a97da
commit
c682e08cf3
42
package-lock.json
generated
42
package-lock.json
generated
@ -18,6 +18,7 @@
|
|||||||
"matchmedia": "^0.1.2",
|
"matchmedia": "^0.1.2",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
|
"react-router-dom": "^6.15.0",
|
||||||
"react-scripts": "5.0.1",
|
"react-scripts": "5.0.1",
|
||||||
"react-swipeable": "^7.0.1",
|
"react-swipeable": "^7.0.1",
|
||||||
"react-tinder-card": "^1.6.2",
|
"react-tinder-card": "^1.6.2",
|
||||||
@ -34,8 +35,7 @@
|
|||||||
"workbox-routing": "^6.6.0",
|
"workbox-routing": "^6.6.0",
|
||||||
"workbox-strategies": "^6.6.0",
|
"workbox-strategies": "^6.6.0",
|
||||||
"workbox-streams": "^6.6.0"
|
"workbox-streams": "^6.6.0"
|
||||||
},
|
}
|
||||||
"devDependencies": {}
|
|
||||||
},
|
},
|
||||||
"node_modules/@aashutoshrathi/word-wrap": {
|
"node_modules/@aashutoshrathi/word-wrap": {
|
||||||
"version": "1.2.6",
|
"version": "1.2.6",
|
||||||
@ -3409,6 +3409,14 @@
|
|||||||
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@remix-run/router": {
|
||||||
|
"version": "1.8.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.8.0.tgz",
|
||||||
|
"integrity": "sha512-mrfKqIHnSZRyIzBcanNJmVQELTnX+qagEDlcKO90RgRBVOZGSGvZKeDihTRfWcqoDn5N/NkUcwWTccnpN18Tfg==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=14.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@rollup/plugin-babel": {
|
"node_modules/@rollup/plugin-babel": {
|
||||||
"version": "5.3.1",
|
"version": "5.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/plugin-babel/-/plugin-babel-5.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/plugin-babel/-/plugin-babel-5.3.1.tgz",
|
||||||
@ -14924,6 +14932,36 @@
|
|||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/react-router": {
|
||||||
|
"version": "6.15.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/react-router/-/react-router-6.15.0.tgz",
|
||||||
|
"integrity": "sha512-NIytlzvzLwJkCQj2HLefmeakxxWHWAP+02EGqWEZy+DgfHHKQMUoBBjUQLOtFInBMhWtb3hiUy6MfFgwLjXhqg==",
|
||||||
|
"dependencies": {
|
||||||
|
"@remix-run/router": "1.8.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=14.0.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": ">=16.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/react-router-dom": {
|
||||||
|
"version": "6.15.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.15.0.tgz",
|
||||||
|
"integrity": "sha512-aR42t0fs7brintwBGAv2+mGlCtgtFQeOzK0BM1/OiqEzRejOZtpMZepvgkscpMUnKb8YO84G7s3LsHnnDNonbQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"@remix-run/router": "1.8.0",
|
||||||
|
"react-router": "6.15.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=14.0.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": ">=16.8",
|
||||||
|
"react-dom": ">=16.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/react-scripts": {
|
"node_modules/react-scripts": {
|
||||||
"version": "5.0.1",
|
"version": "5.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/react-scripts/-/react-scripts-5.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/react-scripts/-/react-scripts-5.0.1.tgz",
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
"matchmedia": "^0.1.2",
|
"matchmedia": "^0.1.2",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
|
"react-router-dom": "^6.15.0",
|
||||||
"react-scripts": "5.0.1",
|
"react-scripts": "5.0.1",
|
||||||
"react-swipeable": "^7.0.1",
|
"react-swipeable": "^7.0.1",
|
||||||
"react-tinder-card": "^1.6.2",
|
"react-tinder-card": "^1.6.2",
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import Start from './components/Start/Start';
|
import { BrowserRouter, Routes, Route } from 'react-router-dom';
|
||||||
import Second from './components/Second/Second';
|
import Start from '../Start/Start';
|
||||||
import Tinder from './components/Tinder/Tinder';
|
import Second from '../Second/Second';
|
||||||
import Main from './components/Main/Main';
|
import Tinder from '../Tinder/Tinder';
|
||||||
import City from './components/City/City';
|
import Main from '../Main/Main';
|
||||||
|
import City from '../City/City';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import './App.css';
|
import './App.css';
|
||||||
|
|
||||||
@ -48,30 +49,17 @@ function App() {
|
|||||||
console.log(userData);
|
console.log(userData);
|
||||||
}, [userData]);
|
}, [userData]);
|
||||||
|
|
||||||
let content = null;
|
|
||||||
switch (buttonValue) {
|
|
||||||
case '/second':
|
|
||||||
content = <Second getValue={handleButtonValue}setUserData={setUserData} />
|
|
||||||
break;
|
|
||||||
case '/tinder':
|
|
||||||
content = <Tinder getValue={handleButtonValue} cardInfo={cardInfo} userData={userData} setUserData={setUserData} />
|
|
||||||
break;
|
|
||||||
case '/main':
|
|
||||||
content = <Main />
|
|
||||||
break;
|
|
||||||
case '/city':
|
|
||||||
content = <City getValue={handleButtonValue} setUserData={setUserData} />
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
content = <Start getValue={handleButtonValue} userData={userData} setUserData={setUserData} />
|
|
||||||
}
|
|
||||||
|
|
||||||
const arrayLength = userData.unique ? userData.unique.length : 0;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`App ${isHidden ? 'hidden' : ''}`}>
|
<BrowserRouter>
|
||||||
{arrayLength !== 0 ? <Main userData={userData}/> : content}
|
<Routes>
|
||||||
</div>
|
<Route path="/" element={<Start getValue={handleButtonValue} userData={userData} setUserData={setUserData} />}/>
|
||||||
|
<Route path="second" element={<Second getValue={handleButtonValue} setUserData={setUserData} />} />
|
||||||
|
<Route path="tinder" element={<Tinder getValue={handleButtonValue} cardInfo={cardInfo} userData={userData} setUserData={setUserData} />} />
|
||||||
|
<Route path="city" element={<City getValue={handleButtonValue} setUserData={setUserData} />} />
|
||||||
|
<Route path="main" element={<Main userData={userData}/>} />
|
||||||
|
</Routes>
|
||||||
|
</BrowserRouter>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -1,10 +1,13 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import './City.css'
|
import './City.css'
|
||||||
|
|
||||||
const City = (props) => {
|
const City = (props) => {
|
||||||
const route = props.getValue;
|
const route = props.getValue;
|
||||||
const setUserData = props.setUserData
|
const setUserData = props.setUserData
|
||||||
|
const second = useNavigate();
|
||||||
|
|
||||||
const [cityOptions, setCityOptions] = useState([]);
|
const [cityOptions, setCityOptions] = useState([]);
|
||||||
const [filteredCityOptions, setFilteredCityOptions] = useState([]);
|
const [filteredCityOptions, setFilteredCityOptions] = useState([]);
|
||||||
@ -111,7 +114,7 @@ const City = (props) => {
|
|||||||
<button
|
<button
|
||||||
className="animated-button"
|
className="animated-button"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
route('/second')
|
second('/second')
|
||||||
setUserData({selectedCity: selectedCity});
|
setUserData({selectedCity: selectedCity});
|
||||||
console.log(selectedCity);
|
console.log(selectedCity);
|
||||||
}}
|
}}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
import './style.css'
|
import './style.css'
|
||||||
import Icon from './images/Vector.svg'
|
import Icon from './images/Vector.svg'
|
||||||
|
|
||||||
@ -6,7 +7,8 @@ import Icon from './images/Vector.svg'
|
|||||||
const Second = (props) => {
|
const Second = (props) => {
|
||||||
|
|
||||||
const route = props.getValue;
|
const route = props.getValue;
|
||||||
|
const tinder = useNavigate();
|
||||||
|
const main = useNavigate();
|
||||||
return (
|
return (
|
||||||
<div style={{
|
<div style={{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
@ -41,8 +43,8 @@ const Second = (props) => {
|
|||||||
gap:15,
|
gap:15,
|
||||||
alignItems:'center',
|
alignItems:'center',
|
||||||
}}>
|
}}>
|
||||||
<button className="btn_first" onClick={() => route('/tinder')}>Давайте!</button>
|
<button className="btn_first" onClick={() => tinder('/tinder')}>Давайте!</button>
|
||||||
<button className="btn_second" onClick={() => route('/main')}>Пропустить</button>
|
<button className="btn_second" onClick={() => main('/main')}>Пропустить</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
@ -1,32 +1,38 @@
|
|||||||
import React, { useEffect } from "react";
|
import React, { useEffect } from "react";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
const Start = (props) => {
|
const Start = (props) => {
|
||||||
|
const history = useNavigate();
|
||||||
const route = props.getValue;
|
const kek = './circle.html';
|
||||||
const kek = './circle.html'
|
|
||||||
|
|
||||||
function hideAddressBar() {
|
function hideAddressBar() {
|
||||||
if (document.documentElement.scrollHeight < window.outerHeight / window.devicePixelRatio)
|
if (document.documentElement.scrollHeight < window.outerHeight / window.devicePixelRatio)
|
||||||
document.documentElement.style.height = (window.outerHeight / window.devicePixelRatio) + 'px';
|
document.documentElement.style.height = (window.outerHeight / window.devicePixelRatio) + 'px';
|
||||||
setTimeout(window.scrollTo(1, 1), 0);
|
setTimeout(window.scrollTo(1, 1), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener("load", function () { hideAddressBar(); });
|
window.addEventListener("load", function () { hideAddressBar(); });
|
||||||
window.addEventListener("orientationchange", function () { hideAddressBar(); });
|
window.addEventListener("orientationchange", function () { hideAddressBar(); });
|
||||||
|
|
||||||
|
const handleButtonClick = () => {
|
||||||
|
history('/city');
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handler = (ev: MessageEvent<{ type: string }>) => {
|
const frame = document.querySelector("#start");
|
||||||
if (typeof ev.data !== 'object') return
|
frame.addEventListener('load', () => {
|
||||||
if (!ev.data.type) return
|
frame.contentWindow.addEventListener('click', () => {
|
||||||
if (ev.data.type !== 'button-click') return
|
handleButtonClick();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
route('/city')
|
return () => {
|
||||||
}
|
frame.removeEventListener('load', () => {
|
||||||
|
frame.contentWindow.removeEventListener('click', () => {
|
||||||
window.addEventListener('message', handler)
|
});
|
||||||
|
});
|
||||||
// Don't forget to remove addEventListener
|
};
|
||||||
return () => window.removeEventListener('message', handler)
|
}, []);
|
||||||
}, [])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{
|
<div style={{
|
||||||
@ -55,8 +61,7 @@ const Start = (props) => {
|
|||||||
fontSize: '40px',
|
fontSize: '40px',
|
||||||
}}>Путешествия <p style={{ color: '#4EB0F2' }}>Просто!</p></span>
|
}}>Путешествия <p style={{ color: '#4EB0F2' }}>Просто!</p></span>
|
||||||
</div>
|
</div>
|
||||||
|
<iframe id="start" scrolling="no" src={kek} style={{
|
||||||
<iframe scrolling="no" src={kek} style={{
|
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
border: 'none',
|
border: 'none',
|
||||||
width: '440px',
|
width: '440px',
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
import TinderCard from 'react-tinder-card';
|
import TinderCard from 'react-tinder-card';
|
||||||
import './Tinder.css';
|
import './Tinder.css';
|
||||||
|
|
||||||
@ -7,6 +8,7 @@ const Tinder = (props) => {
|
|||||||
const route = props.getValue;
|
const route = props.getValue;
|
||||||
const cardInfo = props.cardInfo;
|
const cardInfo = props.cardInfo;
|
||||||
const setUserData = props.setUserData;
|
const setUserData = props.setUserData;
|
||||||
|
const main = useNavigate();
|
||||||
|
|
||||||
const [lastDirection, setLastDirection] = useState();
|
const [lastDirection, setLastDirection] = useState();
|
||||||
const [cardId, setCardId] = useState([]);
|
const [cardId, setCardId] = useState([]);
|
||||||
@ -51,7 +53,7 @@ const Tinder = (props) => {
|
|||||||
var unique = [...new Set(cardId)]
|
var unique = [...new Set(cardId)]
|
||||||
var uniqueIds = [...new Set(allIds)];
|
var uniqueIds = [...new Set(allIds)];
|
||||||
if(uniqueIds.length === cardInfo.length) {
|
if(uniqueIds.length === cardInfo.length) {
|
||||||
route('/main');
|
main('/main');
|
||||||
setUserData(prevUserData => ({ ...prevUserData, unique: unique }));
|
setUserData(prevUserData => ({ ...prevUserData, unique: unique }));
|
||||||
console.log(unique);
|
console.log(unique);
|
||||||
console.log(props.userData);
|
console.log(props.userData);
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom/client';
|
import ReactDOM from 'react-dom/client';
|
||||||
import './index.css';
|
import './index.css';
|
||||||
import App from './App';
|
import App from './components/App/App';
|
||||||
import * as serviceWorkerRegistration from './serviceWorkerRegistration';
|
import * as serviceWorkerRegistration from './components/ServiceWorkerRegistration/serviceWorkerRegistration';
|
||||||
import reportWebVitals from './reportWebVitals';
|
import reportWebVitals from './components/ReportWebVitals/reportWebVitals';
|
||||||
|
|
||||||
const root = ReactDOM.createRoot(document.getElementById('root'));
|
const root = ReactDOM.createRoot(document.getElementById('root'));
|
||||||
root.render(
|
root.render(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user