From c8a3049349b083fa14d4a72a818ef5f0562e17db Mon Sep 17 00:00:00 2001 From: Arseniy Sitnikov Date: Fri, 13 Dec 2024 15:26:27 +0300 Subject: [PATCH] add win popup --- .../AuctionMainPopups/AuctionMainPopups.tsx | 47 ++++++++++++- .../Auction/AuctionPopup/AuctionPopup.tsx | 2 +- frontend/src/shared/Auction/Timer/Timer.tsx | 1 + .../shared/Clicker/PointsZoom/PointsZoom.tsx | 15 ++-- .../shared/Pages/AuctionPage/AuctionPage.tsx | 4 +- .../src/shared/Pages/ErrorPage/ErrorPage.tsx | 7 +- .../src/shared/Pages/RoutePage/RoutePage.tsx | 42 ++++++++---- frontend/src/store/auction/actions.ts | 68 +++++++++++++++++-- frontend/src/store/friends/actions.ts | 1 + frontend/src/store/me/actions.ts | 4 ++ frontend/src/store/rank/actions.ts | 1 + frontend/src/utils/isWhiteList.js | 1 + 12 files changed, 163 insertions(+), 30 deletions(-) diff --git a/frontend/src/shared/Auction/AuctionMainPopups/AuctionMainPopups.tsx b/frontend/src/shared/Auction/AuctionMainPopups/AuctionMainPopups.tsx index 5c131f0..b380822 100644 --- a/frontend/src/shared/Auction/AuctionMainPopups/AuctionMainPopups.tsx +++ b/frontend/src/shared/Auction/AuctionMainPopups/AuctionMainPopups.tsx @@ -14,6 +14,51 @@ export function AuctionMainPopups() { const [closeAnim, setCloseAnim] = useState(false); const topAuctions = useAppSelector | undefined>(state=>state.me.data.topAuctions); const loseAuctions = useAppSelector | undefined>(state => state.me.data.loseAuctions); + const winAuctions = useAppSelector | undefined>(state => state.me.data.winAuctions); + const [winInfo, setWinInfo] = useState(); + + useEffect(() => { + let showWindow = false; + if (winAuctions && winAuctions.length != 0) { + for (let i = 0; i < winAuctions.length; i++) { + const winShow = localStorage.getItem('wS'); + if (winShow) { + const winArray = JSON.parse(winShow); + if (winArray && winArray.length != 0) { + let isExist = false; + for (let k = 0; k < winArray.length; k++) { + if (Number(winArray[k]) === Number(winAuctions[i].id)) { + isExist = true; + } + } + if(!isExist) { + winArray.push(winAuctions[i].id); + localStorage.setItem('wS', JSON.stringify(winArray)); + showWindow = true; + setWinInfo(winAuctions[i]); + } + } else { + const newArray = []; + newArray.push(winAuctions[i].id); + localStorage.setItem('wS', JSON.stringify(newArray)); + showWindow = true; + setWinInfo(winAuctions[i]); + } + } else { + const newArray = []; + newArray.push(winAuctions[i].id); + localStorage.setItem('wS', JSON.stringify(newArray)); + showWindow = true; + setWinInfo(winAuctions[i]); + } + } + } + + if(showWindow) { + setCloseWin(false); + } + + }, [winAuctions]); useEffect(() => { const show = sessionStorage.getItem('shT'); @@ -38,7 +83,7 @@ export function AuctionMainPopups() { return (
{!closeWin && + } />} {!closeTop && topAuctions != undefined && diff --git a/frontend/src/shared/Auction/AuctionPopup/AuctionPopup.tsx b/frontend/src/shared/Auction/AuctionPopup/AuctionPopup.tsx index 6eaa84b..a02b350 100644 --- a/frontend/src/shared/Auction/AuctionPopup/AuctionPopup.tsx +++ b/frontend/src/shared/Auction/AuctionPopup/AuctionPopup.tsx @@ -67,7 +67,7 @@ export function AuctionPopup({ setClose, setCloseErrorBet, auctionId, img, name, dispatch(updatePointsRequestAsync()); dispatch(updateAuction(auctionId)); setBet(bet); - setLead(true); + //setLead(true); const timer = setInterval(() => { setCloseResultPopup(false); clearTimeout(timer); diff --git a/frontend/src/shared/Auction/Timer/Timer.tsx b/frontend/src/shared/Auction/Timer/Timer.tsx index b7cde2f..63bb21e 100644 --- a/frontend/src/shared/Auction/Timer/Timer.tsx +++ b/frontend/src/shared/Auction/Timer/Timer.tsx @@ -16,6 +16,7 @@ export function Timer({initTime}: ITimer) { const tick = () => { if (hour === 0 && min === 0 && sec === 0) { setOver(true); + window.location.reload(); } else if (min === 0 && sec === 0) { setTime([hour - 1, 59, 59]); } else if (sec == 0) { diff --git a/frontend/src/shared/Clicker/PointsZoom/PointsZoom.tsx b/frontend/src/shared/Clicker/PointsZoom/PointsZoom.tsx index 95c38b6..ffc6966 100644 --- a/frontend/src/shared/Clicker/PointsZoom/PointsZoom.tsx +++ b/frontend/src/shared/Clicker/PointsZoom/PointsZoom.tsx @@ -49,24 +49,25 @@ export function PointsZoom({ points, sameInterval, setSameInterval, sameCoords, let initSameInterval = sameInterval; let avtTime = 500; if (points > 1) { - avtTime = clickTimeInit / (initPoints - 1); + avtTime = clickTimeInit / initPoints; } setClickTime(0); setSameCoords(false); - - if ((avtTime < 100 && initSameCoords) || (initSameInterval) && initPoints > 20) { - /*axios.post(`${URL}/api/v1/users/warn/`, {}, { + + if ((avtTime < 100 && initPoints > 20) || (avtTime < 130 && initPoints > 300)) { + + axios.post(`${URL}/api/v1/users/warn/`, {}, { headers: { "Authorization": `TelegramToken ${token}` } }).then(resp => { - console.log(resp); + //console.log(resp); }).catch(err => { //console.log(err) - })*/ - sendAutoClickData(userData.tgId, points, avtTime); + }) + //sendAutoClickData(userData.tgId, points, avtTime); setCloseAutoClick(false); setSameInterval(false); const returnEnergy = energy + initPoints; diff --git a/frontend/src/shared/Pages/AuctionPage/AuctionPage.tsx b/frontend/src/shared/Pages/AuctionPage/AuctionPage.tsx index be38fd5..2350072 100644 --- a/frontend/src/shared/Pages/AuctionPage/AuctionPage.tsx +++ b/frontend/src/shared/Pages/AuctionPage/AuctionPage.tsx @@ -29,7 +29,9 @@ export function AuctionPage() { {errorAuction ? :

Соревнуйся за товары на аукционе!

- {auctionBlock} + {dataAuction.length != 0 ? auctionBlock + :

Скоро тут появятся новые аукционы.

+ }
}
diff --git a/frontend/src/shared/Pages/ErrorPage/ErrorPage.tsx b/frontend/src/shared/Pages/ErrorPage/ErrorPage.tsx index e9b75c1..dd4ab57 100644 --- a/frontend/src/shared/Pages/ErrorPage/ErrorPage.tsx +++ b/frontend/src/shared/Pages/ErrorPage/ErrorPage.tsx @@ -7,15 +7,16 @@ interface IErrorPage { detail: String, title?: string, text?: string, - fullScreen ?: boolean + fullScreen ?: boolean, + isBtn?: boolean, } -export function ErrorPage({ detail, title, text, fullScreen=true }: IErrorPage) { +export function ErrorPage({ detail, title, text, fullScreen = true, isBtn=true }: IErrorPage) { return (

{title ? title : 'Возникла ошибка при загрузке ваших данных'}

{text ? text : 'Попробуйте перезагрузить страницу или войдите позже.'}

-
); diff --git a/frontend/src/shared/Pages/RoutePage/RoutePage.tsx b/frontend/src/shared/Pages/RoutePage/RoutePage.tsx index 676c691..8036c76 100644 --- a/frontend/src/shared/Pages/RoutePage/RoutePage.tsx +++ b/frontend/src/shared/Pages/RoutePage/RoutePage.tsx @@ -1,4 +1,4 @@ -import React, { useEffect } from 'react'; +import React, { useEffect, useState } from 'react'; import styles from './routepage.module.css'; import { WrongSourcePage } from '../WrongSourcePage'; import { ClickerPage } from '../ClickerPage'; @@ -15,6 +15,10 @@ import { ErrorPage } from '../ErrorPage'; import { useNavigate } from 'react-router-dom'; import { DevPage } from '../DevPage'; import { useRankData } from '../../hooks/useRankData'; +import { useDispatch } from 'react-redux'; +import { loadWinAuction } from '../../../store/auction/actions'; +import { useAppSelector } from '../../hooks/useAppSelector'; +import { checkMobile } from '../../../utils/checkMobile'; interface IRoutePage { page: string @@ -23,12 +27,19 @@ interface IRoutePage { export function RoutePage({ page }: IRoutePage) { const verified = useTgData(); const { dataUser, loadingUser, errorUser } = useUserData(); + const token = useAppSelector(state => state.token); + const [mobile, setMobile] = useState(false); useRankData(); const navigate = useNavigate(); + const dispatch = useDispatch(); //@ts-ignore const tg = window.Telegram.WebApp; var BackButton = tg.BackButton; + useEffect(() => { + dispatch(loadWinAuction()); + }, [token]); + useEffect(() => { updateBackground(page); updateStyles(); @@ -43,19 +54,26 @@ export function RoutePage({ page }: IRoutePage) { navigate(-1); }); + useEffect(() => { + setMobile(checkMobile()); + }, []); + return (
- {!verified ? :
- { //@ts-ignore - page === 'main' && (!loadingUser || dataUser.username) && !errorUser && dataUser.name && } - {page === 'rating' && (!loadingUser || dataUser.username) && !errorUser && } - {page === 'referral' && (!loadingUser || dataUser.username) && !errorUser && } - {page === 'auction' && (!loadingUser || dataUser.username) && !errorUser && } - {page === 'styles' && (!loadingUser || dataUser.username) && !errorUser && } - {page === 'dev' && } - {(loadingUser) &&
} - {errorUser && !loadingUser && } -
} + {!mobile ? : +
+ {!verified ? :
+ { //@ts-ignore + page === 'main' && (!loadingUser || dataUser.username) && !errorUser && dataUser.name && } + {page === 'rating' && (!loadingUser || dataUser.username) && !errorUser && } + {page === 'referral' && (!loadingUser || dataUser.username) && !errorUser && } + {page === 'auction' && (!loadingUser || dataUser.username) && !errorUser && } + {page === 'styles' && (!loadingUser || dataUser.username) && !errorUser && } + {page === 'dev' && } + {(loadingUser) &&
} + {errorUser && !loadingUser && } +
} +
}
); } diff --git a/frontend/src/store/auction/actions.ts b/frontend/src/store/auction/actions.ts index b329a18..097f90b 100644 --- a/frontend/src/store/auction/actions.ts +++ b/frontend/src/store/auction/actions.ts @@ -57,6 +57,7 @@ export const auctionRequestAsync = (): ThunkAction endDate) { + active = false; + } const time = Math.ceil(Math.abs(endDate.getTime() - nowDate.getTime()) / 1000); let maxBet = Number(data[i].initial_cost); let isLead = false; @@ -108,12 +112,13 @@ export const auctionRequestAsync = (): ThunkAction myBet) { myBet = Number(userData[z].value); - if(!isLead) { + if (!isLead) { const loseItem = { + id: data[i].id, name: data[i].product.name, img: data[i].product.cover, bet: userData[z].value } - if(active) { + if (active) { loseAuctions.push(loseItem) } } @@ -156,7 +162,7 @@ export const auctionRequestAsync = (): ThunkAction> => (dispatch, getState) => { + const URL = getState().url; + const token = getState().token; + const userId = getState().userTg.id; + + if (token) { + axios.get(`${URL}/api/v1/auction/auction?is_active=false`, + { + headers: { + "Authorization": `TelegramToken ${token}` + } + } + ).then(resp => { + const dataOver = resp.data.results; + + axios.get(`${URL}/api/v1/auction/bet?order_by=-value&is_winning=true`, + { + headers: { + "Authorization": `TelegramToken ${token}` + } + } + ).then(resp2 => { + const dataBet = resp2.data.results; + const winAuctions = []; + + if (dataBet.length != 0) { + if (dataOver.length != 0) { + for (let i = 0; i < dataOver.length; i++) { + for (let k = 0; k < dataBet.length; k++) { + if (dataOver[i].id === dataBet[k].auction) { + if (Number(userId) === Number(dataBet[k].user.tg_id)) { + const item = { + id: dataOver[i].id, + name: dataOver[i].product.name, + img: dataOver[i].product.cover, + bet: dataBet[k].value + } + winAuctions.push(item); + } + } + } + } + } + } + + dispatch(updateMyAuctions(winAuctions, 'win')); + }) + }) + } + +}; \ No newline at end of file diff --git a/frontend/src/store/friends/actions.ts b/frontend/src/store/friends/actions.ts index ac2803d..8a304ad 100644 --- a/frontend/src/store/friends/actions.ts +++ b/frontend/src/store/friends/actions.ts @@ -52,6 +52,7 @@ export const friendsRequestAsync = (): ThunkAction, topAuctions?: Array, + winAuctions?: Array, } export const ME_REQUEST = 'ME_REQUEST'; @@ -369,6 +371,8 @@ export const updateMyAuctions = (data: Array, type: string): Thunk if(type === 'top') { newData.topAuctions = data; + } else if(type === 'win') { + newData.winAuctions = data; } else { newData.loseAuctions = data; } diff --git a/frontend/src/store/rank/actions.ts b/frontend/src/store/rank/actions.ts index 13797f7..f1c7131 100644 --- a/frontend/src/store/rank/actions.ts +++ b/frontend/src/store/rank/actions.ts @@ -46,6 +46,7 @@ export const rankRequestAsync = (): ThunkAction = []; if(token) { + dispatch(rankRequest()); axios.get(`${URL}/api/v1/users/rank/top?limit=3`, { headers: { diff --git a/frontend/src/utils/isWhiteList.js b/frontend/src/utils/isWhiteList.js index 930407e..404da6e 100644 --- a/frontend/src/utils/isWhiteList.js +++ b/frontend/src/utils/isWhiteList.js @@ -2,6 +2,7 @@ import { getTgUserId } from "./verification"; export const isWhiteList = () => { let isWhiteList = false; + //123456, const whiteList = [ //TODO! ];