From ae76b47d3a57c5bb1c33a7fbcbf4d3b83fa7b39c Mon Sep 17 00:00:00 2001 From: ilia Date: Mon, 22 May 2023 18:17:01 +0300 Subject: [PATCH] add all --- package.json | 2 +- src/client/config.ts | 1 + src/client/index.ts | 60 ++++++++++++++++++++++++++++++ src/elements/Card/index.tsx | 13 +++++-- src/elements/Input/index.tsx | 12 +++++- src/pages/EventMatch/index.tsx | 67 +++++++++++++++++++++++++++++++--- src/pages/Register/index.tsx | 19 ++++++++-- 7 files changed, 159 insertions(+), 15 deletions(-) create mode 100644 src/client/config.ts create mode 100644 src/client/index.ts diff --git a/package.json b/package.json index 0a146f5..acacc66 100644 --- a/package.json +++ b/package.json @@ -3,10 +3,10 @@ "version": "0.1.0", "private": true, "dependencies": { - "@react-spring/web": "^9.7.2", "@bem-react/classname": "^1.6.0", "@bem-react/core": "^5.1.0", "@bem-react/di": "^5.0.0", + "@react-spring/web": "^9.7.2", "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", diff --git a/src/client/config.ts b/src/client/config.ts new file mode 100644 index 0000000..7964b79 --- /dev/null +++ b/src/client/config.ts @@ -0,0 +1 @@ +export const origin = 'https://dev2.akarpov.ru/' \ No newline at end of file diff --git a/src/client/index.ts b/src/client/index.ts new file mode 100644 index 0000000..6a2581d --- /dev/null +++ b/src/client/index.ts @@ -0,0 +1,60 @@ +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 + } + +} \ No newline at end of file diff --git a/src/elements/Card/index.tsx b/src/elements/Card/index.tsx index f61bccc..a40f97c 100644 --- a/src/elements/Card/index.tsx +++ b/src/elements/Card/index.tsx @@ -12,14 +12,19 @@ export const Card: react.FC = (props) => { return
{props.children}
} -export const TinderCardContent: react.FC = (props) => { + +interface ITinderCard{ + title: string; + description: string; +} + +export const TinderCardContent: react.FC = (props) => { return
- Отель: Ромашка - Звезд: 4 + Название: {props.title} - Описание: Очень хороший отель с видом на море + Описание: {props.description}
} \ No newline at end of file diff --git a/src/elements/Input/index.tsx b/src/elements/Input/index.tsx index f3b46a4..a01de26 100644 --- a/src/elements/Input/index.tsx +++ b/src/elements/Input/index.tsx @@ -4,8 +4,18 @@ import './style.css' interface IInput{ placeholder: string; className: string; + onChange?: (content: string) => void; } export const Input: react.FC = (props) => { - return + var onChange = props.onChange; + if (!onChange) { + onChange = (e: string) => {} + } + return (onChange as any)(e.target.value)} + /> } \ No newline at end of file diff --git a/src/pages/EventMatch/index.tsx b/src/pages/EventMatch/index.tsx index 3fc6a44..b9ed8e8 100644 --- a/src/pages/EventMatch/index.tsx +++ b/src/pages/EventMatch/index.tsx @@ -4,23 +4,78 @@ 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); - var [createNew, setCreateNew] = react.useState(true); + 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"); - setTimeout(() => { - (ref.current as any).restoreCard(); - }, 2000); + 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); + }) + }}> - + diff --git a/src/pages/Register/index.tsx b/src/pages/Register/index.tsx index adbb732..3fbdbd2 100644 --- a/src/pages/Register/index.tsx +++ b/src/pages/Register/index.tsx @@ -3,6 +3,8 @@ import { Block } from '../../elements/Block' import { Input } from '../../elements/Input' import './style.css' import { Button } from '../../elements/Button' +import { register, signin } from '../../client' +import { useNavigate } from "react-router-dom"; const yandexConnect = require('react-yandex-login') @@ -11,14 +13,25 @@ const clientID = '11e53cfa7add4c55b84168d408a22eb1'; export const Register: react.FC = () => { + const navigate = useNavigate(); + const [username, setUseranme] = react.useState(''); + const [password, setPassword] = react.useState(''); + return

Регистрация

- - + + - +
или