leon пре 1 година
родитељ
комит
cfefcfec58
1 измењених фајлова са 68 додато и 28 уклоњено
  1. 68 28
      src/features/health/MainSwiper.tsx

+ 68 - 28
src/features/health/MainSwiper.tsx

@@ -6,7 +6,7 @@ import MainSleepActiveCard from "./MainSleepActiveCard";
 import { useState } from "react";
 import { WindowType } from "@/utils/types";
 import { useDispatch, useSelector } from "react-redux";
-import { setTab } from "@/store/health";
+import { setMode, setTab } from "@/store/health";
 import { MainColorType } from "@/context/themes/color";
 import { rpxToPx } from "@/utils/tools";
 import dayjs from "dayjs";
@@ -86,58 +86,58 @@ export default function MainSwiper(props: { count: number, pageChanged: Function
                     break;
             }
         }
-        else if (x >= -pageWidth*2 && x <= pageWidth*2) {
+        else if (x >= -pageWidth * 2 && x <= pageWidth * 2) {
             switch (scrollPage) {
                 case 0:
                 case 3:
                     {
-                        scale1 = 1 - (Math.abs(x)-pageWidth) / pageWidth * 0.2
-                        scale2 = x > 0 ? 1 - (pageWidth - x+pageWidth) / pageWidth * 0.2 : 0.8
-                        scale0 = x < 0 ? 1 - (pageWidth + x+pageWidth) / pageWidth * 0.2 : 0.8
+                        scale1 = 1 - (Math.abs(x) - pageWidth) / pageWidth * 0.2
+                        scale2 = x > 0 ? 1 - (pageWidth - x + pageWidth) / pageWidth * 0.2 : 0.8
+                        scale0 = x < 0 ? 1 - (pageWidth + x + pageWidth) / pageWidth * 0.2 : 0.8
                     }
                     break;
                 case 1:
                 case 4:
                     {
-                        scale1 = x < 0 ? 1 - (pageWidth + x+pageWidth) / pageWidth * 0.2 : 0.8
-                        scale2 = 1 - (Math.abs(x)-pageWidth) / pageWidth * 0.2
-                        scale0 = x > 0 ? 1 - (pageWidth - x+pageWidth) / pageWidth * 0.2 : 0.8
+                        scale1 = x < 0 ? 1 - (pageWidth + x + pageWidth) / pageWidth * 0.2 : 0.8
+                        scale2 = 1 - (Math.abs(x) - pageWidth) / pageWidth * 0.2
+                        scale0 = x > 0 ? 1 - (pageWidth - x + pageWidth) / pageWidth * 0.2 : 0.8
                     }
                     break;
                 case 2:
                 case 5:
                     {
-                        scale1 = x > 0 ? 1 - (pageWidth - x+pageWidth) / pageWidth * 0.2 : 0.8
-                        scale2 = x < 0 ? 1 - (pageWidth + x+pageWidth) / pageWidth * 0.2 : 0.8
-                        scale0 = 1 - (Math.abs(x)-pageWidth) / pageWidth * 0.2
+                        scale1 = x > 0 ? 1 - (pageWidth - x + pageWidth) / pageWidth * 0.2 : 0.8
+                        scale2 = x < 0 ? 1 - (pageWidth + x + pageWidth) / pageWidth * 0.2 : 0.8
+                        scale0 = 1 - (Math.abs(x) - pageWidth) / pageWidth * 0.2
                     }
                     break;
             }
         }
-        else if (x >= -pageWidth*3 && x <= pageWidth*3) {
+        else if (x >= -pageWidth * 3 && x <= pageWidth * 3) {
             switch (scrollPage) {
                 case 0:
                 case 3:
                     {
-                        scale2 = 1 - (Math.abs(x)-pageWidth*2) / pageWidth * 0.2
-                        scale0 = x > 0 ? 1 - (pageWidth - x+pageWidth*2) / pageWidth * 0.2 : 0.8
-                        scale1 = x < 0 ? 1 - (pageWidth + x+pageWidth*2) / pageWidth * 0.2 : 0.8
+                        scale2 = 1 - (Math.abs(x) - pageWidth * 2) / pageWidth * 0.2
+                        scale0 = x > 0 ? 1 - (pageWidth - x + pageWidth * 2) / pageWidth * 0.2 : 0.8
+                        scale1 = x < 0 ? 1 - (pageWidth + x + pageWidth * 2) / pageWidth * 0.2 : 0.8
                     }
                     break;
                 case 1:
                 case 4:
                     {
-                        scale2 = x < 0 ? 1 - (pageWidth + x+pageWidth*2) / pageWidth * 0.2 : 0.8
-                        scale0 = 1 - (Math.abs(x)-pageWidth*2) / pageWidth * 0.2
-                        scale1 = x > 0 ? 1 - (pageWidth - x+pageWidth*2) / pageWidth * 0.2 : 0.8
+                        scale2 = x < 0 ? 1 - (pageWidth + x + pageWidth * 2) / pageWidth * 0.2 : 0.8
+                        scale0 = 1 - (Math.abs(x) - pageWidth * 2) / pageWidth * 0.2
+                        scale1 = x > 0 ? 1 - (pageWidth - x + pageWidth * 2) / pageWidth * 0.2 : 0.8
                     }
                     break;
                 case 2:
                 case 5:
                     {
-                        scale2 = x > 0 ? 1 - (pageWidth - x+pageWidth*2) / pageWidth * 0.2 : 0.8
-                        scale0 = x < 0 ? 1 - (pageWidth + x+pageWidth*2) / pageWidth * 0.2 : 0.8
-                        scale1 = 1 - (Math.abs(x)-pageWidth*2) / pageWidth * 0.2
+                        scale2 = x > 0 ? 1 - (pageWidth - x + pageWidth * 2) / pageWidth * 0.2 : 0.8
+                        scale0 = x < 0 ? 1 - (pageWidth + x + pageWidth * 2) / pageWidth * 0.2 : 0.8
+                        scale1 = 1 - (Math.abs(x) - pageWidth * 2) / pageWidth * 0.2
                     }
                     break;
             }
@@ -149,10 +149,34 @@ export default function MainSwiper(props: { count: number, pageChanged: Function
 
     }
 
-    function onTransitionend(){
+    function onTransitionend() {
         scrollPage = current
     }
 
+    function switchMode() {
+        switch (health.mode) {
+            case 'FAST':
+                dispatch(setMode('EAT'));
+                break
+            case 'EAT':
+                dispatch(setMode('FAST'));
+                break
+            case 'DAY':
+                dispatch(setMode('NIGHT'));
+                break
+            case 'NIGHT':
+                dispatch(setMode('DAY'));
+                break
+            case 'SLEEP':
+                dispatch(setMode('ACTIVE'));
+                break
+            case 'ACTIVE':
+                dispatch(setMode('SLEEP'));
+                break
+
+        }
+    }
+
     return <View style={{ flexDirection: 'column', display: 'flex', alignItems: 'center' }}>
         <Text className="today">Today</Text>
         <Text className="main_date">{global.language == 'en' ? dayjs().format('dddd, MMM D') : dayjs().format('MMMD日, dddd')}</Text>
@@ -172,18 +196,34 @@ export default function MainSwiper(props: { count: number, pageChanged: Function
             onChange={pageChanged}
             current={current}>
             <SwiperItem>
-                <MainDayNightCard scale={current==0?1:0.8} count={props.count} typeChanged={typeChanged} id={1} onClick={() => {
-                    setCurrent(0)
+                <MainDayNightCard scale={current == 0 ? 1 : 0.8} count={props.count} typeChanged={typeChanged} id={1} onClick={() => {
+
+                    if (current == 0) {
+                        switchMode()
+                    }
+                    else {
+                        setCurrent(0)
+                    }
                 }} />
             </SwiperItem>
             <SwiperItem>
-                <MainFastEatCard scale={current==1?1:0.8} count={props.count} typeChanged={typeChanged} id={2} onClick={() => {
-                    setCurrent(1)
+                <MainFastEatCard scale={current == 1 ? 1 : 0.8} count={props.count} typeChanged={typeChanged} id={2} onClick={() => {
+                    if (current == 1) {
+                        switchMode()
+                    }
+                    else {
+                        setCurrent(1)
+                    }
                 }} />
             </SwiperItem>
             <SwiperItem>
-                <MainSleepActiveCard scale={current==2?1:0.8} count={props.count} typeChanged={typeChanged} id={3} onClick={() => {
-                    setCurrent(2)
+                <MainSleepActiveCard scale={current == 2 ? 1 : 0.8} count={props.count} typeChanged={typeChanged} id={3} onClick={() => {
+                    if (current == 2) {
+                        switchMode()
+                    }
+                    else {
+                        setCurrent(2)
+                    }
                 }} />
             </SwiperItem>
             {/* <SwiperItem>