Leon há 2 anos atrás
pai
commit
0169950f7d

+ 42 - 13
src/features/trackTimeDuration/components/ChooseScenario.tsx

@@ -18,6 +18,7 @@ import { getPlans } from "@/services/trackTimeDuration";
 
 
 export default function Component() {
+    const isFastFirst = true;
     const { t } = useTranslation()
     const dispatch = useDispatch();
     const [selIndex, setSelIndex] = useState(-1)
@@ -30,10 +31,9 @@ export default function Component() {
     })
 
     useReady(() => {
-        console.log(selScenario)
         if (selScenario) {
             if (selScenario.name == 'FAST_SLEEP') {
-                dispatch(setStep('sleep'))
+                dispatch(setStep(isFastFirst?'fast':'sleep'))
                 setSelIndex(2)
             }
             else if (selScenario.name == 'SLEEP') {
@@ -45,16 +45,19 @@ export default function Component() {
                 setSelIndex(0)
             }
         }
+        Taro.getStorage({key:'scenarios'}).then(res=>{
+            if (res){
+                setScenarios(JSON.parse(res as any))
+            }
+        })
         getPlans().then(res => {
             const data = res as { scenarios: any[] };
+            Taro.setStorage({key:'scenarios', data:JSON.stringify(data.scenarios as any)})
             setScenarios(data.scenarios)
         })
     })
 
     function next() {
-        console.log(scenarios);
-        // var scenario = scenarios[selIndex];
-        // setScenario(scenario)
         Taro.navigateTo({
             url: '/pages/SetSchedule'
         })
@@ -96,6 +99,37 @@ export default function Component() {
         return (end - start) / 1440 * 2 * Math.PI
     }
 
+    // function getScheduleTarget(isFast: boolean) {
+    //     for (var i = 0; i < scenarios.length; i++) {
+    //         if (isFast && scenarios[i].name == 'FAST') {
+    //             if (global.schedule_fast){
+    //                 return global.schedule_fast
+    //             }
+    //             return scenarios[i].schedule.fast
+    //         }
+    //         else if (!isFast && scenarios[i].name == 'SLEEP') {
+    //             if (global.schedule_sleep){
+    //                 return global.schedule_sleep
+    //             }
+    //             return scenarios[i].schedule.sleep
+    //         }
+    //         else {
+    //             if (isFast){
+    //                 if (global.schedule_fast){
+    //                     return global.schedule_fast
+    //                 }
+    //                 return scenarios[i].schedule.fast
+    //             }
+    //             if (global.schedule_sleep){
+    //                 return global.schedule_sleep
+    //             }
+    //             return scenarios[i].schedule.sleep
+    //         }
+
+    //     }
+
+    // }
+
     function getScheduleTarget(isFast: boolean) {
         for (var i = 0; i < scenarios.length; i++) {
             if (isFast && scenarios[i].name == 'FAST') {
@@ -110,12 +144,6 @@ export default function Component() {
                 }
                 return scenarios[i].schedule.sleep
             }
-
-        }
-        return {
-            start_time: '00:00',
-            end_time: '00:00'
-
         }
 
     }
@@ -140,6 +168,7 @@ export default function Component() {
         const bgRing: BgRing = {
             color: '#262626'
         }
+        debugger
 
         const targetRing: TargetRing = {
             color: '#AAFF00',
@@ -199,7 +228,7 @@ export default function Component() {
             dispatch(setStep('sleep'))
         }
         else {
-            dispatch(setStep('sleep'))
+            dispatch(setStep(isFastFirst?'fast':'sleep'))
         }
         // dispatch(setScenarioName(scenarios[index].scenario) as any)
     }
@@ -209,7 +238,7 @@ export default function Component() {
         <Texts text={t('page.choose_scenario.sub_title')} type={TextType.secondary}></Texts>
         <View style={{ height: 20 }} />
         {
-            <View style={{ position: 'relative', zIndex: 1 }}>
+            scenarios.length>0&&<View style={{ position: 'relative', zIndex: 1 }}>
                 <SingleSelect items={items()} itemSelect={handleItemSelect} selIndex={selIndex} />
             </View>
         }

+ 7 - 2
src/features/trackTimeDuration/components/More.tsx

@@ -2,19 +2,22 @@ import { View, Text } from "@tarojs/components";
 import Taro from "@tarojs/taro";
 import { forwardRef, useEffect, useState } from "react";
 import { useTranslation } from "react-i18next";
-import { useSelector } from "react-redux";
+import { useDispatch, useSelector } from "react-redux";
 import trackTimeService, { machine } from "@/store/trackTimeMachine"
 import { recordCheck } from "@/services/trackTimeDuration";
 import LimitPickers from "@/components/LimitPickers";
 import { endFast } from "../actions/TrackTimeActions";
 import Modal from "@/components/Modal";
+import { setStep } from "@/store/scenario";
 
 const Component = forwardRef((props, ref) => {
+    const isFastFirst = true;
     const { t } = useTranslation()
     const scenario = useSelector((state: any) => state.scenario);
     const user = useSelector((state: any) => state.user);
     const [isOpen, setIsOpen] = useState(false);
     const [showModal, setShowModal] = useState(false);
+    const dispatch = useDispatch();
 
     useEffect(() => {
         var value = trackTimeService.getSnapshot().value
@@ -37,9 +40,11 @@ const Component = forwardRef((props, ref) => {
             itemList: [t('feature.track_time_duration.action_sheet.change_schedule'), t('feature.track_time_duration.action_sheet.switch_scenario')]
         })
             .then(res => {
-                console.log(res.tapIndex)
                 switch (res.tapIndex) {
                     case 0:
+                        if (scenario.name == 'FAST_SLEEP') {
+                            dispatch(setStep(isFastFirst?'fast':'sleep'))
+                        }
                         Taro.navigateTo({
                             url: '/pages/SetSchedule'
                         })

+ 1 - 1
src/features/trackTimeDuration/components/SetSchedule.tsx

@@ -17,7 +17,7 @@ import Modal from "@/components/Modal";
 import Dial from './Dial';
 
 export default function Component() {
-  const isFastFirst = false;
+  const isFastFirst = true;
   const dispatch = useDispatch();
   const canvasRef = useRef(null);
   const [scenario] = useState(useSelector((state: any) => state.scenario))