mirror of
https://github.com/task-17-lct/frontend.git
synced 2024-11-22 09:46:35 +03:00
add all
This commit is contained in:
parent
10b2843fe6
commit
ae76b47d3a
|
@ -3,10 +3,10 @@
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@react-spring/web": "^9.7.2",
|
|
||||||
"@bem-react/classname": "^1.6.0",
|
"@bem-react/classname": "^1.6.0",
|
||||||
"@bem-react/core": "^5.1.0",
|
"@bem-react/core": "^5.1.0",
|
||||||
"@bem-react/di": "^5.0.0",
|
"@bem-react/di": "^5.0.0",
|
||||||
|
"@react-spring/web": "^9.7.2",
|
||||||
"@testing-library/jest-dom": "^5.16.5",
|
"@testing-library/jest-dom": "^5.16.5",
|
||||||
"@testing-library/react": "^13.4.0",
|
"@testing-library/react": "^13.4.0",
|
||||||
"@testing-library/user-event": "^13.5.0",
|
"@testing-library/user-event": "^13.5.0",
|
||||||
|
|
1
src/client/config.ts
Normal file
1
src/client/config.ts
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export const origin = 'https://dev2.akarpov.ru/'
|
60
src/client/index.ts
Normal file
60
src/client/index.ts
Normal file
|
@ -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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -12,14 +12,19 @@ export const Card: react.FC<ICard> = (props) => {
|
||||||
return <div className={'card__container ' + props.className}>{props.children}</div>
|
return <div className={'card__container ' + props.className}>{props.children}</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TinderCardContent: react.FC = (props) => {
|
|
||||||
|
interface ITinderCard{
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const TinderCardContent: react.FC<ITinderCard> = (props) => {
|
||||||
return <Card className='tinder-card__card'>
|
return <Card className='tinder-card__card'>
|
||||||
<img src='/sample.jpg' width={200} height={200}></img>
|
<img src='/sample.jpg' width={200} height={200}></img>
|
||||||
<div className="tinder__content">
|
<div className="tinder__content">
|
||||||
<span><strong>Отель:</strong> Ромашка</span>
|
<span><strong>Название:</strong> {props.title}</span>
|
||||||
<span><strong>Звезд:</strong> 4</span>
|
|
||||||
|
|
||||||
<span><strong>Описание: </strong>Очень хороший отель с видом на море</span>
|
<span><strong>Описание: </strong>{props.description}</span>
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
}
|
}
|
|
@ -4,8 +4,18 @@ import './style.css'
|
||||||
interface IInput{
|
interface IInput{
|
||||||
placeholder: string;
|
placeholder: string;
|
||||||
className: string;
|
className: string;
|
||||||
|
onChange?: (content: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Input: react.FC<IInput> = (props) => {
|
export const Input: react.FC<IInput> = (props) => {
|
||||||
return <input type="text" className={'input__container ' +props.className} placeholder={props.placeholder}/>
|
var onChange = props.onChange;
|
||||||
|
if (!onChange) {
|
||||||
|
onChange = (e: string) => {}
|
||||||
|
}
|
||||||
|
return <input
|
||||||
|
type="text"
|
||||||
|
className={'input__container ' +props.className}
|
||||||
|
placeholder={props.placeholder}
|
||||||
|
onChange={(e) => (onChange as any)(e.target.value)}
|
||||||
|
/>
|
||||||
}
|
}
|
|
@ -4,23 +4,78 @@ import './style.css'
|
||||||
import { Block } from '../../elements/Block'
|
import { Block } from '../../elements/Block'
|
||||||
import { Card, TinderCardContent } from '../../elements/Card'
|
import { Card, TinderCardContent } from '../../elements/Card'
|
||||||
import { Button } from '../../elements/Button'
|
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 = () => {
|
export const EventMatch: react.FC = () => {
|
||||||
const ref = useRef(null);
|
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 <div className='centered tin'>
|
return <div className='centered tin'>
|
||||||
<Block className='tinder-block'>
|
<Block className='tinder-block'>
|
||||||
<TinderCard ref={ref} onSwipe={() => {
|
<TinderCard ref={ref} onSwipe={(type) => {
|
||||||
console.log("swipe");
|
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(() => {
|
setTimeout(() => {
|
||||||
(ref.current as any).restoreCard();
|
(ref.current as any).restoreCard();
|
||||||
|
swiping.current = false;
|
||||||
}, 2000);
|
}, 2000);
|
||||||
|
})
|
||||||
|
|
||||||
}}>
|
}}>
|
||||||
<Card className=''>
|
<Card className=''>
|
||||||
<TinderCardContent></TinderCardContent>
|
<TinderCardContent
|
||||||
|
title={data.current.title}
|
||||||
|
description={data.current.description}
|
||||||
|
></TinderCardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</TinderCard>
|
</TinderCard>
|
||||||
</Block>
|
</Block>
|
||||||
|
|
|
@ -3,6 +3,8 @@ import { Block } from '../../elements/Block'
|
||||||
import { Input } from '../../elements/Input'
|
import { Input } from '../../elements/Input'
|
||||||
import './style.css'
|
import './style.css'
|
||||||
import { Button } from '../../elements/Button'
|
import { Button } from '../../elements/Button'
|
||||||
|
import { register, signin } from '../../client'
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
const yandexConnect = require('react-yandex-login')
|
const yandexConnect = require('react-yandex-login')
|
||||||
|
|
||||||
|
@ -11,14 +13,25 @@ const clientID = '11e53cfa7add4c55b84168d408a22eb1';
|
||||||
|
|
||||||
|
|
||||||
export const Register: react.FC = () => {
|
export const Register: react.FC = () => {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const [username, setUseranme] = react.useState('');
|
||||||
|
const [password, setPassword] = react.useState('');
|
||||||
|
|
||||||
|
|
||||||
return <div className='centered'>
|
return <div className='centered'>
|
||||||
<Block className='reg-block'>
|
<Block className='reg-block'>
|
||||||
<h4>Регистрация</h4>
|
<h4>Регистрация</h4>
|
||||||
<Input placeholder='Почта' className='reg-input'/>
|
<Input placeholder='Почта' className='reg-input' onChange={setUseranme}/>
|
||||||
<Input placeholder='Пароль' className='reg-input'/>
|
<Input placeholder='Пароль' className='reg-input' onChange={setPassword}/>
|
||||||
<Input placeholder='Пароль еще раз' className='reg-input'/>
|
<Input placeholder='Пароль еще раз' className='reg-input'/>
|
||||||
<Button className=''>Зарегистрироваться</Button>
|
<Button className='' onClick={() => {
|
||||||
|
register(username, password).then((e) => {
|
||||||
|
signin(username, password).then((e) => {
|
||||||
|
localStorage.setItem('token', e.access);
|
||||||
|
navigate('/event-match')
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}}>Зарегистрироваться</Button>
|
||||||
<div className="separator">
|
<div className="separator">
|
||||||
<div className="sep-item"></div>
|
<div className="sep-item"></div>
|
||||||
<span>или</span>
|
<span>или</span>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user