From c6e547f4d6e8512ce19d713e114f3b93f39cce8e Mon Sep 17 00:00:00 2001 From: = <=> Date: Mon, 29 May 2023 10:57:38 +0300 Subject: [PATCH] add tinder --- src/client/index.ts | 161 ++++++++++++++++---------- src/pages/EventMatch/index.tsx | 202 ++++++++++++++++++--------------- src/pages/EventMatch/style.css | 54 +++++++-- 3 files changed, 258 insertions(+), 159 deletions(-) diff --git a/src/client/index.ts b/src/client/index.ts index 6a2581d..e316436 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -1,60 +1,103 @@ -import axios from 'axios'; -import { origin } from './config'; - - -export const register = async (username: string, password: string) => { - await axios.post( - origin + 'api/auth/register/', - { - 'username': username, - 'email': username, - 'password': password - } - ) -} - -export const signin = async (username: string, password: string) => { - const response = await axios.post( - origin + 'api/auth/token/', - { - 'username': username, - 'password': password - } - ); - return response.data; -} - - -export const startTinder = async () => { - const data = await axios.get( - origin + 'api/tinder/start', - { - headers: { - 'Authorization': 'Bearer ' + localStorage.getItem('token') - } - } - ); - return data.data; -} - -export const swipe = async (itemId: string, type: string) => { - var url = origin + 'api/tinder/' + itemId + '/proceed/'; - console.log(url, itemId) - try{ - const data = await axios.post( - url, - { - 'action': type, - }, - { - headers: { - 'Authorization': 'Bearer ' + localStorage.getItem('token') - } - } - ); - return data.data; - } catch { - return false - } - +import axios from 'axios'; +import { origin } from './config'; + + +export const register = async (username: string, password: string) => { + await axios.post( + origin + 'api/auth/register/', + { + 'username': username, + 'email': username, + 'password': password + } + ) +} + +export const signin = async (username: string, password: string) => { + const response = await axios.post( + origin + 'api/auth/token/', + { + 'username': username, + 'password': password + } + ); + return response.data; +} + + +export const startTinder = async () => { + const data = await axios.get( + origin + 'api/tinder/start', + { + headers: { + 'Authorization': 'Bearer ' + localStorage.getItem('token') + } + } + ); + return data.data; +} + +export const swipe = async (itemId: string, type: string) => { + var url = origin + 'api/tinder/' + itemId + '/proceed/'; + console.log(url, itemId) + try{ + const data = await axios.post( + url, + { + 'action': type, + }, + { + headers: { + 'Authorization': 'Bearer ' + localStorage.getItem('token') + } + } + ); + return data.data; + } catch { + return false + } + +} + +export const dailySelectionGenerate = async () => { + var data = await axios.get( + origin + 'api/recommendations/get_daily_selection/', + { + headers: { + 'Authorization': 'Bearer ' + localStorage.getItem('token') + } + } + ); + return data.data; +} + +export const dailySelectionBuild = async (buildData: any) => { + var data = await axios.post( + origin + 'api/recommendations/generate_daily_selection/', + {nodes: buildData}, + { + headers: { + 'Authorization': 'Bearer ' + localStorage.getItem('token') + } + } + ); + return data.data; +} + + +export const saveTinderPath = async (tinderData: any) => { + await axios.post( + origin + 'api/route/save', { + "points": [{ + date: '2000-01-01', + paths: tinderData + },] + }, + + { + headers: { + 'Authorization': 'Bearer ' + localStorage.getItem('token') + } + } + ) } \ No newline at end of file diff --git a/src/pages/EventMatch/index.tsx b/src/pages/EventMatch/index.tsx index b9ed8e8..f9c3f2c 100644 --- a/src/pages/EventMatch/index.tsx +++ b/src/pages/EventMatch/index.tsx @@ -1,93 +1,111 @@ -import react, { useRef } from 'react' -import TinderCard from 'react-tinder-card' -import './style.css' -import { Block } from '../../elements/Block' -import { Card, TinderCardContent } from '../../elements/Card' -import { Button } from '../../elements/Button' -import { startTinder, swipe, } from '../../client' -import {useNavigate} from 'react-router-dom'; - -interface IEventData{ - title: string; - description: string; - id: string; -} - - -export const EventMatch: react.FC = () => { - const ref = useRef(null); - const navigate = useNavigate(); - const started = useRef(false); - const swiping = useRef(false); - const [cardData, setCardData] = react.useState({title: "", description: "", id: ''} as IEventData); - const data = react.useRef({title: "", description: "", id: ''} as IEventData) - - - if (!started.current) { - started.current = true; - startTinder().then((e) => { - - data.current = { - title: e.title, - description: e.description.split(' ').slice(0, 10).join(' '), - id: e.oid - }; - setCardData({ - title: e.title, - description: e.description.split(' ').slice(0, 10).join(' '), - id: e.oid - }); - }) - } - - - return
- - { - console.log("swipe"); - if (swiping.current) return; - swiping.current = true; - swipe(data.current.id, type).then((e) => { - if (!e) { - navigate('/'); - return; - } - data.current = { - title: e.event.title, - description: e.event.description.split(' ').slice(0, 10).join(' '), - id: e.event.oid - }; - setCardData( - { - title: e.event.title, - description: e.event.description.split(' ').slice(0, 10).join(' '), - id: e.event.oid - } - ); - setTimeout(() => { - (ref.current as any).restoreCard(); - swiping.current = false; - }, 2000); - }) - - }}> - - - - - - - - - - - -
+import react, { useRef, useState } from 'react' +import TinderCard from 'react-tinder-card' +import './style.css' +import { Block } from '../../elements/Block' +import { Card, TinderCardContent } from '../../elements/Card' +import { Button } from '../../elements/Button' +import { dailySelectionBuild, dailySelectionGenerate, saveTinderPath, startTinder, swipe, } from '../../client' +import {useNavigate} from 'react-router-dom'; +import { MyMap } from '../../elements/map' + +interface IEventData{ + title: string; + description: string; + id: string; +} + + +export const EventMatch: react.FC = () => { + const ref = useRef(null); + const navigate = useNavigate(); + const started = useRef(false); + const [dailyData, setDailyData] = useState([]); + const [resData, setResData] = useState([]); + const queried = useRef(false); + const [answerData, setAnswerData] = useState([]); + + if (!started.current) { + started.current = true; + dailySelectionGenerate().then((e) => { + console.log(e) + setDailyData(e.events); + }) + } + + return
+ + { + dailyData.map((e) => { + return { + console.log(dailyData.indexOf(e)) + if (dailyData.indexOf(e) == 0) { + if (!resData.length) return; + if (!queried.current) { + dailySelectionBuild(resData).then((e) => { + setAnswerData(e.path); + }); + queried.current = true; + } + } + + if (type == 'right') { + setResData(resData.concat([ + { + 'action': 'right', + 'oid': (e as any).oid + } as any + ])) + } + + }} + > + + + + + + }) + } +
+ { + dailyData.length && !answerData.length ? + (!queried.current ? +
Вы не выбрали ни одного события, Мы не можем сгенерировать вам маршрут. Возвращяйтесь к нам завтра. { + navigate('/'); + }} + >Вернуться на главную
: Подождите немного, мы генерируем для вас ежедневный маршрут) : answerData.length ? e.type == 'point').map((e: any) => {return { + cords: [e.point.lat, e.point.lon], + title: e.point.title, + description: "" + }}) + + }> : <> + } + { + answerData.length ?
+ + +
: <> + } +
+ +
+
} \ No newline at end of file diff --git a/src/pages/EventMatch/style.css b/src/pages/EventMatch/style.css index e421adb..b92a5ec 100644 --- a/src/pages/EventMatch/style.css +++ b/src/pages/EventMatch/style.css @@ -1,9 +1,47 @@ -.tinder-block{ - width: 700px; - display: flex; - justify-content: center; -} - -.main-btn{ - background-color: #FFCF08; +.tinder-block{ + width: 700px; + display: flex; + justify-content: center; +} + +.main-btn{ + background-color: #FFCF08; +} + +.tinder-block{ + height: 600px; +} + +.card{ + position: absolute; +} +.span-er{ + width: 250px; + text-align: center; +} +a{ + color: black; +} +a:visited{ + color: black; +} + +.btns{ + display: flex; + flex-direction: column; + gap: 10px; + margin-top: 20px; +} + +.cont-span{ + display: flex; + justify-content: center; + flex-direction: column; + width: 500px; +} + +.span-cont{ + display: flex; + justify-content: center; + } \ No newline at end of file