Leon vor 1 Jahr
Ursprung
Commit
9e09c1ac15

+ 9 - 6
src/app.tsx

@@ -164,16 +164,19 @@ const App: React.FC<PropsWithChildren> = ({ children }) => {
 
   if (process.env.TARO_ENV == 'rn') {
     return <ActionSheetProvider>
-      <Provider store={store}>
-        <StatusBar barStyle='light-content' backgroundColor="#000" />
-        {children}
-      </Provider>
+
+        <Provider store={store}>
+
+          <StatusBar barStyle='light-content' backgroundColor="#000" />
+          {children}
+        </Provider>
+
     </ActionSheetProvider>
   }
 
   return <Provider store={store}>
-    {children}
-  </Provider>
+      {children}
+    </Provider>
 }
 
 // class App extends Component<PropsWithChildren> {

+ 67 - 0
src/features/trackTimeDuration/components/CheckAccess.scss

@@ -0,0 +1,67 @@
+@import '@/utils/common.scss';
+
+.fast_alert_container {
+    position: fixed;
+    left: 0;
+    top: 0;
+    right: 0;
+    bottom: 0;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    background-color: #000D1FF2;
+    z-index: 100000;
+}
+
+.fast_alert_content {
+    display: flex;
+    flex-direction: column;
+    width: 536px;
+    background-color: #313F52FF;
+    border-radius: 32px;
+    padding-left: 40px;
+    padding-right: 40px;
+    padding-top: 64px;
+    padding-bottom: 40px;
+    box-sizing: border-box;
+    align-items: center;
+}
+
+.fast_alert_title {
+    color: #fff;
+    font-size: 32px;
+    font-weight: bold;
+    margin-bottom: 30px;
+}
+
+.fast_alert_detail {
+    color: #fff;
+    font-size: 28px;
+    font-weight: bold;
+    margin-bottom: 36px;
+}
+
+.fast_alert_confirm {
+    width: 440px;
+    height: 84px;
+    border-radius: 42px;
+    color: #000D1FFF;
+    background-color: $fastColor;
+    font-size: 28px;
+    font-weight: bold;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+}
+
+.fast_alert_cancel {
+    margin-top: 20px;
+    width: 440px;
+    height: 84px;
+    color: #C4CCDA99;
+    font-size: 28px;
+    font-weight: bold;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+}

+ 198 - 0
src/features/trackTimeDuration/components/CheckAccess.tsx

