|
@@ -4,37 +4,18 @@ import { useTranslation } from "react-i18next";
|
|
|
import { ColorType } from "@/context/themes/color";
|
|
import { ColorType } from "@/context/themes/color";
|
|
|
import { rpxToPx } from "@/utils/tools";
|
|
import { rpxToPx } from "@/utils/tools";
|
|
|
import { TimeFormatter } from "@/utils/time_format";
|
|
import { TimeFormatter } from "@/utils/time_format";
|
|
|
-import Modal from "@/components/layout/Modal.weapp";
|
|
|
|
|
import { useEffect, useRef, useState } from "react";
|
|
import { useEffect, useRef, useState } from "react";
|
|
|
-import { durationDatas, durationIndex, getColor, getDurationTitle } from "../hooks/Console";
|
|
|
|
|
-import PickerViews from "@/components/input/PickerViews";
|
|
|
|
|
-import { useSelector } from "react-redux";
|
|
|
|
|
-import Taro from "@tarojs/taro";
|
|
|
|
|
-import { updateRecord } from "@/services/trackTimeDuration";
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
export default function TotalTime(props: { record: any }) {
|
|
export default function TotalTime(props: { record: any }) {
|
|
|
- const [showDurationPicker, setShowDurationPicker] = useState(false)
|
|
|
|
|
- const [fastPickerValue, setFastPickerValue] = useState([0, 0])
|
|
|
|
|
- const [sleepPickerValue, setSleepPickerValue] = useState([0, 0])
|
|
|
|
|
- const [showEditPicker, setShowEditPicker] = useState(false)
|
|
|
|
|
const [count, setCount] = useState(0)
|
|
const [count, setCount] = useState(0)
|
|
|
- const common = useSelector((state: any) => state.common);
|
|
|
|
|
- const [isFast, setIsFast] = useState(true)
|
|
|
|
|
- const durationPickerRef = useRef(null)
|
|
|
|
|
const { t } = useTranslation()
|
|
const { t } = useTranslation()
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
- getStateDetail()
|
|
|
|
|
setCount((pre) => pre + 1)
|
|
setCount((pre) => pre + 1)
|
|
|
}, [props.record])
|
|
}, [props.record])
|
|
|
|
|
|
|
|
- function getStateDetail() {
|
|
|
|
|
- var current_record = props.record
|
|
|
|
|
- if (current_record.fast)
|
|
|
|
|
- setFastPickerValue(durationIndex(current_record.fast.target_start_time, current_record.fast.target_end_time, common))
|
|
|
|
|
- if (current_record.sleep)
|
|
|
|
|
- setSleepPickerValue(durationIndex(current_record.sleep.target_start_time, current_record.sleep.target_end_time, common))
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
function sleepCompleteStatus() {
|
|
function sleepCompleteStatus() {
|
|
|
if (props.record.sleep.status == "NOT_STARTED") {
|
|
if (props.record.sleep.status == "NOT_STARTED") {
|
|
@@ -75,40 +56,21 @@ export default function TotalTime(props: { record: any }) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function setFastDuration(e) {
|
|
function setFastDuration(e) {
|
|
|
- setIsFast(true)
|
|
|
|
|
if (disableChange(true)) return
|
|
if (disableChange(true)) return
|
|
|
if (process.env.TARO_ENV == 'weapp') {
|
|
if (process.env.TARO_ENV == 'weapp') {
|
|
|
e.stopPropagation()
|
|
e.stopPropagation()
|
|
|
}
|
|
}
|
|
|
- if (props.record.status == 'WAIT_FOR_START') {
|
|
|
|
|
- setShowDurationPicker(true)
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- setShowEditPicker(true)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ global.showFastPicker()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function setSleepDuration(e) {
|
|
function setSleepDuration(e) {
|
|
|
-
|
|
|
|
|
- setIsFast(false)
|
|
|
|
|
if (disableChange(false)) return
|
|
if (disableChange(false)) return
|
|
|
if (process.env.TARO_ENV == 'weapp') {
|
|
if (process.env.TARO_ENV == 'weapp') {
|
|
|
e.stopPropagation()
|
|
e.stopPropagation()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (props.record.status == 'WAIT_FOR_START') {
|
|
|
|
|
- Taro.showToast({
|
|
|
|
|
- title: t('feature.track_time_duration.common.start_fasting_first'),
|
|
|
|
|
- icon: 'none'
|
|
|
|
|
- })
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- if (props.record.status == 'WAIT_FOR_START' || props.record.status == 'ONGOING1') {
|
|
|
|
|
- setShowDurationPicker(true)
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- setShowEditPicker(true)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ global.showSleepPicker()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function disableChange(isFastStatus) {
|
|
function disableChange(isFastStatus) {
|
|
@@ -165,117 +127,6 @@ export default function TotalTime(props: { record: any }) {
|
|
|
</View>
|
|
</View>
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function durationPickerContent() {
|
|
|
|
|
- var color = getColor(props.record)
|
|
|
|
|
- var title = getDurationTitle(props.record, t)
|
|
|
|
|
- return <View style={{ color: '#fff', backgroundColor: 'transparent' }}>
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- <PickerViews ref={durationPickerRef}
|
|
|
|
|
- onChange={durationChange}
|
|
|
|
|
- items={durationDatas(common)}
|
|
|
|
|
- value={isFast ? fastPickerValue : sleepPickerValue}
|
|
|
|
|
- themeColor={color}
|
|
|
|
|
- title={title}
|
|
|
|
|
- showBtns={true}
|
|
|
|
|
- onCancel={() => {
|
|
|
|
|
- setShowDurationPicker(false)
|
|
|
|
|
- }} />
|
|
|
|
|
- </View>
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- function editPickerContent() {
|
|
|
|
|
- return <View style={{ color: '#fff', backgroundColor: 'transparent' }}>
|
|
|
|
|
- <PickerViews ref={durationPickerRef}
|
|
|
|
|
- onChange={durationChange}
|
|
|
|
|
- items={durationDatas(common)}
|
|
|
|
|
- value={isFast ? fastPickerValue : sleepPickerValue}
|
|
|
|
|
- themeColor={isFast ? ColorType.fast : ColorType.sleep}
|
|
|
|
|
- title={isFast ? t('feature.track_time_duration.action_sheet.edit_fasting_goal') :
|
|
|
|
|
- t('feature.track_time_duration.action_sheet.edit_sleeping_goal')}
|
|
|
|
|
- showBtns={true}
|
|
|
|
|
- onCancel={() => {
|
|
|
|
|
- setShowEditPicker(false)
|
|
|
|
|
- }} />
|
|
|
|
|
- </View>
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- function durationChange(e) {
|
|
|
|
|
- // debugger
|
|
|
|
|
- var count = (e[0] + common.duration.min) * 60 + e[1] * common.duration.step
|
|
|
|
|
- // var count = (e[0] + 1) * 60 + e[1] * 5
|
|
|
|
|
- if (showDurationPicker) {
|
|
|
|
|
- global.changeTargetDuration(count, isFast)
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- var params: any = {}
|
|
|
|
|
- if (isFast) {
|
|
|
|
|
- params = {
|
|
|
|
|
- fast: {
|
|
|
|
|
- target_duration: count * 60 * 1000
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- params = {
|
|
|
|
|
- sleep: {
|
|
|
|
|
- target_duration: count * 60 * 1000
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- updateRecord({
|
|
|
|
|
- ...params
|
|
|
|
|
- }, props.record.id).then(res => {
|
|
|
|
|
- global.indexPageRefresh()
|
|
|
|
|
- }).catch(e => {
|
|
|
|
|
-
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- setShowDurationPicker(false)
|
|
|
|
|
- setShowEditPicker(false)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- function modalContent() {
|
|
|
|
|
- if (showDurationPicker || showEditPicker) {
|
|
|
|
|
- if (process.env.TARO_ENV == 'weapp') {
|
|
|
|
|
- return <Modal
|
|
|
|
|
- testInfo={null}
|
|
|
|
|
- dismiss={() => {
|
|
|
|
|
- setShowDurationPicker(false)
|
|
|
|
|
- setShowEditPicker(false)
|
|
|
|
|
- }}
|
|
|
|
|
- confirm={() => { }}>
|
|
|
|
|
- {
|
|
|
|
|
- showDurationPicker ? durationPickerContent() : editPickerContent()
|
|
|
|
|
- }
|
|
|
|
|
- </Modal>
|
|
|
|
|
- }
|
|
|
|
|
- else if (process.env.TARO_ENV == 'rn') {
|
|
|
|
|
- return <PageContainer style={{ backgroundColor: '#1c1c1c' }}
|
|
|
|
|
- // overlayStyle='background-color:rgba(0,0,0,0.9)'
|
|
|
|
|
- // custom-style='background-color:#1c1c1c'
|
|
|
|
|
- overlayStyle={{ backgroundColor: 'rgba(0,0,0,0.9)' }}
|
|
|
|
|
- customStyle={{ backgroundColor: '#1c1c1c' }}
|
|
|
|
|
- closeOnSlideDown={false}
|
|
|
|
|
- onBeforeEnter={() => {
|
|
|
|
|
-
|
|
|
|
|
- }}
|
|
|
|
|
- onBeforeLeave={() => {
|
|
|
|
|
- }}
|
|
|
|
|
- onClick={() => { alert('b') }}
|
|
|
|
|
- onClickOverlay={() => { alert('a') }}
|
|
|
|
|
- onAfterLeave={() => { setShowDurationPicker(false); setShowEditPicker(false) }}
|
|
|
|
|
- show={showDurationPicker} round={true} overlay={true} position='bottom'
|
|
|
|
|
- >
|
|
|
|
|
- {
|
|
|
|
|
- showDurationPicker ? durationPickerContent() : editPickerContent()
|
|
|
|
|
- }
|
|
|
|
|
- </PageContainer>
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- return <View />
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
return <View style={{ width: rpxToPx(600) }}>
|
|
return <View style={{ width: rpxToPx(600) }}>
|
|
|
{
|
|
{
|
|
|
props.record.fast && <View>
|
|
props.record.fast && <View>
|
|
@@ -342,9 +193,6 @@ export default function TotalTime(props: { record: any }) {
|
|
|
</View>
|
|
</View>
|
|
|
</View>
|
|
</View>
|
|
|
}
|
|
}
|
|
|
- {
|
|
|
|
|
- modalContent()
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
</View>
|
|
</View>
|
|
|
}
|
|
}
|