|
@@ -7,9 +7,12 @@ import { useEffect, useState } from "react";
|
|
|
import LimitPickers from "@/components/input/LimitPickers";
|
|
import LimitPickers from "@/components/input/LimitPickers";
|
|
|
import Modal from "@/components/layout/Modal";
|
|
import Modal from "@/components/layout/Modal";
|
|
|
import { ColorType } from "@/context/themes/color";
|
|
import { ColorType } from "@/context/themes/color";
|
|
|
|
|
+import { useSelector } from "react-redux";
|
|
|
|
|
|
|
|
export default function Component(props: { data: any, delete: Function, preview: Function }) {
|
|
export default function Component(props: { data: any, delete: Function, preview: Function }) {
|
|
|
|
|
+ const common = useSelector((state: any) => state.common);
|
|
|
const [detail, setDetail] = useState(props.data)
|
|
const [detail, setDetail] = useState(props.data)
|
|
|
|
|
+ const [count, setCount] = useState(0)
|
|
|
const [showModal, setShowModal] = useState(false)
|
|
const [showModal, setShowModal] = useState(false)
|
|
|
const [isStart, setIsStart] = useState(false)
|
|
const [isStart, setIsStart] = useState(false)
|
|
|
const { t } = useTranslation()
|
|
const { t } = useTranslation()
|
|
@@ -63,37 +66,83 @@ export default function Component(props: { data: any, delete: Function, preview:
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function updateTag(index) {
|
|
function updateTag(index) {
|
|
|
- var tags = ['早餐', '午餐', '晚餐', '宵夜']
|
|
|
|
|
- var tag = tags[index]
|
|
|
|
|
|
|
+ var tag = common.meal_tags[index]
|
|
|
editFoodJournal({
|
|
editFoodJournal({
|
|
|
- tags: [tag]
|
|
|
|
|
|
|
+ meal_tag: {
|
|
|
|
|
+ code: tag.code
|
|
|
|
|
+ }
|
|
|
}, detail.id).then(res => {
|
|
}, detail.id).then(res => {
|
|
|
var obj = detail
|
|
var obj = detail
|
|
|
- obj.tags = [tag]
|
|
|
|
|
|
|
+ // obj.tags = [tag]
|
|
|
|
|
+ obj.meal_tag = {
|
|
|
|
|
+ code: tag.code,
|
|
|
|
|
+ label: tag.label
|
|
|
|
|
+ }
|
|
|
setDetail(obj)
|
|
setDetail(obj)
|
|
|
|
|
+ setCount(count + 1)
|
|
|
}).catch(e => {
|
|
}).catch(e => {
|
|
|
|
|
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function updateTime(e) {
|
|
function updateTime(e) {
|
|
|
- console.log(e)
|
|
|
|
|
|
|
+ var date = new Date(e)
|
|
|
|
|
+ var year = date.getFullYear()
|
|
|
|
|
+ var month = date.getMonth() + 1
|
|
|
|
|
+ var day = date.getDate()
|
|
|
|
|
+ var obj: any;
|
|
|
|
|
+ obj = {
|
|
|
|
|
+ start: {
|
|
|
|
|
+ date: (year + '') + (month < 10 ? '0' + month : month) + (day < 10 ? '0' + day : day),
|
|
|
|
|
+ timestamp: e
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!isStart) {
|
|
|
|
|
+ obj = {
|
|
|
|
|
+ end: {
|
|
|
|
|
+ date: (year + '') + (month < 10 ? '0' + month : month) + (day < 10 ? '0' + day : day),
|
|
|
|
|
+ timestamp: e
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ editFoodJournal({
|
|
|
|
|
+ ...obj
|
|
|
|
|
+ }, detail.id).then(res => {
|
|
|
|
|
+ setDetail(res)
|
|
|
|
|
+ setCount(count + 1)
|
|
|
|
|
+ }).catch(e => {
|
|
|
|
|
+
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function getTime(t) {
|
|
|
|
|
+ var date = new Date(t)
|
|
|
|
|
+ var hour = date.getHours()
|
|
|
|
|
+ var minute = date.getMinutes()
|
|
|
|
|
+ return (hour < 10 ? '0' + hour : hour) + ':' + (minute < 10 ? '0' + minute : minute)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return <View className="food_timeline_item" onLongPress={showActionSheet}>
|
|
return <View className="food_timeline_item" onLongPress={showActionSheet}>
|
|
|
{/* <View className="thumb" style={{backgroundColor:'pink'}}/> */}
|
|
{/* <View className="thumb" style={{backgroundColor:'pink'}}/> */}
|
|
|
<View className="tags">
|
|
<View className="tags">
|
|
|
- <Text onClick={() => updateTag(0)}>早餐</Text>
|
|
|
|
|
- <Text onClick={() => updateTag(1)}>午餐</Text>
|
|
|
|
|
- <Text onClick={() => updateTag(2)}>晚餐</Text>
|
|
|
|
|
- <Text onClick={() => updateTag(3)}>宵夜</Text>
|
|
|
|
|
|
|
+ {
|
|
|
|
|
+ common.meal_tags.map((item, index) => {
|
|
|
|
|
+ return <Text onClick={() => updateTag(index)}>{item.label}</Text>
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
</View>
|
|
</View>
|
|
|
<View className="thumb_bg">
|
|
<View className="thumb_bg">
|
|
|
<Image className="thumb" src={detail.cover} mode="aspectFill" onClick={preview} />
|
|
<Image className="thumb" src={detail.cover} mode="aspectFill" onClick={preview} />
|
|
|
<View className="food_desc">
|
|
<View className="food_desc">
|
|
|
- <Text>{detail.tags && detail.tags.length > 0 && detail.tags[0]}</Text>
|
|
|
|
|
|
|
+ <Text>{detail.meal_tag && detail.meal_tag.label}</Text>
|
|
|
|
|
+ <Text>{detail.start && getTime(detail.start.timestamp)} </Text>
|
|
|
|
|
+ {
|
|
|
|
|
+ detail.end.timestamp && <Text>{'-' + getTime(detail.end.timestamp)}</Text>
|
|
|
|
|
+ }
|
|
|
</View>
|
|
</View>
|
|
|
</View>
|
|
</View>
|
|
|
|
|
+ <Text className="food_item_date">{detail.start.date}</Text>
|
|
|
{
|
|
{
|
|
|
showModal && <Modal dismiss={() => { setShowModal(false) }} confirm={() => { setShowModal(false) }}>
|
|
showModal && <Modal dismiss={() => { setShowModal(false) }} confirm={() => { setShowModal(false) }}>
|
|
|
<View className='modal_content'>
|
|
<View className='modal_content'>
|