|
|
@@ -5,8 +5,13 @@ import { rpxToPx } from "@/utils/tools";
|
|
|
import { ColorType } from "@/context/themes/color";
|
|
|
import Footer from "@/components/layout/Footer";
|
|
|
import { ChooseScenarioBtn, SetScheduleBtn } from "@/features/common/SpecBtns";
|
|
|
-import { useSelector } from "react-redux";
|
|
|
+import { useDispatch, useSelector } from "react-redux";
|
|
|
import { useEffect, useState } from "react";
|
|
|
+import Modal from "@/components/layout/Modal.weapp";
|
|
|
+import TimePicker from "@/features/common/TimePicker";
|
|
|
+import { useTranslation } from "react-i18next";
|
|
|
+import { updateFast, updateSleep } from "@/store/set_target";
|
|
|
+import { setPlan } from "@/services/trackTimeDuration";
|
|
|
|
|
|
export default function SetGoal() {
|
|
|
let router
|
|
|
@@ -26,11 +31,16 @@ export default function SetGoal() {
|
|
|
const [sleepDuration, setSleepDuration] = useState<any>(0)
|
|
|
const [fastTarget, setFastTarget] = useState(target.fast.schedule.fast)
|
|
|
const [sleepTarget, setSleepTarget] = useState(target.sleep.schedule.sleep)
|
|
|
+ const [showTimePicker, setShowTimePicker] = useState(false)
|
|
|
+ const [isFast, setIsFast] = useState(true)
|
|
|
+ const [isStart, setIsStart] = useState(true)
|
|
|
+ const { t } = useTranslation()
|
|
|
+ const dispatch = useDispatch();
|
|
|
|
|
|
useEffect(() => {
|
|
|
getFastDuration()
|
|
|
getSleepDuration()
|
|
|
- }, [])
|
|
|
+ }, [target.fast, target.sleep])
|
|
|
|
|
|
function getFastDuration() {
|
|
|
var obj = target.fast.schedule.fast
|
|
|
@@ -56,6 +66,132 @@ export default function SetGoal() {
|
|
|
setSleepDuration(str)
|
|
|
}
|
|
|
|
|
|
+ function hidePicker() {
|
|
|
+ setShowTimePicker(false)
|
|
|
+ }
|
|
|
+
|
|
|
+ function modalContent() {
|
|
|
+ return <Modal
|
|
|
+ testInfo={null}
|
|
|
+ dismiss={() => {
|
|
|
+ hidePicker()
|
|
|
+ // setShowTimeoutPicker(false)
|
|
|
+ }}
|
|
|
+ confirm={() => { }}>
|
|
|
+ {
|
|
|
+ timePickerContent()
|
|
|
+ }
|
|
|
+ </Modal>
|
|
|
+ }
|
|
|
+
|
|
|
+ function pickerTitle() {
|
|
|
+ if (isFast) {
|
|
|
+ if (isStart) {
|
|
|
+ return t('feature.track_time_duration.dial.picker_fast_schedule_start_time');
|
|
|
+ }
|
|
|
+ return t('feature.track_time_duration.dial.picker_fast_schedule_end_time');
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (isStart) {
|
|
|
+ return t('feature.track_time_duration.dial.picker_sleep_schedule_start_time');
|
|
|
+ }
|
|
|
+ return t('feature.track_time_duration.dial.picker_sleep_schedule_end_time');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function pickerConfirm(e) {
|
|
|
+ hidePicker()
|
|
|
+ if (isFast) {
|
|
|
+ var fast = JSON.parse(JSON.stringify(target.fast))
|
|
|
+
|
|
|
+ if (isStart) {
|
|
|
+ fast.schedule.fast.start_time = e
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ fast.schedule.fast.end_time = e
|
|
|
+ }
|
|
|
+ dispatch(updateFast({ fast: fast }))
|
|
|
+ setFastTarget(fast.schedule.fast)
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ var sleep = JSON.parse(JSON.stringify(target.sleep))
|
|
|
+
|
|
|
+ if (isStart) {
|
|
|
+ sleep.schedule.sleep.start_time = e
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ sleep.schedule.sleep.end_time = e
|
|
|
+ }
|
|
|
+ dispatch(updateSleep({ sleep: sleep }))
|
|
|
+ setSleepTarget(sleep.schedule.sleep)
|
|
|
+ }
|
|
|
+
|
|
|
+ getFastDuration()
|
|
|
+ getSleepDuration()
|
|
|
+ }
|
|
|
+
|
|
|
+ function timePickerContent() {
|
|
|
+ var time = ''
|
|
|
+ if (isFast) {
|
|
|
+ if (isStart) {
|
|
|
+ time = fastTarget.start_time
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ time = fastTarget.end_time
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (isStart) {
|
|
|
+ time = sleepTarget.start_time
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ time = sleepTarget.end_time
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return <TimePicker time={time}
|
|
|
+ color={isFast ? ColorType.fast : ColorType.sleep}
|
|
|
+ title={pickerTitle()}
|
|
|
+ confirm={pickerConfirm}
|
|
|
+ cancel={hidePicker} />
|
|
|
+ }
|
|
|
+
|
|
|
+ function confirm() {
|
|
|
+ var params:any = {}
|
|
|
+ if (target.isMixed) {
|
|
|
+ params.scenario = 'FAST_SLEEP'
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ params.scenario = 'FAST'
|
|
|
+ }
|
|
|
+
|
|
|
+ setPlan({
|
|
|
+ scenario: scenario.name,
|
|
|
+ schedule: {
|
|
|
+ fast: {
|
|
|
+ start_time: isFastFirst ? scenario.schedule.fast.start_time : startTime,
|
|
|
+ end_time: isFastFirst ? scenario.schedule.fast.end_time : endTime,
|
|
|
+ }, sleep: {
|
|
|
+ start_time: !isFastFirst ? scenario.schedule.sleep.start_time : startTime,
|
|
|
+ end_time: !isFastFirst ? scenario.schedule.sleep.end_time : endTime,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ setBtnDisable(false)
|
|
|
+ dispatch(setStep('fast'))
|
|
|
+ if (global.checkData) {
|
|
|
+ global.checkData()
|
|
|
+ }
|
|
|
+
|
|
|
+ if (global.indexPageRefresh) {
|
|
|
+ global.indexPageRefresh()
|
|
|
+ }
|
|
|
+ popMixScheduleAlert(scenario.schedule.fast.start_time, startTime)
|
|
|
+
|
|
|
+
|
|
|
+ }).catch(e => {
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
return <View style={{ display: 'flex', flexDirection: 'column' }}>
|
|
|
<Text className="target_title">{isSelf ? 'Set Action Plan' : 'Almost Done!'}</Text>
|
|
|
{
|
|
|
@@ -93,6 +229,9 @@ export default function SetGoal() {
|
|
|
|
|
|
<View className="cell_bg" style={{ padding: 0 }}>
|
|
|
<View className="cell_top" style={{ margin: 0 }} onClick={() => {
|
|
|
+ setIsFast(true)
|
|
|
+ setIsStart(true)
|
|
|
+ setShowTimePicker(true)
|
|
|
}}>
|
|
|
<Text className="cell_title">Start fasting</Text>
|
|
|
<Text className="cell_value" style={{ color: ColorType.fast }}>{fastTarget.start_time}</Text>
|
|
|
@@ -101,6 +240,9 @@ export default function SetGoal() {
|
|
|
</View>
|
|
|
{
|
|
|
target.isMixed && <View className="cell_top" style={{ margin: 0 }} onClick={() => {
|
|
|
+ setIsFast(false)
|
|
|
+ setIsStart(true)
|
|
|
+ setShowTimePicker(true)
|
|
|
}}>
|
|
|
<Text className="cell_title">Go to bed</Text>
|
|
|
<Text className="cell_value" style={{ color: ColorType.sleep }}>{sleepTarget.start_time}</Text>
|
|
|
@@ -110,6 +252,9 @@ export default function SetGoal() {
|
|
|
}
|
|
|
{
|
|
|
target.isMixed && <View className="cell_bottom" style={{ margin: 0 }} onClick={() => {
|
|
|
+ setIsFast(false)
|
|
|
+ setIsStart(false)
|
|
|
+ setShowTimePicker(true)
|
|
|
}}>
|
|
|
<Text className="cell_title">Wake up</Text>
|
|
|
|
|
|
@@ -118,6 +263,9 @@ export default function SetGoal() {
|
|
|
</View>
|
|
|
}
|
|
|
<View className="cell_bottom" style={{ margin: 0 }} onClick={() => {
|
|
|
+ setIsFast(true)
|
|
|
+ setIsStart(false)
|
|
|
+ setShowTimePicker(true)
|
|
|
}}>
|
|
|
<Text className="cell_title">End fasting</Text>
|
|
|
|
|
|
@@ -133,10 +281,13 @@ export default function SetGoal() {
|
|
|
|
|
|
<Footer>
|
|
|
<ChooseScenarioBtn
|
|
|
- onClick={() => { }}
|
|
|
- title={parseInt(router.params.isActionPlan + '') == 1 ? 'Suggest Plan' : 'Next'}
|
|
|
+ onClick={confirm}
|
|
|
+ title={'Next'}
|
|
|
background={ColorType.fast}
|
|
|
/>
|
|
|
</Footer>
|
|
|
+ {
|
|
|
+ showTimePicker && modalContent()
|
|
|
+ }
|
|
|
</View>
|
|
|
}
|