This commit is contained in:
= 2023-05-29 10:48:15 +03:00
parent 6b07040476
commit f4aa746dc9
11 changed files with 52 additions and 38 deletions

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}

View File

@ -48,16 +48,8 @@
"react-app/jest" "react-app/jest"
] ]
}, },
"browserslist": { "browserslist": [
"production": [ "defaults",
">0.2%", "not ie 11"
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
] ]
} }
}

View File

@ -1 +1 @@
export const origin = 'https://dev2.akarpov.ru/' export const origin = 'https://0e06-92-100-146-65.ngrok-free.app/'

View File

@ -7,9 +7,18 @@ import axios from "axios";
// }); // });
export const backend = axios.create({ export let backend = axios.create({
baseURL: 'https://0e06-92-100-146-65.ngrok-free.app/api/', baseURL: 'https://0e06-92-100-146-65.ngrok-free.app/api/',
timeout: 100000, timeout: 100000,
headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')} headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}
} }
) )
export const updateBackend = () =>{
backend = axios.create({
baseURL: 'https://0e06-92-100-146-65.ngrok-free.app/api/',
timeout: 100000,
headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}
}
)
}

View File

@ -25,6 +25,7 @@ export const Login: react.FC = () => {
<Input placeholder='Пароль' className='reg-input' onChange={setPassword}/> <Input placeholder='Пароль' className='reg-input' onChange={setPassword}/>
<Button className='' onClick={() => { <Button className='' onClick={() => {
signin(username, password).then((e) => { signin(username, password).then((e) => {
console.log(e)
localStorage.setItem('token', e.access); localStorage.setItem('token', e.access);
localStorage.setItem('firstAuth', 'true'); localStorage.setItem('firstAuth', 'true');
@ -36,9 +37,9 @@ export const Login: react.FC = () => {
<span>или</span> <span>или</span>
<div className="sep-item"></div> <div className="sep-item"></div>
</div> </div>
<YandexLogin clientID={clientID} onSuccess={() => {}}> <Button className='login-btn-y' onClick={()=>navigate('/register')}>Зарегистрироваться</Button>
<button className="btn-y">Yandex login</button>
</YandexLogin>
</Block> </Block>
</div> </div>
} }

View File

@ -20,8 +20,7 @@
width: 400px; width: 400px;
} }
.btn-y{ .login-btn-y{
width: 440px!important;
background-color: #FFCF08; background-color: #FFCF08;
border-radius: 10px; border-radius: 10px;
padding: 15px 50px; padding: 15px 50px;

View File

@ -1,7 +1,7 @@
import { AutoComplete, DatePicker, Input, Checkbox, Select, Radio, Space, Spin } from 'antd'; import { AutoComplete, DatePicker, Input, Checkbox, Select, Radio, Space, Spin } from 'antd';
import react, { useEffect, useState } from 'react' import react, { useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
import { backend } from '../../consts'; import { backend, updateBackend } from '../../consts';
import { Button } from '../../elements/Button'; import { Button } from '../../elements/Button';
import { FavoriteCard, FavoriteCardIE } from '../../elements/FavoriteCard'; import { FavoriteCard, FavoriteCardIE } from '../../elements/FavoriteCard';
import { GenerateCard } from '../../elements/GenerateCard'; import { GenerateCard } from '../../elements/GenerateCard';
@ -21,10 +21,10 @@ export const Main: react.FC = () => {
let navigate = useNavigate() let navigate = useNavigate()
let token = localStorage.getItem('token') let token = localStorage.getItem('token')
let firstAuth = localStorage.getItem('firstAuth') let firstAuth = localStorage.getItem('firstAuth')
console.log(token)
useEffect(()=>{ useEffect(()=>{
updateBackend()
if (null == localStorage.getItem('token')){ if (null == localStorage.getItem('token')){
navigate('/login') navigate('/login')
} }

View File

@ -38,9 +38,8 @@ export const Register: react.FC = () => {
<span>или</span> <span>или</span>
<div className="sep-item"></div> <div className="sep-item"></div>
</div> </div>
<YandexLogin clientID={clientID} onSuccess={() => {}}> <Button className='login-btn-y' onClick={()=>navigate('/login')}>Войти</Button>
<button className="btn-y">Yandex login</button>
</YandexLogin>
</Block> </Block>
</div> </div>
} }

View File

@ -20,8 +20,7 @@
width: 400px; width: 400px;
} }
.btn-y{ .login-btn-y{
width: 440px!important;
background-color: #FFCF08; background-color: #FFCF08;
border-radius: 10px; border-radius: 10px;
padding: 15px 50px; padding: 15px 50px;

View File

@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react"; import React, { useEffect, useRef, useState } from "react";
import { useParams } from "react-router-dom"; import { useParams } from "react-router-dom";
import { backend } from "../../consts"; import { backend } from "../../consts";
import { RouteCard, RouteCardIE } from "../../elements/RouteCard"; import { RouteCard, RouteCardIE } from "../../elements/RouteCard";
@ -15,14 +15,26 @@ export const SearchPage:React.FC = () =>{
const [data, setData] = useState([]) const [data, setData] = useState([])
const [events, setEvents] = useState([]) const [events, setEvents] = useState([])
const queried = useRef(false);
useEffect(()=>{ useEffect(()=>{
if (cities.length == 0){
backend.get('/data/cities').then((response)=>setCities(response.data))
backend.post('/route/build',JSON.parse(prefs as string)).then((r)=>setData(r.data as any))
backend.post('/recommendations/build_events/',JSON.parse(prefs as string)).then((r)=>setEvents(r.data as any))
}
})
const dataLoad = async (prefs: string) => {
const cities = await backend.get('/data/cities')
const routes = await backend.post('/route/build',JSON.parse(prefs as string))
const events = await backend.post('/recommendations/build_events/',JSON.parse(prefs as string))
return {
cities, routes, events
}
}
if (!queried.current) {
queried.current = true;
dataLoad(prefs as string).then((data) => {
setCities(data.cities.data as any);
setData(data.routes.data as any);
setEvents(data.events.data as any);
})
}
}, [prefs])
console.log(events) console.log(events)
let newData; let newData;

View File

@ -1,5 +1,5 @@
import { import {
createBrowserRouter createBrowserRouter, createHashRouter
} from 'react-router-dom' } from 'react-router-dom'
import App from './App' import App from './App'
import { Register } from './pages/Register'; import { Register } from './pages/Register';
@ -7,8 +7,8 @@ import { Login } from './pages/Login';
import { Main } from './pages/Main'; import { Main } from './pages/Main';
import { EventMatch } from './pages/EventMatch'; import { EventMatch } from './pages/EventMatch';
import { GenerateTour } from './pages/GenerateTour'; import { GenerateTour } from './pages/GenerateTour';
import { Prefernces } from './elements/Prefernces';
import { SearchPage } from './pages/SearchPage'; import { SearchPage } from './pages/SearchPage';
import { Prefernces } from './elements/Prefernces';
const routes = [ const routes = [
@ -47,4 +47,4 @@ const routes = [
] ]
export const router = createBrowserRouter(routes); export const router = createHashRouter(routes);