@@ -0,0 +1,198 @@
+import showAlert from "@/components/basic/Alert"
+import { View, Text } from "@tarojs/components";
+import './CheckAccess.scss'
+
+import { useContext, useEffect, useState } from "react";
+
+export default function CheckAccess() {
+    const [showFastAlert, setShowFastAlert] = useState(false)
+    const [alertTitle, setAlertTitle] = useState('')
+    const [alertContent, setAlertContent] = useState('')
+    const [showCancel, setShowCancel] = useState(false)
+    const [cancelText, setCancelText] = useState('')
+    const [confirmText, setConfirmText] = useState('')
+
+
+    useEffect(() => {
+        global.checkAccess = (acccessData: any) => {
+            const currentStatus = acccessData.current.qualification.status
+            const preStatus = acccessData.previous.qualification.status
+
+            if (preStatus == 'NOT_QUALIFIED' && currentStatus == 'NOT_QUALIFIED') {
+                const { streak_fast_current } = acccessData.current.qualification.condition
+
+                setShowFastAlert(true)
+                setAlertTitle('Well Done')
+                setAlertContent(`You're on a ${streak_fast_current}-day streak.
+                    Two more days until unlocking 'Fasting with sleep.'`)
+                setShowCancel(false)
+                setConfirmText('Got it!')
+
+                // showAlert({
+                //     title: 'Well Done',
+                //     content: `You're on a ${streak_fast_current}-day streak.
+                //         Two more days until unlocking 'Fasting with sleep.'`,
+                //     showCancel: false,
+                //     confirmText: 'Got it!',
+                // })
+                return;
+            }
+            else if (preStatus == 'NOT_QUALIFIED' && currentStatus == 'PROVISIONAL_QUALIFIED') {
+
+                setShowFastAlert(true)
+                setAlertTitle('Premium Access Unlocked')
+                setAlertContent(`You've unlocked 'Fasting with Sleep' since you're on a x-day streak.`)
+                setShowCancel(true)
+                setCancelText('Stay with Fasting Only')
+                setConfirmText('Upgrade to Fasting with Sleep\n(Offer Expiring in 21:59:59)')
+
+                // showAlert({
+                //     title: 'Premium Access Unlocked',
+                //     content: `You've unlocked 'Fasting with Sleep' since you're on a x-day streak.
+                //     Are you ready to up the game?`,
+                //     showCancel: true,
+                //     cancelText: 'Stay',
+                //     confirmText: 'Upgrade',
+                //     confirm: upgrade
+                // })
+                return;
+            }
+            else if (preStatus == 'PROVISIONAL_QUALIFIED' && currentStatus == 'PROVISIONAL_QUALIFIED') {
+                const { streak_fast_current, streak_sleep_current } = acccessData.current.qualification.condition
+
+                setShowFastAlert(true)
+                setAlertTitle('Well Done')
+                setAlertContent(`You're on a ${streak_fast_current}-day fasting streak${streak_sleep_current > 0 ? ' and a ' + streak_sleep_current + '-day sleep streak' : ''}.\nKeep 'em going to stay in the game.'`)
+                setShowCancel(false)
+                setConfirmText('Got it!')
+                // showAlert({
+                //     title: 'Well Done',
+                //     content: `You're on a ${streak_fast_current}-day fasting streak${streak_sleep_current > 0 ? ' and a ' + streak_sleep_current + '-day sleep streak' : ''}.
+                //     Keep 'em going to stay in the game.'`,
+                //     showCancel: false,
+                //     confirmText: 'Got it!',
+                // })
+                return;
+            }
+            else if (preStatus == 'PROVISIONAL_QUALIFIED' && currentStatus == 'NOT_QUALIFIED') {
+                setShowFastAlert(true)
+                setAlertTitle('Premium Access Lost')
+                setAlertContent(`You've lost premium access to the 'Fasting with Sleep' feature
+                since you lost your fasting streak. To regain access, become a PRO or achieve a new 3-day fasting streak.`)
+                setShowCancel(true)
+                setCancelText('Achieve')
+                setConfirmText('Become')
+                // showAlert({
+                //     title: 'Premium Access Lost',
+                //     content: `You've lost premium access to the 'Fasting with Sleep' feature
+                //     since you lost your fasting streak. To regain access, become a PRO or achieve a new 3-day fasting streak.`,
+                //     showCancel: true,
+                //     cancelText:'Achieve',
+                //     confirmText: 'Become',
+                // })
+                return;
+            }
+        }
+    }, [])
+
+    function upgrade() {
+
+    }
+
+    function confirm() {
+        setShowFastAlert(false)
+    }
+
+    function cancel() {
+        setShowFastAlert(false)
+    }
+
+    function alertPop() {
+        return <View className="fast_alert_container">
+            <View className="fast_alert_content">
+                <View className="fast_alert_title">{alertTitle}</View>
+                <View className="fast_alert_detail">{alertContent}</View>
+                <View className="fast_alert_confirm" onClick={confirm}>{confirmText}</View>
+                {
+                    showCancel && <View className="fast_alert_cancel" onClick={cancel}>{cancelText}</View>
+                }
+                
+            </View>
+        </View>
+    }
+
+    return <View>
+        {
+            showFastAlert && alertPop()
+        }
+    </View>
+}
+
+// export const checkAccessProvisional = (acccessData: any, showFastAlert: any) => {
+//     debugger
+
+//     const currentStatus = acccessData.current.qualification.status
+//     const preStatus = acccessData.previous.qualification.status
+
+//     function upgrade() {
+//         showAlert({
+//             title: 'Congrats on Your PRO Status!',
+//             content: `To preserve this status, continue your fasting streak in 倒计时 and begin your sleep streak. Remember to keep both of them going.`,
+//             showCancel: false,
+//             confirmText: 'Got it!',
+//         })
+//     }
+
+//     if (preStatus == 'NOT_QUALIFIED' && currentStatus == 'NOT_QUALIFIED') {
+//         debugger
+//         const { streak_fast_current } = acccessData.current.qualification.condition
+//         showFastAlert({
+//             title: 'hello world'
+//         })
+//         // showAlert({
+//         //     title: 'Well Done',
+//         //     content: `You're on a ${streak_fast_current}-day streak.
+//         //         Two more days until unlocking 'Fasting with sleep.'`,
+//         //     showCancel: false,
+//         //     confirmText: 'Got it!',
+//         // })
+//         return;
+//     }
+//     else if (preStatus == 'NOT_QUALIFIED' && currentStatus == 'PROVISIONAL_QUALIFIED') {
+//         showAlert({
+//             title: 'Premium Access Unlocked',
+//             content: `You've unlocked 'Fasting with Sleep' since you're on a x-day streak.
+//             Are you ready to up the game?`,
+//             showCancel: true,
+//             cancelText: 'Stay',
+//             confirmText: 'Upgrade',
+//             confirm: upgrade
+//         })
+//         return;
+//     }
+//     else if (preStatus == 'PROVISIONAL_QUALIFIED' && currentStatus == 'PROVISIONAL_QUALIFIED') {
+//         const { streak_fast_current, streak_sleep_current } = acccessData.current.qualification.condition
+//         showAlert({
+//             title: 'Well Done',
+//             content: `You're on a ${streak_fast_current}-day fasting streak${streak_sleep_current > 0 ? ' and a ' + streak_sleep_current + '-day sleep streak' : ''}.
+//             Keep 'em going to stay in the game.'`,
+//             showCancel: false,
+//             confirmText: 'Got it!',
+//         })
+//         return;
+//     }
+//     else if (preStatus == 'PROVISIONAL_QUALIFIED' && currentStatus == 'NOT_QUALIFIED') {
+//         showFastAlert({
+//             title: 'hello world2'
+//         })
+//         // showAlert({
+//         //     title: 'Premium Access Lost',
+//         //     content: `You've lost premium access to the 'Fasting with Sleep' feature
+//         //     since you lost your fasting streak. To regain access, become a PRO or achieve a new 3-day fasting streak.`,
+//         //     showCancel: true,
+//         //     cancelText:'Achieve',
+//         //     confirmText: 'Become',
+//         // })
+//         return;
+//     }
+// }

