| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710 |
- import { View, Text } from '@tarojs/components'
- import './fast_sleep_card.scss'
- import { rpxToPx } from '@/utils/tools'
- import { MainColorType } from '@/context/themes/color';
- import { TimeFormatter } from '@/utils/time_format';
- import Rings, { RingCommon, BgRing, TargetRing, CurrentDot } from "@/features/trackTimeDuration/components/Rings";
- import { getDurationArc, getStartArc, getThemeColor } from '@/features/health/hooks/health_hooks';
- import { useSelector } from 'react-redux';
- import { useTranslation } from 'react-i18next';
- import StatusIndicator, { StatusType } from '../base/status_indicator';
- import { IconCheck, IconCircle, IconMiss } from '@/components/basic/Icons';
- export default function FastSleepCard(props: { step: number, data: any }) {
- const health = useSelector((state: any) => state.health);
- const { t } = useTranslation()
- const common: RingCommon = {
- useCase: 'ChooseScenario',
- radius: 50,
- lineWidth: 14,
- isFast: true,
- status: 'WAIT_FOR_START'
- }
- const common2: RingCommon = {
- useCase: 'ChooseScenario',
- radius: 31,
- lineWidth: 14,
- isFast: true,
- status: 'WAIT_FOR_START'
- }
- const common3: RingCommon = {
- useCase: 'ChooseScenario',
- radius: 40,
- lineWidth: 14,
- isFast: true,
- status: 'WAIT_FOR_START'
- }
- const bgRing: BgRing = {
- color: MainColorType.ringBg
- }
- function target0BigRing() {
- const { fast } = props.data
- return {
- color: MainColorType.fastLight,
- startArc: getStartArc(fast.target.start_timestamp),
- durationArc: getDurationArc(fast.target.start_timestamp, fast.target.end_timestamp)
- }
- }
- function target0SmallRing() {
- const { sleep } = props.data
- if (sleep.real && sleep.real.end_timestamp) {
- return {
- color: MainColorType.sleepLight,
- startArc: getStartArc(sleep.real.start_timestamp),
- durationArc: getDurationArc(sleep.real.start_timestamp, sleep.real.end_timestamp)
- }
- }
- return {
- color: MainColorType.sleepLight,
- startArc: getStartArc(sleep.target.start_timestamp),
- durationArc: getDurationArc(sleep.target.start_timestamp, sleep.target.end_timestamp)
- }
- }
- function target1BigRing() {
- const { fast, sleep, status } = props.data
- if (status == 'OG2_NO1') {
- var fastStarttoSleepDuration = 0
- var time1 = sleep.period.start_time
- var time2 = fast.period.start_time
- var t1 = parseInt(time1.split(':')[0]) * 60 + parseInt(time1.split(':')[1])
- var t2 = parseInt(time2.split(':')[0]) * 60 + parseInt(time2.split(':')[1])
- fastStarttoSleepDuration = t1 - t2 > 0 ? (t1 - t2) * 60 * 1000 : (t1 - t2) * 60 * 1000 + 24 * 3600 * 1000
- return {
- color: MainColorType.fastLight,
- startArc: getStartArc(fast.target.start_timestamp),
- durationArc: getDurationArc(fast.target.start_timestamp, fast.target.start_timestamp + fastStarttoSleepDuration)
- }
- // var now = new Date().getTime()
- // return TimeFormatter.calculateTimeDifference(now, now + fastStarttoSleepDuration)
- }
- return {
- color: MainColorType.fastLight,
- startArc: getStartArc(fast.target.start_timestamp),
- durationArc: getDurationArc(fast.target.start_timestamp, sleep.target.start_timestamp)
- }
- }
- function target2BigRing() {
- const { sleep } = props.data
- if (sleep.real && sleep.real.end_timestamp) {
- return {
- color: MainColorType.sleepLight,
- startArc: getStartArc(sleep.real.start_timestamp),
- durationArc: getDurationArc(sleep.real.start_timestamp, sleep.real.end_timestamp)
- }
- }
- return {
- color: MainColorType.sleepLight,
- startArc: getStartArc(sleep.target.start_timestamp),
- durationArc: getDurationArc(sleep.target.start_timestamp, sleep.target.end_timestamp)
- }
- }
- function target3BigRing() {
- const { fast, sleep, status } = props.data
- if (status == 'OG2_NO1') {
- var time1 = fast.period.end_time
- var time2 = sleep.period.end_time
- var duration = 0
- var t1 = parseInt(time1.split(':')[0]) * 60 + parseInt(time1.split(':')[1])
- var t2 = parseInt(time2.split(':')[0]) * 60 + parseInt(time2.split(':')[1])
- duration = t1 - t2 >= 0 ? (t1 - t2) * 60 * 1000 : (t1 - t2) * 60 * 1000 + 24 * 3600 * 1000
- return {
- color: MainColorType.fastLight,
- startArc: getStartArc(fast.target.end_timestamp - duration),
- durationArc: getDurationArc(fast.target.end_timestamp - duration, fast.target.end_timestamp)
- }
- }
- return {
- color: MainColorType.fastLight,
- startArc: getStartArc(status == 'OG3' ? sleep.real.end_timestamp : sleep.target.end_timestamp),
- durationArc: getDurationArc(status == 'OG3' ? sleep.real.end_timestamp : sleep.target.end_timestamp, fast.target.end_timestamp)
- }
- }
- function real0BigRing() {
- const { fast, sleep, status } = props.data
- if (status == 'WFS') {
- if (fast.target.start_timestamp <= new Date().getTime() && new Date().getTime() < fast.target.end_timestamp)
- return {
- color: MainColorType.fast,
- startArc: getStartArc(fast.target.start_timestamp),
- durationArc: getDurationArc(fast.target.start_timestamp, new Date().getTime())
- }
- return null
- }
- if (status == 'OG2_NO1') {
- return null;
- }
- return {
- color: MainColorType.fast,
- startArc: getStartArc(fast.real.start_timestamp),
- durationArc: getDurationArc(fast.real.start_timestamp, new Date().getTime())
- }
- }
- function real0SmallRing() {
- const { sleep } = props.data
- if (!sleep.real) {
- return null;
- }
- if (sleep.real.end_timestamp) {
- return {
- color: MainColorType.sleep,
- startArc: getStartArc(sleep.real.start_timestamp),
- durationArc: getDurationArc(sleep.real.start_timestamp, sleep.real.end_timestamp)
- }
- }
- return {
- color: MainColorType.sleep,
- startArc: getStartArc(sleep.real.start_timestamp),
- durationArc: getDurationArc(sleep.real.start_timestamp, new Date().getTime())
- }
- }
- function real1BigRing() {
- const { fast, sleep, status } = props.data
- if (fast.real) {
- if (status == 'OG1') {
- return {
- color: MainColorType.fast,
- startArc: getStartArc(fast.real.start_timestamp),
- durationArc: getDurationArc(fast.real.start_timestamp, new Date().getTime())
- }
- }
- return {
- color: MainColorType.fast,
- startArc: getStartArc(fast.real.start_timestamp),
- durationArc: getDurationArc(fast.real.start_timestamp, sleep.real.start_timestamp)
- }
- }
- return null;
- }
- function real2BigRing() {
- const { sleep } = props.data
- if (!sleep.real) {
- return null;
- }
- return {
- color: MainColorType.sleep,
- startArc: getStartArc(sleep.real.start_timestamp),
- durationArc: getDurationArc(sleep.real.start_timestamp, sleep.real.end_timestamp ? sleep.real.end_timestamp : new Date().getTime())
- }
- }
- function real3BigRing() {
- const { fast, sleep } = props.data
- if (!sleep.real || !sleep.real.end_timestamp) {
- return null;
- }
- return {
- color: MainColorType.fast,
- startArc: getStartArc(sleep.real.end_timestamp),
- durationArc: getDurationArc(sleep.real.end_timestamp, new Date().getTime())
- }
- }
- function currentDot(mode, outRange?: boolean) {
- return {
- color: outRange ? '#B2B2B2' : getThemeColor(mode),
- lineWidth: 4,
- borderColor: '#ffffff',
- offset: 0
- }
- }
- function circle0() {
- const { fast, sleep, status } = props.data
- var outRange = true
- var outRange2 = true
- if (fast.status == 'OG') {
- outRange = false
- }
- else if (fast.target.start_timestamp <= new Date().getTime() && new Date().getTime() < fast.target.end_timestamp) {
- outRange = false
- }
- if (sleep.status == 'OG') {
- outRange2 = false
- }
- else if (sleep.target.start_timestamp <= new Date().getTime() && new Date().getTime() < sleep.target.end_timestamp) {
- outRange2 = false
- }
- return <View style={{
- display: 'flex', alignItems: 'center', justifyContent: 'center', width: 114, height: 114,
- marginLeft: rpxToPx(50),
- marginTop: rpxToPx(86),
- position: 'relative',
- }}>
- <Rings common={common}
- bgRing={bgRing}
- targetRing={target0BigRing()}
- realRing={real0BigRing()}
- canvasId={'circle0_big'}
- currentDot={currentDot('FAST', outRange)}
- />
- <View style={{
- position: 'absolute',
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'center',
- left: 0,
- right: 0,
- top: 0,
- bottom: 0
- }}>
- <Rings common={common2}
- bgRing={bgRing}
- targetRing={target0SmallRing()}
- realRing={real0SmallRing()}
- canvasId={'circle0_small'}
- currentDot={currentDot('SLEEP', outRange2)}
- />
- </View>
- </View>
- }
- function circle1() {
- const { fast, sleep, status } = props.data
- var outRange = true
- if (fast.status == 'OG') {
- outRange = false
- }
- else if (fast.target.start_timestamp <= new Date().getTime() && new Date().getTime() < fast.target.end_timestamp) {
- outRange = false
- }
- return <View style={{ display: 'flex', marginTop: rpxToPx(100), marginLeft: rpxToPx(70), alignItems: 'center', justifyContent: 'center', width: 96, height: 96, position: 'relative' }}> <Rings common={common3}
- bgRing={bgRing}
- targetRing={target1BigRing()}
- realRing={real1BigRing()}
- canvasId={'circle1_big'}
- currentDot={currentDot('FAST', outRange)}
- /></View>
- }
- function circle2() {
- const { fast, sleep, status } = props.data
- var outRange = true
- if (sleep.status == 'OG') {
- outRange = false
- }
- else if (sleep.target.start_timestamp <= new Date().getTime() && new Date().getTime() < sleep.target.end_timestamp) {
- outRange = false
- }
- return <View style={{ display: 'flex', marginTop: rpxToPx(100), marginLeft: rpxToPx(70), alignItems: 'center', justifyContent: 'center', width: 96, height: 96, position: 'relative' }}> <Rings common={common3}
- bgRing={bgRing}
- targetRing={target2BigRing()}
- realRing={real2BigRing()}
- canvasId={'circle2_big'}
- currentDot={currentDot('SLEEP', outRange)}
- /></View>
- }
- function circle3() {
- const { fast, sleep, status } = props.data
- var outRange = true
- if (fast.status == 'OG') {
- outRange = false
- }
- else if (fast.target.start_timestamp <= new Date().getTime() && new Date().getTime() < fast.target.end_timestamp) {
- outRange = false
- }
- return <View style={{ display: 'flex', marginTop: rpxToPx(100), marginLeft: rpxToPx(70), alignItems: 'center', justifyContent: 'center', width: 96, height: 96, position: 'relative' }}> <Rings common={common3}
- bgRing={bgRing}
- targetRing={target3BigRing()}
- realRing={real3BigRing()}
- canvasId={'circle3_big'}
- currentDot={currentDot('FAST',outRange)}
- /></View>
- }
- function circleContent() {
- switch (props.step) {
- case 0:
- return circle0()
- case 1:
- return circle1()
- case 2:
- return circle2()
- case 3:
- return circle3()
- }
- }
- function statusBar() {
- var title = ''
- var hide = false;
- const { status } = props.data
- switch (props.step) {
- case 0:
- {
- if (status == 'WFS') {
- title = t('health.ready_for_logging')
- }
- else {
- title = t('health.logging_progress')
- }
- return <View style={{
- position: 'absolute',
- display: 'flex',
- alignItems: 'center',
- flexDirection: 'row',
- left: rpxToPx(20),
- top: rpxToPx(20),
- opacity: hide ? 0 : 1
- }}>
- <StatusIndicator type={status == 'WFS' ? StatusType.normal : StatusType.ing}
- color={status == 'OG2_NO1' || status == 'OG2' ? MainColorType.sleep : MainColorType.fast}
- text={title}
- fontColor={MainColorType.g01}
- fontSize={rpxToPx(20)}
- >
- {/* {status == 'WFS' && <IconCircle width={rpxToPx(26)} color={MainColorType.fast} />} */}
- </StatusIndicator>
- </View>
- // else if (status == 'OG2_NO1') {
- // title = ''
- // hide = true
- // }
- // else {
- // title = 'In progress'
- // }
- }
- break;
- case 1:
- {
- title = t('health.stage1')
- var type = StatusType.normal
- var color: any = MainColorType.fast
- var img: any = null
- if (status == 'WFS') {
- type = StatusType.img
- color = 'transparent'
- img = <IconCircle width={rpxToPx(26)} color={MainColorType.fast} />
- }
- else if (status == 'OG1') {
- type = StatusType.ing
- }
- else if (status == 'OG2_NO1') {
- type = StatusType.img
- color = MainColorType.error
- img = <IconMiss width={rpxToPx(26)} color='#fff' />
- }
- else {
- type = StatusType.img
- img = <IconCheck width={rpxToPx(26)} height={rpxToPx(26)} color='#fff' />
- }
- return <View style={{
- position: 'absolute',
- display: 'flex',
- alignItems: 'center',
- flexDirection: 'row',
- left: rpxToPx(20),
- top: rpxToPx(20),
- opacity: hide ? 0 : 1
- }}>
- <StatusIndicator type={type}
- color={color}
- text={title}
- fontColor={MainColorType.g01}
- fontSize={rpxToPx(20)}
- >
- {
- img
- }
- </StatusIndicator>
- </View>
- }
- break;
- case 2:
- {
- title = t('health.stage2')
- // if (status == 'OG2') {
- // title = 'Stage 2 in progress'
- // }
- // else if (status == 'OG3' || status == 'OG2_NO1') {
- // title = 'Stage 2'
- // }
- // else {
- // title = 'Stage 2'
- // }
- var type = StatusType.normal
- var img: any = null
- var color: any = MainColorType.sleep
- if (status == 'WFS' || status == 'OG1') {
- type = StatusType.img
- img = <IconCircle width={rpxToPx(26)} color={MainColorType.sleep} />
- color = 'transparent'
- }
- else if (status == 'OG2') {
- type = StatusType.ing
- }
- else if (status == 'OG2_NO1') {
- type = StatusType.ing
- img = <IconMiss width={rpxToPx(26)} color='#fff' />
- }
- else {
- type = StatusType.img
- img = <IconCheck width={rpxToPx(26)} height={rpxToPx(26)} color='#fff' />
- }
- return <View style={{
- position: 'absolute',
- display: 'flex',
- alignItems: 'center',
- flexDirection: 'row',
- left: rpxToPx(20),
- top: rpxToPx(20),
- opacity: hide ? 0 : 1
- }}>
- <StatusIndicator type={type}
- color={color}
- text={title}
- fontColor={MainColorType.g01}
- fontSize={rpxToPx(20)}
- >
- {
- img
- }
- </StatusIndicator>
- </View>
- }
- case 3:
- {
- title = t('health.stage3')
- var type = StatusType.normal
- var img: any = null
- if (status == 'OG3') {
- type = StatusType.ing
- }
- else if (status == 'OG2_NO1') {
- type = StatusType.img
- img = <IconCircle width={rpxToPx(26)} color={MainColorType.fast} />
- }
- else {
- type = StatusType.img
- img = <IconCircle width={rpxToPx(26)} color={MainColorType.fast} />
- }
- return <View style={{
- position: 'absolute',
- display: 'flex',
- alignItems: 'center',
- flexDirection: 'row',
- left: rpxToPx(20),
- top: rpxToPx(20),
- opacity: hide ? 0 : 1
- }}>
- <StatusIndicator type={type}
- color={status == 'OG3' ? MainColorType.fast : 'transparent'}
- text={title}
- fontColor={MainColorType.g01}
- fontSize={rpxToPx(20)}
- >
- {
- img
- }
- </StatusIndicator>
- </View>
- // if (status == 'OG3') {
- // title = 'Stage 3 in progress'
- // }
- // else if (status == 'OG2_NO1') {
- // title = 'Stage 3 pending start'
- // }
- // else {
- // title = 'Stage 3'
- // }
- }
- break;
- }
- return <View style={{
- position: 'absolute',
- display: 'flex',
- alignItems: 'center',
- flexDirection: 'row',
- left: rpxToPx(20),
- top: rpxToPx(20),
- opacity: hide ? 0 : 1
- }}>
- <View style={{
- width: rpxToPx(12),
- height: rpxToPx(12),
- borderRadius: rpxToPx(6),
- marginLeft: rpxToPx(10),
- marginRight: rpxToPx(10),
- backgroundColor: props.step == 2 ? MainColorType.sleep : MainColorType.fast
- }} />
- <View className='h20' style={{ color: MainColorType.g01 }}>{title}</View>
- </View>
- }
- function fastTime() {
- const { fast, status } = props.data
- if (status == 'WFS' || status == 'OG2_NO1') {
- var now = new Date().getTime()
- return TimeFormatter.calculateTimeDifference(now, now + fast.target.duration)
- }
- return TimeFormatter.countdown(fast.real.start_timestamp)
- }
- function sleepTime() {
- const { sleep, status } = props.data
- if (status == 'WFS' || status == 'OG1') {
- var now = new Date().getTime()
- return TimeFormatter.calculateTimeDifference(now, now + sleep.target.duration)
- }
- else if (status == 'OG3') {
- return TimeFormatter.calculateTimeDifference(sleep.real.start_timestamp, sleep.real.end_timestamp)
- }
- return TimeFormatter.countdown(sleep.real.start_timestamp)
- }
- function step1() {
- if (health.fast_with_sleep.status == 'OG2_MISALIGNED') {
- return 'Not Available'
- }
- const { fast, sleep, status } = props.data
- if (status == 'WFS') {
- return TimeFormatter.calculateTimeDifference(fast.target.start_timestamp, sleep.target.start_timestamp)
- }
- else if (status == 'OG1') {
- var now = new Date().getTime()
- return TimeFormatter.countdown(fast.real.start_timestamp)
- }
- else if (status == 'OG2_NO1') {
- var fastStarttoSleepDuration = 0
- var time1 = sleep.period.start_time
- var time2 = fast.period.start_time
- var t1 = parseInt(time1.split(':')[0]) * 60 + parseInt(time1.split(':')[1])
- var t2 = parseInt(time2.split(':')[0]) * 60 + parseInt(time2.split(':')[1])
- fastStarttoSleepDuration = t1 - t2 > 0 ? (t1 - t2) * 60 * 1000 : (t1 - t2) * 60 * 1000 + 24 * 3600 * 1000
- var now = new Date().getTime()
- return TimeFormatter.calculateTimeDifference(now, now + fastStarttoSleepDuration)
- }
- return TimeFormatter.calculateTimeDifference(fast.real.start_timestamp, sleep.real.start_timestamp)
- }
- function step2() {
- if (health.fast_with_sleep.status == 'OG2_MISALIGNED') {
- return 'Not Meaningful'
- }
- const { fast, sleep, status } = props.data
- if (status == 'OG2_NO1' || status == 'OG2') {
- return TimeFormatter.countdown(sleep.real.start_timestamp)
- }
- else if (status == 'OG3') {
- return TimeFormatter.calculateTimeDifference(sleep.real.start_timestamp, sleep.real.end_timestamp)
- }
- return TimeFormatter.calculateTimeDifference(sleep.target.start_timestamp, sleep.target.end_timestamp)
- }
- function step3() {
- const { fast, sleep, status } = props.data
- if (status == 'OG3') {
- return TimeFormatter.countdown(sleep.real.end_timestamp)
- }
- return diffentTime(sleep.period.end_time, fast.period.end_time)
- }
- function diffentTime(time2, time1) {
- var duration = 0
- var t1 = parseInt(time1.split(':')[0]) * 60 + parseInt(time1.split(':')[1])
- var t2 = parseInt(time2.split(':')[0]) * 60 + parseInt(time2.split(':')[1])
- duration = t1 - t2 >= 0 ? (t1 - t2) * 60 * 1000 : (t1 - t2) * 60 * 1000 + 24 * 3600 * 1000
- var now = new Date().getTime()
- return TimeFormatter.calculateTimeDifference(now, now + duration)
- }
- function statusDetail() {
- switch (props.step) {
- case 0:
- return <View className='right_content'>
- <View className='h34 ' style={{ lineHeight: rpxToPx(42) + 'px' }}>{t('health.fasting')}</View>
- <View className='h36 bold' style={{ color: MainColorType.fast, lineHeight: rpxToPx(52) + 'px' }}>{fastTime()}</View>
- <View style={{ height: rpxToPx(24) }} />
- <View className='h34 ' style={{ lineHeight: rpxToPx(42) + 'px' }}>{t('health.sleep')}</View>
- <View className='h36 bold' style={{ color: MainColorType.sleep, lineHeight: rpxToPx(52) + 'px' }}>{sleepTime()}</View>
- </View>
- case 1:
- return <View className='right_content'>
- <View className='h34 ' style={{ lineHeight: rpxToPx(42) + 'px' }}>{t('health.fast_before_bed')}</View>
- <View style={{ height: rpxToPx(12) }} />
- <View className='h36 bold' style={{ color: MainColorType.fast, lineHeight: rpxToPx(52) + 'px' }}>{step1()}</View>
- </View>
- case 2:
- return <View className='right_content'>
- <View className='h34 ' style={{ lineHeight: rpxToPx(42) + 'px' }}>{t('health.fast_while_sleep')}</View>
- <View style={{ height: rpxToPx(12) }} />
- <View className='h36 bold' style={{ color: MainColorType.sleep, lineHeight: rpxToPx(52) + 'px' }}>{step2()}</View>
- </View>
- case 3:
- return <View className='right_content'>
- <View className='h34 ' style={{ lineHeight: rpxToPx(42) + 'px' }}>{t('health.fast_after_sleep')}</View>
- <View style={{ height: rpxToPx(12) }} />
- <View className='h36 bold' style={{ color: MainColorType.fast, lineHeight: rpxToPx(52) + 'px' }}>{step3()}</View>
- </View>
- }
- return <View className='right_content'></View>
- }
- return <View style={{
- position: 'relative', display: 'flex', flexDirection: 'row',
- height: rpxToPx(384),
- boxSizing: 'border-box'
- }}>
- {
- statusBar()
- }
- {
- circleContent()
- }
- <View style={{
- marginLeft: rpxToPx(36), height: props.step == 0 ? 114 : 96,
- marginTop: props.step == 0 ? rpxToPx(86) : rpxToPx(100),
- display: 'flex',
- flexDirection: 'row',
- alignItems: 'center'
- }}>
- {
- statusDetail()
- }
- </View>
- </View>
- }
|