|
|
@@ -52,8 +52,9 @@ export default function LogTime() {
|
|
|
const type = router.params.type
|
|
|
const [data, setData] = useState<any>(null)
|
|
|
const health = useSelector((state: any) => state.health);
|
|
|
- const [showGoal, setShowGoal] = useState(false)
|
|
|
+ const [showGoal, setShowGoal] = useState(router.params.longfast)
|
|
|
const tapIndex = router.params.index ?? 0
|
|
|
+ const [longDuration, setLongDuration] = useState(24)
|
|
|
|
|
|
const [expandIndex, setExpandIndex] = useState(router.params.initIndex ? router.params.initIndex : tapIndex)
|
|
|
const [chooseDate, setChooseDate] = useState(false)
|
|
|
@@ -121,6 +122,17 @@ export default function LogTime() {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ function getLongDuration() {
|
|
|
+ var day = Math.floor(longDuration / 24)
|
|
|
+ var hour = longDuration % 24
|
|
|
+ var str = ''
|
|
|
+ if (day > 0)
|
|
|
+ str = day + '天'
|
|
|
+ if (hour > 0)
|
|
|
+ str += hour + '小时'
|
|
|
+ return str
|
|
|
+ }
|
|
|
+
|
|
|
function initDatas(res = data) {
|
|
|
const { fast, sleep } = res
|
|
|
|
|
|
@@ -139,6 +151,11 @@ export default function LogTime() {
|
|
|
title: isStart ? sleep.timeline[0].title : sleep.timeline[1].title
|
|
|
});
|
|
|
}
|
|
|
+ if (router.params.longfast) {
|
|
|
+ Taro.setNavigationBarTitle({
|
|
|
+ title: t('health.long_fast')
|
|
|
+ })
|
|
|
+ }
|
|
|
list.push({
|
|
|
event_id: timeline.event_id,
|
|
|
schedule_id: timeline.schedule_id,
|
|
|
@@ -298,6 +315,19 @@ export default function LogTime() {
|
|
|
params.duration = isFast ? data.fast.target.duration : data.sleep.target.duration
|
|
|
}
|
|
|
list.push(params)
|
|
|
+
|
|
|
+ if (router.params.longfast && isStart) {
|
|
|
+ list = [{
|
|
|
+ schedule_id: health.long_fast.timeline[0].schedule_id,
|
|
|
+ date: dayjs(timestamp).format('YYYYMMDD'),
|
|
|
+ timestamp: timestamp,
|
|
|
+ extra: {
|
|
|
+ long_fast_goal: longDuration * 60,
|
|
|
+ set_time: global.set_time ? global.set_time : new Date().getTime(),
|
|
|
+ confirm_time: new Date().getTime()
|
|
|
+ }
|
|
|
+ }]
|
|
|
+ }
|
|
|
}
|
|
|
else {
|
|
|
if (type == 'home') {
|
|
|
@@ -409,6 +439,10 @@ export default function LogTime() {
|
|
|
global.refreshHistory()
|
|
|
if (global.refreshFastSleep)
|
|
|
global.refreshFastSleep()
|
|
|
+
|
|
|
+ if (global.refreshLongFast) {
|
|
|
+ global.refreshLongFast()
|
|
|
+ }
|
|
|
Taro.redirectTo({
|
|
|
url: './post_result?data=' + JSON.stringify(res)
|
|
|
})
|
|
|
@@ -433,6 +467,21 @@ export default function LogTime() {
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
+ if ((res as any).warn_code == 'SAVE_AS_IF') {
|
|
|
+ showAlert({
|
|
|
+ title: 'Saving as Intermittent Fasting',
|
|
|
+ content: 'Fasting that lasts fewer than 24 hours will be saved as Intermittent Fasting.',
|
|
|
+ showCancel: true,
|
|
|
+ cancelText: '取消',
|
|
|
+ confirmText: '保存',
|
|
|
+ cancel: () => {
|
|
|
+ },
|
|
|
+ confirm: () => {
|
|
|
+ tapCommit(false, false, (res as any).warn_code)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
setErrors((res as any).error_messages)
|
|
|
setConflicts((res as any).conflict_schedule_ids)
|
|
|
setShowSuccess(true)
|
|
|
@@ -504,7 +553,13 @@ export default function LogTime() {
|
|
|
var obj = array[0]
|
|
|
var timestamp = getTimestamp(obj)
|
|
|
var duration = isFast ? data.fast.target.duration : data.sleep.target.duration
|
|
|
+ if (router.params.longfast){
|
|
|
+ duration = longDuration*1000*3600
|
|
|
+ }
|
|
|
var time2 = timestamp + duration
|
|
|
+ if (router.params.longfast){
|
|
|
+ return 'Expect to end fast at ' + dayjs(time2).format('MM-DD HH:mm')
|
|
|
+ }
|
|
|
var strTime = TimeFormatter.dayjsFormat(time2, false)
|
|
|
if (isFast) {
|
|
|
return 'Expect to end fast at ' + strTime
|
|
|
@@ -691,6 +746,93 @@ export default function LogTime() {
|
|
|
return <View style={{ position: 'relative' }}></View>
|
|
|
}
|
|
|
|
|
|
+ function goalCard() {
|
|
|
+ if (isSingle && isStart && showGoal) {
|
|
|
+ if (router.params.longfast) {
|
|
|
+ return <Card>
|
|
|
+ <View style={{ position: 'relative' }}>
|
|
|
+ <View className="card_header" style={{ justifyContent: 'space-between' }}>
|
|
|
+ <View className="h34" style={{ marginLeft: rpxToPx(12) }}>LongFast Goal</View>
|
|
|
+ <NewButton
|
|
|
+ type={expandIndex == -1 ? NewButtonType.alpha : NewButtonType.gray}
|
|
|
+ color={isFast ? MainColorType.fast : MainColorType.sleep}
|
|
|
+ height={rpxToPx(84)}
|
|
|
+ title={getLongDuration()}
|
|
|
+ fontNormal
|
|
|
+ onClick={() => { setExpandIndex(-1) }}
|
|
|
+ />
|
|
|
+ {/* </View> */}
|
|
|
+ </View>
|
|
|
+ {
|
|
|
+ expandIndex == -1 && <View style={{
|
|
|
+ display: 'flex',
|
|
|
+ flexDirection: 'column',
|
|
|
+ alignItems: 'center'
|
|
|
+ }}>
|
|
|
+ <NewDurationPicker color={MainColorType.fast}
|
|
|
+ type={DurationPickerType.long}
|
|
|
+ value={longDuration}
|
|
|
+ onChange={(e) => {
|
|
|
+ setLongDuration(e)
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+
|
|
|
+ </View>
|
|
|
+ </Card>
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return <Card>
|
|
|
+ <View style={{ position: 'relative' }}>
|
|
|
+ <View className="card_header" style={{ justifyContent: 'space-between' }}>
|
|
|
+ <View className="h34" style={{ marginLeft: rpxToPx(12) }}>{isFast ? 'Fast Goal' : 'Sleep Goal'}</View>
|
|
|
+ {/* <View style={{
|
|
|
+ borderColor: expandIndex == -1 ? isFast ? MainColorType.fast : MainColorType.sleep : 'transparent',
|
|
|
+ borderWidth: rpxToPx(2),
|
|
|
+ borderRadius: rpxToPx(88 / 4),
|
|
|
+ borderStyle: 'solid'
|
|
|
+ }}> */}
|
|
|
+ <NewButton
|
|
|
+ type={expandIndex == -1 ? NewButtonType.alpha : NewButtonType.gray}
|
|
|
+ color={isFast ? MainColorType.fast : MainColorType.sleep}
|
|
|
+ height={rpxToPx(84)}
|
|
|
+ title={durationTime()}
|
|
|
+ fontNormal
|
|
|
+ onClick={() => { setExpandIndex(-1) }}
|
|
|
+ />
|
|
|
+ {/* </View> */}
|
|
|
+ </View>
|
|
|
+ {
|
|
|
+ expandIndex == -1 && <View style={{
|
|
|
+ display: 'flex',
|
|
|
+ flexDirection: 'column',
|
|
|
+ alignItems: 'center'
|
|
|
+ }}>
|
|
|
+ <NewDurationPicker
|
|
|
+ type={DurationPickerType.normal}
|
|
|
+ value={isFast ? data.fast.target.duration : data.sleep.target.duration}
|
|
|
+ onChange={e => {
|
|
|
+ var temp = JSON.parse(JSON.stringify(data))
|
|
|
+ if (isFast) {
|
|
|
+ temp.fast.target.duration = e
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ temp.sleep.target.duration = e
|
|
|
+ }
|
|
|
+ setData(temp)
|
|
|
+ }}
|
|
|
+ color={isFast ? MainColorType.fast : MainColorType.sleep} />
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+
|
|
|
+ </View>
|
|
|
+ </Card>
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return <View />
|
|
|
+ }
|
|
|
+
|
|
|
if (!loaded) return <View />
|
|
|
|
|
|
return <View className="page_container">
|
|
|
@@ -738,51 +880,7 @@ export default function LogTime() {
|
|
|
</View>
|
|
|
}
|
|
|
{
|
|
|
- isSingle && isStart && showGoal && <Card>
|
|
|
- <View style={{ position: 'relative' }}>
|
|
|
- <View className="card_header" style={{ justifyContent: 'space-between' }}>
|
|
|
- <View className="h34" style={{ marginLeft: rpxToPx(12) }}>{isFast ? 'Fast Goal' : 'Sleep Goal'}</View>
|
|
|
- {/* <View style={{
|
|
|
- borderColor: expandIndex == -1 ? isFast ? MainColorType.fast : MainColorType.sleep : 'transparent',
|
|
|
- borderWidth: rpxToPx(2),
|
|
|
- borderRadius: rpxToPx(88 / 4),
|
|
|
- borderStyle: 'solid'
|
|
|
- }}> */}
|
|
|
- <NewButton
|
|
|
- type={expandIndex == -1 ? NewButtonType.alpha : NewButtonType.gray}
|
|
|
- color={isFast ? MainColorType.fast : MainColorType.sleep}
|
|
|
- height={rpxToPx(84)}
|
|
|
- title={durationTime()}
|
|
|
- fontNormal
|
|
|
- onClick={() => { setExpandIndex(-1) }}
|
|
|
- />
|
|
|
- {/* </View> */}
|
|
|
- </View>
|
|
|
- {
|
|
|
- expandIndex == -1 && <View style={{
|
|
|
- display: 'flex',
|
|
|
- flexDirection: 'column',
|
|
|
- alignItems: 'center'
|
|
|
- }}>
|
|
|
- <NewDurationPicker
|
|
|
- type={DurationPickerType.normal}
|
|
|
- value={isFast ? data.fast.target.duration : data.sleep.target.duration}
|
|
|
- onChange={e => {
|
|
|
- var temp = JSON.parse(JSON.stringify(data))
|
|
|
- if (isFast) {
|
|
|
- temp.fast.target.duration = e
|
|
|
- }
|
|
|
- else {
|
|
|
- temp.sleep.target.duration = e
|
|
|
- }
|
|
|
- setData(temp)
|
|
|
- }}
|
|
|
- color={isFast ? MainColorType.fast : MainColorType.sleep} />
|
|
|
- </View>
|
|
|
- }
|
|
|
-
|
|
|
- </View>
|
|
|
- </Card>
|
|
|
+ goalCard()
|
|
|
}
|
|
|
{
|
|
|
isSingle && isStart && showGoal && <View className="h24 g02" style={{
|