+ 0 - 1
src/features/trackTimeDuration/components/ConsolePicker.tsx

@@ -41,7 +41,6 @@ const Component = forwardRef((props: {
 
 
     function resetPickerData() {
-        debugger
         if (currentValueList) {
             setValues(currentValueList)
         }

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

@@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next'
 import { useDispatch, useSelector } from 'react-redux';
 import { endFast, endSleep, startFast, startSleep } from "../actions/TrackTimeActions";
 import { jumpPage } from '../hooks/Common';
-import { useEffect, useRef, useState } from 'react';
+import { useContext, useEffect, useRef, useState } from 'react';
 import ConsolePicker from './ConsolePicker';
 import LimitPickers from '@/components/input/LimitPickers';
 import LimitTimeoutPickers from '@/components/input/LimitTimeoutPickers';
@@ -17,6 +17,7 @@ import { wxPubFollow } from '@/services/permission';
 import { setWXFollow } from '@/store/permission';
 import CircadianDetailPopup from './CircadianDetailPopup';
 import showAlert from '@/components/basic/Alert';
+import CheckAccess from './CheckAccess';
 
 let useNavigation;
 
@@ -35,6 +36,7 @@ let defaultTimestamp = 0
 let isTimeout = false
 let stageIndex = 0
 export default function IndexConsole(props: { record: any }) {
+    
     const user = useSelector((state: any) => state.user);
     const { status } = props.record.current_record;
     const currentRecord = props.record.current_record;
@@ -611,11 +613,13 @@ export default function IndexConsole(props: { record: any }) {
                     global.refrehWeekly()
                     global.refreshStreaks()
                     refreshDayNight()
+                    global.checkAccess((res as any).access)
+                    // checkAccessProvisional((res as any).access,showFastAlert)
                 }).catch((e) => {
                     setBtnDisable(false)
                     var picker = limitPickerRef.current;
                     (picker as any).resetPickerData()
-
+                    
 
                 })
                 break
@@ -808,6 +812,7 @@ export default function IndexConsole(props: { record: any }) {
         {
             showStageModal && stageContent()
         }
+        <CheckAccess />
 
     </View>
 }

+ 4 - 0
src/pages/clock/ChooseScenario.tsx

@@ -27,6 +27,10 @@ export default function ChooseScenario() {
             var targets: any = {}
             data.scenarios.forEach((item) => {
                 if (item.name == 'FAST') {
+                    
+                    if (item.schedule.fast.duration.prev_input){
+                        item.schedule.fast.duration.last_value = item.schedule.fast.duration.init_value
+                    }
                     targets.fast = item
                 }
                 else if (item.name == 'SLEEP') {

+ 32 - 9
src/pages/clock/Suggest.tsx

@@ -33,7 +33,9 @@ export default function Suggest() {
 
     const [suggestIndex, setSuggestIndex] = useState(-1)
     const [suggestItems, setSuggestItem] = useState<any>([])
-    const [scrollTop,setScrollTop] = useState(0)
+    const [scrollTop, setScrollTop] = useState(0)
+    const [fastRecommendIndex, setFastRecommendIndex] = useState(-1)
+    const [fastLastIndex, setFastLastIndex] = useState(-1)
 
 
     useEffect(() => {
@@ -42,9 +44,16 @@ export default function Suggest() {
             var obj = target.fast.schedule.fast
             var array: any = []
             var currentIndex = -1;
+            var recommendIndex = -1;
+            var lastIndex = -1;
 
             for (var i = 0; i < obj.duration.options.length; i++) {
-
+                if (obj.duration.options[i] == obj.duration.last_value) {
+                    lastIndex = i
+                }
+                else if (obj.duration.options[i] == obj.duration.default_value) {
+                    recommendIndex = i
+                }
                 var fast = JSON.parse(JSON.stringify(target.fast))
                 var startCount = fast.schedule.fast.end_time.split(':')[0] * 60 + fast.schedule.fast.end_time.split(':')[1] * 1 - obj.duration.options[i] * 60
                 if (startCount < 0) {
@@ -54,7 +63,7 @@ export default function Suggest() {
 
                 array.push({
                     hours: obj.duration.options[i],
-                    left: 24-obj.duration.options[i],
+                    left: 24 - obj.duration.options[i],
                     // minutes: obj.duration.minutes[i],
                     // number: obj.duration.numbers[i],
                     time: start
@@ -88,20 +97,22 @@ export default function Suggest() {
             //     }
             // }
 
+            setFastRecommendIndex(recommendIndex)
+            setFastLastIndex(lastIndex)
             setSuggestItem(array)
             setSuggestIndex(currentIndex)
-            setScrollTop(currentIndex*rpxToPx(160))
+            setScrollTop(currentIndex * rpxToPx(160))
         }
         else if (pageStep == 3) {
             var obj = target.sleep.schedule.sleep
             var sleep_cycle = obj.cycle
             var sleep_latency = obj.latency.init_value
             var array: any = []
-            var index:number = 0;
+            var index: number = 0;
             for (var i = 0; i < sleep_cycle.num.options.length; i++) {
                 var count = sleep_cycle.num.options[i] * sleep_cycle.duration.init_value + sleep_latency
                 //sleep.schedule.sleep.cycle.num.init_value = sleep.schedule.sleep.cycle.num.options[suggestIndex]
-                if (sleep_cycle.num.options[i]==sleep_cycle.num.init_value){
+                if (sleep_cycle.num.options[i] == sleep_cycle.num.init_value) {
                     index = i
                 }
 
@@ -307,7 +318,7 @@ export default function Suggest() {
         else {
             var sleep = JSON.parse(JSON.stringify(target.sleep))
             sleep.schedule.sleep.end_time = time
-            fast.schedule.sleep.start_time = start
+            sleep.schedule.sleep.start_time = start
             dispatch(updateSleep({ sleep: sleep }))
         }
     }
@@ -368,7 +379,19 @@ export default function Suggest() {
                             return <View onClick={() => {
                                 setSuggestIndex(index)
                             }} key={index} className={index == suggestIndex ? 'item_sel1' : 'item1'}>
-                                <View className="suggest_item_title">{item.hours} hours</View>
+                                <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
+                                    <View className="suggest_item_title">{item.hours} hours</View>
+                                    <View style={{ flex: 1 }} />
+                                    {
+                                        index == fastRecommendIndex &&
+                                        <View style={{color:'#fff'}}>Recommended</View>
+                                    }
+                                    {
+                                        index == fastLastIndex &&
+                                        <View style={{color:'#fff',marginLeft:5}}>Last</View>
+                                    }
+                                </View>
+
                                 <View className="suggest_item_desc">{item.left} hrs eating</View>
                                 {
                                     index == suggestIndex &&
@@ -433,7 +456,7 @@ export default function Suggest() {
                 <ChooseScenarioBtn
                     onClick={next}
                     title={pageStep == 0 || pageStep == 2 ? 'Suggest Plan' : 'Next'}
-                    background={pageStep<2?ColorType.fast:ColorType.sleep}
+                    background={pageStep < 2 ? ColorType.fast : ColorType.sleep}
                 />
                 <Text className="suggest_footer_btn" onClick={myself}>Set Schedule Myself</Text>
             </View>

+ 3 - 3
src/pages/common/RecordsHistory.tsx

@@ -356,9 +356,9 @@ export default function Page() {
     function detail() {
         if (router.params.type == 'time') {
             return <View>
-                {/* {
-                    user.test_user && <Text style={{ color: '#fff', position: 'absolute', right: 50, top: 0 }} onClick={() => global.clearHistory()}>删除全部</Text>
-                } */}
+                {
+                    process.env.TARO_ENV=='weapp'&&user.test_user && <Text style={{ color: '#fff', position: 'absolute', right: 50, top: 0 }} onClick={() => global.clearHistory()}>删除全部</Text>
+                }
                 {
                     filters()
                 }