diff --git a/src/components/CreateProfilePage/index.tsx b/src/components/CreateProfilePage/index.tsx index 2821880..7f5cf80 100644 --- a/src/components/CreateProfilePage/index.tsx +++ b/src/components/CreateProfilePage/index.tsx @@ -1,10 +1,12 @@ -import { useState } from "react" +import { useEffect, useRef, useState } from "react" import { useNavigate } from "react-router-dom" import { CircularProgressbar, buildStyles } from 'react-circular-progressbar' import { useTranslation } from 'react-i18next' import ProcessFlow from "./ProcessFlow" import routes from "../../routes" import styles from './styles.module.css' +import { useSelector } from "react-redux" +import { selectors } from "../../store" const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)) @@ -12,6 +14,25 @@ function CreateProfilePage(): JSX.Element { const { t } = useTranslation() const navigate = useNavigate() const [progress, setProgress] = useState(0) + const auraCoordinates = useSelector(selectors.selectAuraCoordinates) + const progressbarRef = useRef(null); + const pageRef = useRef(null); + const [auraCoordinatesCounted, setAuraCoordinatesCounted] = useState({ + x: auraCoordinates.X - 125, + y: auraCoordinates.Y - 125 + }) + + useEffect(() => { + setTimeout(() => { + setAuraCoordinatesCounted( + { + x: (progressbarRef?.current?.offsetLeft || 0) + (pageRef?.current?.parentElement?.parentElement?.offsetLeft || 0), + y: (progressbarRef?.current?.offsetTop || 0) + 50 + } + ) + }, 1000); + }, [progressbarRef]) + const processItems = [ { task: () => sleep(3300).then(() => setProgress(23)), label: t('money_energy') }, { task: () => sleep(2550).then(() => setProgress(48)), label: t('sexual_energy') }, @@ -24,9 +45,9 @@ function CreateProfilePage(): JSX.Element { .then(() => navigate(routes.client.attention())) return ( -
-
-
+
+
+
navigate(routes.client.createProfile()) + const dispatch = useDispatch() + const updateCoordinates = useCallback((X: number, Y: number) => { + dispatch(actions.aura.update({ + coordinates: { + X, + Y + } + })) + }, [dispatch]) + const handleNext = (e: any) => { + const X = e.clientX || Math.round(e.touches[0].clientX) + const Y = e.clientY || Math.round(e.touches[0].clientY) + updateCoordinates(X, Y) + navigate(routes.client.createProfile()) + } return (
diff --git a/src/store/aura.ts b/src/store/aura.ts new file mode 100644 index 0000000..a610374 --- /dev/null +++ b/src/store/aura.ts @@ -0,0 +1,38 @@ +import { createSlice, createSelector } from '@reduxjs/toolkit' +import type { PayloadAction } from '@reduxjs/toolkit' + +interface IAura { + coordinates: { + X: number + Y: number + } +} + +const initialState: IAura = { + coordinates: { + X: 0, + Y: 0 + } +} + +const auraSlice = createSlice({ + name: 'aura', + initialState, + reducers: { + update(state, action: PayloadAction>) { + if (action.payload.coordinates?.X) { + return { ...state, ...action.payload } + } else { + return state + } + }, + }, + extraReducers: (builder) => builder.addCase('reset', () => initialState), +}) + +export const { actions } = auraSlice +export const selectAuraCoordinates = createSelector( + (state: { aura: IAura }) => state.aura.coordinates, + (aura) => aura +) +export default auraSlice.reducer