|
|
@@ -1,7 +1,7 @@
|
|
|
import { View, Text } from '@tarojs/components'
|
|
|
import './CircadianDetailPopup.scss'
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
-import { useState } from 'react'
|
|
|
+import { useEffect, useState } from 'react'
|
|
|
import { rpxToPx } from '@/utils/tools'
|
|
|
import { TimeFormatter } from '@/utils/time_format'
|
|
|
import { useSelector } from 'react-redux'
|
|
|
@@ -17,20 +17,59 @@ export default function DayNightDetailPopup(props: {
|
|
|
sunsetTime: any,
|
|
|
sunriseTime: any,
|
|
|
sunriseTmrTime: any,
|
|
|
- nightDate:any,
|
|
|
- dayDate:any,
|
|
|
- onClose: Function
|
|
|
+ nightDate: any,
|
|
|
+ dayDate: any,
|
|
|
+ onClose: Function,
|
|
|
}) {
|
|
|
const dayNight = useSelector((state: any) => state.night);
|
|
|
const day = useSelector((state: any) => state.day);
|
|
|
const [tabIndex, setTabIndex] = useState(0)
|
|
|
const { t } = useTranslation()
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ if (isCompleted()) {
|
|
|
+ setTabIndex(1)
|
|
|
+ }
|
|
|
+ }, [])
|
|
|
+
|
|
|
function getTitle() {
|
|
|
return props.isNight ? t('feature.day_night.night_popover') : t('feature.day_night.day_popover')
|
|
|
}
|
|
|
|
|
|
+ function getCompletedTitle(){
|
|
|
+ if (props.isNight){
|
|
|
+ return TimeFormatter.getDayOfWeek(new Date(props.authInfo.night_completed.sunset_ts).getDay(),true)
|
|
|
+ }
|
|
|
+ return TimeFormatter.getDayOfWeek(new Date(props.authInfo.night_completed.sunrise_ts).getDay(),true)
|
|
|
+ }
|
|
|
+
|
|
|
+ function getSubTitle(){
|
|
|
+ if (props.isNight){
|
|
|
+ return TimeFormatter.getMonthAndDayByTimestamp(props.authInfo.night_completed.sunset_ts)
|
|
|
+ }
|
|
|
+ return TimeFormatter.getMonthAndDayByTimestamp(props.authInfo.night_completed.sunrise_ts)
|
|
|
+ }
|
|
|
+
|
|
|
+ function isCompleted() {
|
|
|
+ if (props.isNight) {
|
|
|
+ if (props.authInfo && props.authInfo.night_completed && new Date().getTime() > props.authInfo.night_completed.sunrise_ts) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (props.authInfo && props.authInfo.day_completed && new Date().getTime() > props.authInfo.day_completed.sunset_ts) {
|
|
|
+
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
function nightDuration() {
|
|
|
+ if (isCompleted()) {
|
|
|
+ return TimeFormatter.calculateTimeDifference(props.authInfo.night_completed.sunset_ts, props.authInfo.night_completed.sunrise_ts);
|
|
|
+ }
|
|
|
|
|
|
var sunRiseObj = dayNight.nightRingSunrise
|
|
|
var sunSetObj = dayNight.nightRingSunset
|
|
|
@@ -46,6 +85,9 @@ export default function DayNightDetailPopup(props: {
|
|
|
}
|
|
|
|
|
|
function dayDuration() {
|
|
|
+ if (isCompleted()) {
|
|
|
+ return TimeFormatter.calculateTimeDifference(props.authInfo.day_completed.sunrise_ts, props.authInfo.day_completed.sunset_ts);
|
|
|
+ }
|
|
|
var sunRiseObj = day.dayRingSunrise
|
|
|
var sunSetObj = day.dayRingSunset
|
|
|
var sunRise = parseInt(sunRiseObj.split(':')[0]) * 60 + parseInt(sunRiseObj.split(':')[1])
|
|
|
@@ -174,34 +216,37 @@ export default function DayNightDetailPopup(props: {
|
|
|
<View style={{ flexDirection: 'row', alignItems: 'center', marginTop: rpxToPx(8), display: 'flex', width: '100%' }}>
|
|
|
<Text className='pop_duration_txt'>{props.isNight ? nightDuration() : dayDuration()}</Text>
|
|
|
</View>
|
|
|
- <View style={{ marginTop: rpxToPx(20), display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
|
|
|
- <View className='countdown_time_bg'>
|
|
|
- <Text className='title'>{timeDesc()}</Text>
|
|
|
- <Text className='value' style={{ color: props.isNight ? ColorType.night : ColorType.day }}>{timeCount()}</Text>
|
|
|
- </View>
|
|
|
- {
|
|
|
- showExtraData() && <View className='countdown_time_bg'>
|
|
|
- <Text className='title'>{timeDesc2()}</Text>
|
|
|
- <Text className='value' style={{ opacity: 0.4, color: props.isNight ? ColorType.night : ColorType.day }}>{timeCount2()}</Text>
|
|
|
+ {
|
|
|
+ !isCompleted() && <View style={{ marginTop: rpxToPx(20), display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
|
|
|
+ <View className='countdown_time_bg'>
|
|
|
+ <Text className='title'>{timeDesc()}</Text>
|
|
|
+ <Text className='value' style={{ color: props.isNight ? ColorType.night : ColorType.day }}>{timeCount()}</Text>
|
|
|
</View>
|
|
|
- }
|
|
|
+ {
|
|
|
+ showExtraData() && <View className='countdown_time_bg'>
|
|
|
+ <Text className='title'>{timeDesc2()}</Text>
|
|
|
+ <Text className='value' style={{ opacity: 0.4, color: props.isNight ? ColorType.night : ColorType.day }}>{timeCount2()}</Text>
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+
|
|
|
+ </View>
|
|
|
+ }
|
|
|
|
|
|
- </View>
|
|
|
</View>
|
|
|
}
|
|
|
|
|
|
function nightDurationDesc() {
|
|
|
if (!props.authInfo || !(props.authInfo as any).lat) {
|
|
|
if (new Date().getHours() >= 6) {
|
|
|
- return [t('feature.day_night.tonight'),t('feature.day_night.tomorrow_morning')]
|
|
|
+ return [t('feature.day_night.tonight'), t('feature.day_night.tomorrow_morning')]
|
|
|
}
|
|
|
- return [t('feature.day_night.last_night'),t('feature.day_night.this_morning')]
|
|
|
+ return [t('feature.day_night.last_night'), t('feature.day_night.this_morning')]
|
|
|
// return `Yesterday ${sunsetTime} - Today ${sunriseTmrTime}`
|
|
|
}
|
|
|
if (props.nightDate.getDate() == new Date().getDate()) {
|
|
|
- return [t('feature.day_night.tonight'),t('feature.day_night.tomorrow_morning')]
|
|
|
+ return [t('feature.day_night.tonight'), t('feature.day_night.tomorrow_morning')]
|
|
|
}
|
|
|
- return [t('feature.day_night.last_night'),t('feature.day_night.this_morning')]
|
|
|
+ return [t('feature.day_night.last_night'), t('feature.day_night.this_morning')]
|
|
|
//`Yesterday ${sunsetTime} - Today ${sunriseTmrTime}`
|
|
|
}
|
|
|
|
|
|
@@ -225,49 +270,98 @@ export default function DayNightDetailPopup(props: {
|
|
|
|
|
|
function events() {
|
|
|
let timelineItems: any = []
|
|
|
-
|
|
|
+
|
|
|
if (props.isNight) {
|
|
|
- var list = nightDurationDesc()
|
|
|
- timelineItems.push(
|
|
|
- {
|
|
|
- status: showExtraData() ? 'done' : 'padding',
|
|
|
- title: '日落',//list[0],
|
|
|
- content: list[0]+' '+props.sunsetTime,
|
|
|
- date: '',
|
|
|
- color: ColorType.night
|
|
|
- }
|
|
|
- )
|
|
|
-
|
|
|
- timelineItems.push(
|
|
|
- {
|
|
|
- status: 'padding',
|
|
|
- title: '日出',//list[1],
|
|
|
- content: list[1]+' '+props.sunriseTmrTime,
|
|
|
- date: '',
|
|
|
- color: ColorType.night
|
|
|
- }
|
|
|
- )
|
|
|
+ if (isCompleted()) {
|
|
|
+ timelineItems.push(
|
|
|
+ {
|
|
|
+ status: 'done',
|
|
|
+ title: '日落',//list[0],
|
|
|
+ content: TimeFormatter.dateTimeFormate(props.authInfo.night_completed.sunset_ts, true),
|
|
|
+ date: '',
|
|
|
+ color: ColorType.night
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ timelineItems.push(
|
|
|
+ {
|
|
|
+ status: 'done',
|
|
|
+ title: '日出',//list[1],
|
|
|
+ content: TimeFormatter.dateTimeFormate(props.authInfo.night_completed.sunrise_ts, true),
|
|
|
+ date: '',
|
|
|
+ color: ColorType.night
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+ else {
|
|
|
+
|
|
|
+ var list = nightDurationDesc()
|
|
|
+ timelineItems.push(
|
|
|
+ {
|
|
|
+ status: showExtraData() ? 'done' : 'padding',
|
|
|
+ title: '日落',//list[0],
|
|
|
+ content: list[0] + ' ' + props.sunsetTime,
|
|
|
+ date: '',
|
|
|
+ color: ColorType.night
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ timelineItems.push(
|
|
|
+ {
|
|
|
+ status: 'padding',
|
|
|
+ title: '日出',//list[1],
|
|
|
+ content: list[1] + ' ' + props.sunriseTmrTime,
|
|
|
+ date: '',
|
|
|
+ color: ColorType.night
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
else {
|
|
|
- timelineItems.push(
|
|
|
- {
|
|
|
- status: showExtraData() ? 'done' : 'padding',
|
|
|
- title: '日出',//dayDurationDesc(),
|
|
|
- content: dayDurationDesc()+' '+props.sunriseTime,
|
|
|
- date: '',
|
|
|
- color: ColorType.day
|
|
|
- }
|
|
|
- )
|
|
|
-
|
|
|
- timelineItems.push(
|
|
|
- {
|
|
|
- status: 'padding',
|
|
|
- title: '日落',//dayDurationDesc(),
|
|
|
- content: dayDurationDesc()+' '+props.sunsetTime,
|
|
|
- date: '',
|
|
|
- color: ColorType.day
|
|
|
- }
|
|
|
- )
|
|
|
+ if (isCompleted()) {
|
|
|
+ timelineItems.push(
|
|
|
+ {
|
|
|
+ status: 'done',
|
|
|
+ title: '日落',//list[0],
|
|
|
+ content: TimeFormatter.dateTimeFormate(props.authInfo.day_completed.sunrise_ts, true),
|
|
|
+ date: '',
|
|
|
+ color: ColorType.night
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ timelineItems.push(
|
|
|
+ {
|
|
|
+ status: 'done',
|
|
|
+ title: '日出',//list[1],
|
|
|
+ content: TimeFormatter.dateTimeFormate(props.authInfo.day_completed.sunset_ts, true),
|
|
|
+ date: '',
|
|
|
+ color: ColorType.night
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ timelineItems.push(
|
|
|
+ {
|
|
|
+ status: showExtraData() ? 'done' : 'padding',
|
|
|
+ title: '日出',//dayDurationDesc(),
|
|
|
+ content: dayDurationDesc() + ' ' + props.sunriseTime,
|
|
|
+ date: '',
|
|
|
+ color: ColorType.day
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ timelineItems.push(
|
|
|
+ {
|
|
|
+ status: 'padding',
|
|
|
+ title: '日落',//dayDurationDesc(),
|
|
|
+ content: dayDurationDesc() + ' ' + props.sunsetTime,
|
|
|
+ date: '',
|
|
|
+ color: ColorType.day
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|
|
|
return <View style={{ display: 'flex', flexDirection: 'row' }}>
|
|
|
<Timeline items={timelineItems} title='' width={468} />
|
|
|
@@ -275,7 +369,13 @@ export default function DayNightDetailPopup(props: {
|
|
|
}
|
|
|
|
|
|
return <View className='detail_container'>
|
|
|
- <Text className='detail_popup_title'>{getTitle()}</Text>
|
|
|
+ {
|
|
|
+ isCompleted()?<Text className='detail_popup_title'>{getCompletedTitle()}<Text className='detail_popup_subttitle'> {getSubTitle()}</Text></Text>:
|
|
|
+ <Text className='detail_popup_title'>{getTitle()}</Text>
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
<View className='detail_tabbar'>
|
|
|
<View onClick={() => { setTabIndex(0) }} className={tabIndex == 0 ? 'detail_tabitem_sel' : 'detail_tabitem_nor'}>{t('feature.day_night.overview')}</View>
|
|
|
<View onClick={() => { setTabIndex(1) }} className={tabIndex == 1 ? 'detail_tabitem_sel' : 'detail_tabitem_nor'}>{t('feature.day_night.events')}</View>
|