import formatMilliseconds from "@/utils/format_time";
import { View, Text, Image } from "@tarojs/components";
import './History.scss'
import Taro from "@tarojs/taro";
import dayjs from "dayjs";
import { useSelector } from "react-redux";
import { getThemeColor } from "./hooks/health_hooks";
import Rings, { RingCommon, BgRing, TargetRing, CurrentDot } from "@/features/trackTimeDuration/components/Rings";
import { MainColorType } from "@/context/themes/color";
import { durationArc, startArc } from "./util";
import { IconLongFast, IconMore } from "@/components/basic/Icons";
import showActionSheet from "@/components/basic/ActionSheet";
import { delRecord, makeDone } from "@/services/health";
import showAlert from "@/components/basic/Alert";
import { rpxToPx } from "@/utils/tools";
import NewButton, { NewButtonType } from "@/_health/base/new_button";
import TimeTitleDesc from "@/_health/components/time_title_desc";
import CoverList from "@/_health/components/cover_list";
import { TimeFormatter } from "@/utils/time_format";
import { jumpPage } from "../trackTimeDuration/hooks/Common";
import TargetProgress from "@/_health/components/target_progress";
import Cell from "@/_health/base/cell";
import { setFirstActiveId, setFirstEatId } from "@/store/health";
import JournalCover from "../journal/components/journal_cover";
import TimelineDate from "@/_health/components/timeline_date";
import { useEffect } from "react";
export default function HistoryItem(props: {
data: any,
preData: any,
index: number,
onClick: Function,
isArchived?: boolean,
refresh?: Function,
mode: string,
fast_type?: string,
hideLine?: boolean,
type?: string
}) {
const health = useSelector((state: any) => state.health);
const scale = '?x-oss-process=image/format,webp/resize,w_400'
useEffect(()=>{
return ()=>{
console.log('dealloc history item')
}
},[])
function goDetail(event_id?: any) {
// debugger
if (props.mode == 'EAT' || props.mode == 'ACTIVE') {
// jumpPage(`/_health/pages/timeline_detail?event_id=${event_id}&fast_type=${props.fast_type}&isfastsleep=0`)
}
else {
jumpPage(`/_health/pages/timeline_detail?disable_edit=1&window_id=${props.data.window_id}&fast_type=${props.fast_type}&type=recent&isfastsleep=${props.mode == 'FAST,SLEEP' ? 1 : 0}`)
}
}
function singleItem(type, url, obj, key,urls=[]) {
return {
if (process.env.TARO_ENV == 'weapp') {
e.stopPropagation()
}
if (type == 'PIC') {
var temp: any = null
props.data.events.map(item => {
item.moments && item.moments.map(moment => {
if (moment.media && moment.media.length > 0) {
if (moment.media[0].url == url) {
temp = item
}
}
})
})
if (temp) {
jumpPage(`/_health/pages/timeline_detail?disable_edit=1&event_id=${temp.id}&isfastsleep=0`)
}
}
else {
jumpPage(`/_health/pages/timeline_detail?disable_edit=1&event_id=${obj.event_id}&isfastsleep=0`)
}
}}
style={{ display: 'flex', flexDirection: 'row', marginBottom: rpxToPx(12), flex: 1 }} key={key * 1000}>
{
type == 'TEXT' &&
}
{
type == 'PIC' &&
}
{
type == 'PIC_TEXT' && {
if (process.env.TARO_ENV == 'weapp') {
e.stopPropagation()
}
Taro.previewImage({
current: urls[0],
urls: urls
})
}}>
// {
// if (process.env.TARO_ENV == 'weapp') {
// e.stopPropagation()
// }
// Taro.previewImage({
// current: url,
// urls: [url]
// })
// }}
// mode="aspectFill" />
}
{
type == 'PIC_TEXT' &&
}
}
function imgText() {
if (props.data.texts.length == 0 && props.data.pics.length == 0) {
return
}
return
{
props.data.pics.length > 0 &&
}
{
props.data.texts.map((item2, index2) => {
return 0 ? rpxToPx(310) : rpxToPx(512) }}
time=''
title={item2.title}
desc={item2.description}
/>
})
}
}
return
{
props.mode != 'EAT' && props.mode != 'ACTIVE' && props.data.dataArray.map((content, i) => {
var urlArray:any = []
if (content.type == 'PIC_TEXT'){
urlArray = content.data[0].urls.map(obj => obj.url);
}
return
{
content.type == 'TEXT' && {content.data.map((detail, j) => {
return
})}
}
{
content.type == 'PIC' &&
}
{
content.type == 'PIC_TEXT' && {
if (process.env.TARO_ENV == 'weapp') {
e.stopPropagation()
}
Taro.previewImage({
current: urlArray[0],
urls: urlArray
})
}}>
// {
// if (process.env.TARO_ENV == 'weapp') {
// e.stopPropagation()
// }
// Taro.previewImage({
// current: content.data[0].url,
// urls: [content.data[0].url]
// })
// }}
// mode="aspectFill" />
}
{
content.type == 'PIC_TEXT' &&
}
})
}
{
props.mode != 'EAT' && props.mode != 'ACTIVE' && imgText()
}
{
(props.mode == 'EAT' || props.mode == 'ACTIVE') && props.data.dataArray.map((content, i) => {
switch (content.type) {
case 'TEXT':
{
return content.data.map((detail, j) => {
return singleItem('TEXT', '', detail, j * 10)
})
}
break
case 'PIC':
{
return content.data.map((detail, j) => {
return singleItem('PIC', detail, '', j * 10)
})
}
break
case 'PIC_TEXT':
const urlArray = content.data[0].urls.map(obj => obj.url);
return singleItem('PIC_TEXT', content.data[0].url, content.data[0], i,urlArray)
break
}
})
}
{
props.type != 'FAST,SLEEP' && props.mode != 'EAT' && props.mode != 'ACTIVE' && props.data.windows.map((item, index) => {
return : null
}
canvasId={`${item.window}${item.window_range.start_timestamp}${index}`}
startTimestamp={item.window_range.start_timestamp}
endTimerstamp={item.window_range.end_timestamp}
/>
})
}
{
props.type == 'FAST,SLEEP' && props.data.windows.length >= 2 &&
}
{/* fast_sleep双环无法展示时,显示一个placeholder 骨架图 */}
{
props.type == 'FAST,SLEEP' && props.data.windows.length < 2 &&
}
}