|
|
@@ -5,7 +5,7 @@ import { ColorType } from "@/context/themes/color";
|
|
|
import WeekCalendarItem from "./WeekCalendarItem";
|
|
|
import { rpxToPx } from "@/utils/tools";
|
|
|
import { TimeFormatter } from "@/utils/time_format";
|
|
|
-import { clockSummaryStats } from "@/services/trackTimeDuration";
|
|
|
+import { clockSummaryStats, eatWakes } from "@/services/trackTimeDuration";
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
import { IconBigArrow } from "@/components/basic/Icons";
|
|
|
import dayjs from "dayjs";
|
|
|
@@ -24,7 +24,7 @@ if (process.env.TARO_ENV == 'rn') {
|
|
|
}
|
|
|
|
|
|
|
|
|
-const WeekCalendar = memo(() => {
|
|
|
+const WeekCalendar = memo((props: { isFastSleep: boolean }) => {
|
|
|
const [calendars, setCalendars] = useState<any>([])
|
|
|
const [current, setCurrent] = useState(0)
|
|
|
const [summary, setSummary] = useState<any>(null)
|
|
|
@@ -53,20 +53,39 @@ const WeekCalendar = memo(() => {
|
|
|
}
|
|
|
var list: any = []
|
|
|
var offset = 12 * 3600 * 1000 + pageIndex * pageSize * 24 * 3600 * 1000
|
|
|
+ if (!props.isFastSleep){
|
|
|
+ offset = pageIndex * pageSize * 24 * 3600 * 1000
|
|
|
+ }
|
|
|
for (var i = 0; i < pageSize; i++) {
|
|
|
list.push(`${i + pageIndex * pageSize},${timestamp - 7 * 24 * 3600 * 1000 * i - offset},${timestamp - 7 * 24 * 3600 * 1000 * i + 7 * 24 * 3600 * 1000 - offset}`)
|
|
|
}
|
|
|
- clockSummaryStats({ times: list.join(';') }).then(res => {
|
|
|
- var list = (res as any).data.reverse()
|
|
|
- if (pageIndex == 0) {
|
|
|
- setCalendars(list)
|
|
|
- setSummary(list[current].summary_stats ? list[current].summary_stats : null)
|
|
|
- setCalendarData(list[current])
|
|
|
-
|
|
|
- setIsLoading(false)
|
|
|
- }
|
|
|
-
|
|
|
- })
|
|
|
+ if (props.isFastSleep){
|
|
|
+ clockSummaryStats({ times: list.join(';') }).then(res => {
|
|
|
+ var list = (res as any).data.reverse()
|
|
|
+ if (pageIndex == 0) {
|
|
|
+ setCalendars(list)
|
|
|
+ setSummary(list[current].summary_stats ? list[current].summary_stats : null)
|
|
|
+ setCalendarData(list[current])
|
|
|
+
|
|
|
+ setIsLoading(false)
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ eatWakes({ times: list.join(';') }).then(res => {
|
|
|
+ var list = (res as any).data.reverse()
|
|
|
+ if (pageIndex == 0) {
|
|
|
+ setCalendars(list)
|
|
|
+ setSummary(list[current].summary_stats ? list[current].summary_stats : null)
|
|
|
+ setCalendarData(list[current])
|
|
|
+
|
|
|
+ setIsLoading(false)
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
function getRecords() {
|
|
|
@@ -80,36 +99,72 @@ const WeekCalendar = memo(() => {
|
|
|
}
|
|
|
var list: any = []
|
|
|
var offset = 12 * 3600 * 1000 + pageIndex * pageSize * 24 * 3600 * 1000
|
|
|
+ if (!props.isFastSleep){
|
|
|
+ offset = pageIndex * pageSize * 24 * 3600 * 1000
|
|
|
+ }
|
|
|
for (var i = 0; i < pageSize; i++) {
|
|
|
list.push(`${i + pageIndex * pageSize},${timestamp - 7 * 24 * 3600 * 1000 * i - offset},${timestamp - 7 * 24 * 3600 * 1000 * i + 7 * 24 * 3600 * 1000 - offset}`)
|
|
|
}
|
|
|
- clockSummaryStats({ times: list.join(';') }).then(res => {
|
|
|
- var list = (res as any).data.reverse()
|
|
|
- if (list.length > 1) {
|
|
|
- lastFastValue = list[list.length - 2].summary_stats.fast.avg
|
|
|
- lastSleepValue = list[list.length - 2].summary_stats.sleep.avg
|
|
|
- }
|
|
|
|
|
|
- if (pageIndex == 0) {
|
|
|
- setCalendars(list)
|
|
|
- setCurrent(list.length - 1)
|
|
|
- setSummary(list[list.length - 1].summary_stats ? list[list.length - 1].summary_stats : null)
|
|
|
- setCalendarData(list[list.length - 1])
|
|
|
- setMinTime((res as any).extra.real_start_time_min)
|
|
|
- setLeft((list.length - 1) * parseInt(rpxToPx(658) + ''))
|
|
|
- setIsLoading(false);
|
|
|
- if (ref.current) {
|
|
|
- (ref.current as any).scrollToOffset((list.length - 1) * parseInt(rpxToPx(658) + ''), false);
|
|
|
- setTimeout(() => {
|
|
|
+ if (props.isFastSleep){
|
|
|
+ clockSummaryStats({ times: list.join(';') }).then(res => {
|
|
|
+ var list = (res as any).data.reverse()
|
|
|
+ if (list.length > 1) {
|
|
|
+ lastFastValue = list[list.length - 2].summary_stats.fast.avg
|
|
|
+ lastSleepValue = list[list.length - 2].summary_stats.sleep.avg
|
|
|
+ }
|
|
|
+
|
|
|
+ if (pageIndex == 0) {
|
|
|
+ setCalendars(list)
|
|
|
+ setCurrent(list.length - 1)
|
|
|
+ setSummary(list[list.length - 1].summary_stats ? list[list.length - 1].summary_stats : null)
|
|
|
+ setCalendarData(list[list.length - 1])
|
|
|
+ setMinTime((res as any).extra.real_start_time_min)
|
|
|
+ setLeft((list.length - 1) * parseInt(rpxToPx(658) + ''))
|
|
|
+ setIsLoading(false);
|
|
|
+ if (ref.current) {
|
|
|
(ref.current as any).scrollToOffset((list.length - 1) * parseInt(rpxToPx(658) + ''), false);
|
|
|
- }, 500)
|
|
|
+ setTimeout(() => {
|
|
|
+ (ref.current as any).scrollToOffset((list.length - 1) * parseInt(rpxToPx(658) + ''), false);
|
|
|
+ }, 500)
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- else {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- })
|
|
|
+ else {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ eatWakes({ times: list.join(';') }).then(res => {
|
|
|
+ var list = (res as any).data.reverse()
|
|
|
+ if (list.length > 1) {
|
|
|
+ lastFastValue = list[list.length - 2].summary_stats.eat.avg
|
|
|
+ lastSleepValue = list[list.length - 2].summary_stats.wake.avg
|
|
|
+ }
|
|
|
+
|
|
|
+ if (pageIndex == 0) {
|
|
|
+ setCalendars(list)
|
|
|
+ setCurrent(list.length - 1)
|
|
|
+ setSummary(list[list.length - 1].summary_stats ? list[list.length - 1].summary_stats : null)
|
|
|
+ setCalendarData(list[list.length - 1])
|
|
|
+ setMinTime((res as any).extra.real_start_time_min)
|
|
|
+ setLeft((list.length - 1) * parseInt(rpxToPx(658) + ''))
|
|
|
+ setIsLoading(false);
|
|
|
+ if (ref.current) {
|
|
|
+ (ref.current as any).scrollToOffset((list.length - 1) * parseInt(rpxToPx(658) + ''), false);
|
|
|
+ setTimeout(() => {
|
|
|
+ (ref.current as any).scrollToOffset((list.length - 1) * parseInt(rpxToPx(658) + ''), false);
|
|
|
+ }, 500)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
// clockSummaryStats({start:new Date().getTime()-7*24*3600*1000,end:new Date().getTime()}).then(res => { })
|
|
|
}
|
|
|
|
|
|
@@ -157,8 +212,8 @@ const WeekCalendar = memo(() => {
|
|
|
|
|
|
function onChange(e) {
|
|
|
var page = e.detail.current
|
|
|
- lastFastValue = calendars[current].summary_stats.fast.avg
|
|
|
- lastSleepValue = calendars[current].summary_stats.sleep.avg
|
|
|
+ lastFastValue = props.isFastSleep?calendars[current].summary_stats.fast.avg:calendars[current].summary_stats.eat.avg
|
|
|
+ lastSleepValue = props.isFastSleep?calendars[current].summary_stats.sleep.avg:calendars[current].summary_stats.wake.avg
|
|
|
setCurrent(page)
|
|
|
setSummary(calendars[page].summary_stats ? calendars[page].summary_stats : null)
|
|
|
setCalendarData(calendars[page])
|
|
|
@@ -175,8 +230,14 @@ const WeekCalendar = memo(() => {
|
|
|
|
|
|
function getWeekDuration() {
|
|
|
if (global.language == 'en') {
|
|
|
+ if (!props.isFastSleep) {
|
|
|
+ return `${t('feature.common.day_of_week_full.mon')}, ${getDate(calendarData.start)} - ${t('feature.common.day_of_week_full.sun')}, ${getDate(calendarData.end-1)}`
|
|
|
+ }
|
|
|
return `${t('feature.common.day_of_week_full.sun')} ${t('feature.common.time_desc.afternoon')}, ${getDate(calendarData.start)} - ${t('feature.common.day_of_week_full.sun')} ${t('feature.common.time_desc.morning')}, ${getDate(calendarData.end)}`
|
|
|
}
|
|
|
+ if (!props.isFastSleep) {
|
|
|
+ return `${getDate(calendarData.start)} ${t('feature.common.day_of_week_full.mon')} - ${getDate(calendarData.end-1)} ${t('feature.common.day_of_week_full.sun')}`
|
|
|
+ }
|
|
|
return `${getDate(calendarData.start)} ${t('feature.common.day_of_week_full.sun')}${t('feature.common.time_desc.afternoon')} - ${getDate(calendarData.end)} ${t('feature.common.day_of_week_full.sun')}${t('feature.common.time_desc.morning')}`
|
|
|
}
|
|
|
|
|
|
@@ -193,49 +254,49 @@ const WeekCalendar = memo(() => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- function showWeeklyItem(index){
|
|
|
- if (process.env.TARO_ENV=='weapp'){
|
|
|
- if (index >= current - 1 && index <= current + 1){
|
|
|
+ function showWeeklyItem(index) {
|
|
|
+ if (process.env.TARO_ENV == 'weapp') {
|
|
|
+ if (index >= current - 1 && index <= current + 1) {
|
|
|
return true
|
|
|
}
|
|
|
return false
|
|
|
}
|
|
|
- if (index >= current - 2 && index <= current + 2){
|
|
|
+ if (index >= current - 2 && index <= current + 2) {
|
|
|
return true
|
|
|
}
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
if (!calendarData)
|
|
|
- return <View />
|
|
|
+ return <View style={{height:parseInt(rpxToPx(520) + '')+rpxToPx(16)+rpxToPx(32)+rpxToPx(20)+rpxToPx(72)}}/>
|
|
|
return <View style={{ display: 'flex', flexDirection: 'column' }}>
|
|
|
<View className="calendar_summary_top">
|
|
|
<View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', flex: 1 }}>
|
|
|
{
|
|
|
- !summary || summary.fast.avg == 0 ? <View className="calendar-empty-bg" style={{ borderColor: ColorType.fast }}>
|
|
|
- <View className="calendar-empty-line" style={{ backgroundColor: ColorType.fast }} />
|
|
|
+ !summary || (props.isFastSleep?summary.fast.avg == 0:summary.eat.avg == 0) ? <View className="calendar-empty-bg" style={{ borderColor: props.isFastSleep ? ColorType.fast : ColorType.food }}>
|
|
|
+ <View className="calendar-empty-line" style={{ backgroundColor: props.isFastSleep ? ColorType.fast : ColorType.food }} />
|
|
|
</View> :
|
|
|
- <View className={lastFastValue > summary.fast.avg ? 'calendar-arrow-bg-down' : 'calendar-arrow-bg'} style={{ backgroundColor: ColorType.fast }}>
|
|
|
+ <View className={(props.isFastSleep?lastFastValue > summary.fast.avg:lastFastValue > summary.eat.avg) ? 'calendar-arrow-bg-down' : 'calendar-arrow-bg'} style={{ backgroundColor: props.isFastSleep ? ColorType.fast : ColorType.food }}>
|
|
|
<IconBigArrow color="#fff" width={rpxToPx(32)} />
|
|
|
</View>
|
|
|
}
|
|
|
<View className="calendar_summary_item">
|
|
|
- <Text className="calendar_summary_title">{t('feature.track_time_duration.weekly.fast_average')}</Text>
|
|
|
- <Text className="calendar_summary_value" style={{ color: ColorType.fast }}>{!summary || summary.fast.avg == 0 ? t('feature.track_time_duration.record_fast_sleep.none') : TimeFormatter.calculateTimeDifference(new Date().getTime(), new Date().getTime() + summary.fast.avg)}</Text>
|
|
|
+ <Text className="calendar_summary_title">{props.isFastSleep ? t('feature.track_time_duration.weekly.fast_average') : t('feature.track_time_duration.weekly.eat_average')}</Text>
|
|
|
+ <Text className="calendar_summary_value" style={{ color: props.isFastSleep ? ColorType.fast : ColorType.food }}>{!summary || (props.isFastSleep?summary.fast.avg == 0:summary.eat.avg == 0) ? t('feature.track_time_duration.record_fast_sleep.none') : TimeFormatter.calculateTimeDifference(new Date().getTime(), new Date().getTime() + (props.isFastSleep?summary.fast.avg:summary.eat.avg))}</Text>
|
|
|
</View>
|
|
|
</View>
|
|
|
<View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', flex: 1 }}>
|
|
|
{
|
|
|
- !summary || summary.sleep.avg == 0 ? <View className="calendar-empty-bg" style={{ borderColor: ColorType.sleep }}>
|
|
|
- <View className="calendar-empty-line" style={{ backgroundColor: ColorType.sleep }} />
|
|
|
+ !summary || (props.isFastSleep?summary.sleep.avg == 0:summary.wake.avg == 0) ? <View className="calendar-empty-bg" style={{ borderColor: props.isFastSleep ? ColorType.sleep : ColorType.activity }}>
|
|
|
+ <View className="calendar-empty-line" style={{ backgroundColor: props.isFastSleep ? ColorType.sleep : ColorType.activity }} />
|
|
|
</View> :
|
|
|
- <View className={lastSleepValue > summary.sleep.avg ? 'calendar-arrow-bg-down' : 'calendar-arrow-bg'} style={{ backgroundColor: ColorType.sleep }}>
|
|
|
+ <View className={lastSleepValue > (props.isFastSleep?summary.sleep.avg:summary.wake.avg) ? 'calendar-arrow-bg-down' : 'calendar-arrow-bg'} style={{ backgroundColor: props.isFastSleep ? ColorType.sleep : ColorType.activity }}>
|
|
|
<IconBigArrow color="#fff" width={rpxToPx(32)} />
|
|
|
</View>
|
|
|
}
|
|
|
<View className="calendar_summary_item">
|
|
|
- <Text className="calendar_summary_title">{t('feature.track_time_duration.weekly.sleep_average')}</Text>
|
|
|
- <Text className="calendar_summary_value" style={{ color: ColorType.sleep }}>{!summary || summary.sleep.avg == 0 ? t('feature.track_time_duration.record_fast_sleep.none') : TimeFormatter.calculateTimeDifference(new Date().getTime(), new Date().getTime() + summary.sleep.avg)}</Text>
|
|
|
+ <Text className="calendar_summary_title">{props.isFastSleep ? t('feature.track_time_duration.weekly.sleep_average') : t('feature.track_time_duration.weekly.wake_average')}</Text>
|
|
|
+ <Text className="calendar_summary_value" style={{ color: props.isFastSleep ? ColorType.sleep : ColorType.activity }}>{!summary || (props.isFastSleep?summary.sleep.avg == 0:summary.wake.avg == 0) ? t('feature.track_time_duration.record_fast_sleep.none') : TimeFormatter.calculateTimeDifference(new Date().getTime(), new Date().getTime() + (props.isFastSleep?summary.sleep.avg:summary.wake.avg))}</Text>
|
|
|
</View>
|
|
|
</View>
|
|
|
|
|
|
@@ -287,51 +348,35 @@ const WeekCalendar = memo(() => {
|
|
|
return <SwiperItem key={index}>
|
|
|
{
|
|
|
showWeeklyItem(index) ?
|
|
|
- <WeekCalendarItem data={item} isCurrentWeek={index == calendars.length - 1} /> :
|
|
|
+ <WeekCalendarItem data={item} isCurrentWeek={index == calendars.length - 1} isFastSleep={props.isFastSleep} /> :
|
|
|
<View style={{ width: parseInt(rpxToPx(658) + ''), flexShrink: 0 }} />
|
|
|
}
|
|
|
</SwiperItem>
|
|
|
})
|
|
|
}
|
|
|
</Swiper>
|
|
|
- {/* <ScrollView
|
|
|
- style={{
|
|
|
- marginLeft: parseInt(rpxToPx(46) + ''),
|
|
|
- width: parseInt(rpxToPx(658) + ''),
|
|
|
- height: parseInt(rpxToPx(520) + ''),
|
|
|
- flexDirection: 'row', display: 'flex',
|
|
|
-
|
|
|
- }}
|
|
|
- ref={ref}
|
|
|
- showScrollbar={false}
|
|
|
- onScroll={onScroll}
|
|
|
- onDragEnd={dragEnd}
|
|
|
- onDragStart={dragStart}
|
|
|
- scrollLeft={left}
|
|
|
- scrollX pagingEnabled={true}
|
|
|
- showsHorizontalScrollIndicator={false}
|
|
|
- enableFlex enhanced>
|
|
|
- {
|
|
|
- calendars.map((item, index) => {
|
|
|
-
|
|
|
- if (index == current || index == current - 1 || index == current + 1)
|
|
|
- return <WeekCalendarItem data={item} key={index} isCurrentWeek={index == calendars.length - 1} />
|
|
|
- return <View key={index} style={{ width: parseInt(rpxToPx(658) + ''), flexShrink: 0 }} />
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- </ScrollView> */}
|
|
|
- </View>
|
|
|
- <View className="chart_times" style={{ marginTop: parseInt(rpxToPx(60) + ''), marginBottom: parseInt(rpxToPx(60) + '') }}>
|
|
|
- <Text className="chart_times_txt" style={{ left: 0, top: 0 }}>12:00</Text>
|
|
|
- <Text className="chart_times_txt" style={{ left: 0, top: parseInt(rpxToPx(100 - 7) + '') }}>18:00</Text>
|
|
|
- <Text className="chart_times_txt" style={{ left: 0, top: parseInt(rpxToPx(200 - 5) + '') }}>24:00</Text>
|
|
|
- <Text className="chart_times_txt" style={{ left: 0, top: parseInt(rpxToPx(300 - 5) + '') }}>06:00</Text>
|
|
|
- <Text className="chart_times_txt" style={{ left: 0, bottom: 0 }}>12:00</Text>
|
|
|
</View>
|
|
|
+ {
|
|
|
+ props.isFastSleep ? <View className="chart_times" style={{ marginTop: parseInt(rpxToPx(60) + ''), marginBottom: parseInt(rpxToPx(60) + '') }}>
|
|
|
+ <Text className="chart_times_txt" style={{ left: 0, top: 0 }}>12:00</Text>
|
|
|
+ <Text className="chart_times_txt" style={{ left: 0, top: parseInt(rpxToPx(100 - 7) + '') }}>18:00</Text>
|
|
|
+ <Text className="chart_times_txt" style={{ left: 0, top: parseInt(rpxToPx(200 - 5) + '') }}>24:00</Text>
|
|
|
+ <Text className="chart_times_txt" style={{ left: 0, top: parseInt(rpxToPx(300 - 5) + '') }}>06:00</Text>
|
|
|
+ <Text className="chart_times_txt" style={{ left: 0, bottom: 0 }}>12:00</Text>
|
|
|
+ </View> :
|
|
|
+ <View className="chart_times" style={{ marginTop: parseInt(rpxToPx(60) + ''), marginBottom: parseInt(rpxToPx(60) + '') }}>
|
|
|
+ <Text className="chart_times_txt" style={{ left: 0, top: 0 }}>00:00</Text>
|
|
|
+ <Text className="chart_times_txt" style={{ left: 0, top: parseInt(rpxToPx(100 - 7) + '') }}>06:00</Text>
|
|
|
+ <Text className="chart_times_txt" style={{ left: 0, top: parseInt(rpxToPx(200 - 5) + '') }}>12:00</Text>
|
|
|
+ <Text className="chart_times_txt" style={{ left: 0, top: parseInt(rpxToPx(300 - 5) + '') }}>18:00</Text>
|
|
|
+ <Text className="chart_times_txt" style={{ left: 0, bottom: 0 }}>24:00</Text>
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+
|
|
|
</View>
|
|
|
|
|
|
</View>
|
|
|
+
|
|
|
</View>
|
|
|
})
|
|
|
|