|
@@ -5,17 +5,18 @@ import { useEffect, useState } from 'react'
|
|
|
import { delFoodJournal } from '@/services/foodJournal'
|
|
import { delFoodJournal } from '@/services/foodJournal'
|
|
|
import Taro from '@tarojs/taro'
|
|
import Taro from '@tarojs/taro'
|
|
|
|
|
|
|
|
-export default function Component(props: { array: any,refresh:Function }) {
|
|
|
|
|
|
|
+export default function Component(props: { array: any, refresh: Function, forceRefresh: Function }) {
|
|
|
const [list, setList] = useState(props.array)
|
|
const [list, setList] = useState(props.array)
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
setList(props.array)
|
|
setList(props.array)
|
|
|
- }, [props.array,props.array.length])
|
|
|
|
|
|
|
+ }, [props.array, props.array.length])
|
|
|
|
|
|
|
|
function del(index) {
|
|
function del(index) {
|
|
|
delFoodJournal(list[index].id).then(res => {
|
|
delFoodJournal(list[index].id).then(res => {
|
|
|
var temps = list.splice(index, 1)
|
|
var temps = list.splice(index, 1)
|
|
|
setList(temps)
|
|
setList(temps)
|
|
|
|
|
+ props.refresh()
|
|
|
}).catch(e => {
|
|
}).catch(e => {
|
|
|
|
|
|
|
|
})
|
|
})
|
|
@@ -32,12 +33,12 @@ export default function Component(props: { array: any,refresh:Function }) {
|
|
|
// })
|
|
// })
|
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
- function preview(index){
|
|
|
|
|
- var urls:any = []
|
|
|
|
|
- list.map(item=>{
|
|
|
|
|
|
|
+ function preview(index) {
|
|
|
|
|
+ var urls: any = []
|
|
|
|
|
+ list.map(item => {
|
|
|
urls.push({
|
|
urls.push({
|
|
|
- url:item.media[0].url,
|
|
|
|
|
- type:item.media[0].url.indexOf('mp4')!=-1?'video':'image'
|
|
|
|
|
|
|
+ url: item.media[0].url,
|
|
|
|
|
+ type: item.media[0].url.indexOf('mp4') != -1 ? 'video' : 'image'
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
Taro.previewMedia({
|
|
Taro.previewMedia({
|
|
@@ -46,7 +47,7 @@ export default function Component(props: { array: any,refresh:Function }) {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function updateItem(index,data){
|
|
|
|
|
|
|
+ function updateItem(index, data) {
|
|
|
list[index] = data
|
|
list[index] = data
|
|
|
setList(list)
|
|
setList(list)
|
|
|
}
|
|
}
|
|
@@ -54,11 +55,12 @@ export default function Component(props: { array: any,refresh:Function }) {
|
|
|
return <View style={{ flexDirection: 'column', display: 'flex' }}>
|
|
return <View style={{ flexDirection: 'column', display: 'flex' }}>
|
|
|
{
|
|
{
|
|
|
list.map((item, index) => {
|
|
list.map((item, index) => {
|
|
|
- return <FoodTimelineItem data={item} index={index} key={index}
|
|
|
|
|
- delete={() => del(index)}
|
|
|
|
|
- preview={()=>preview(index)}
|
|
|
|
|
- update={(data)=>updateItem(index,data)}
|
|
|
|
|
- forceRefresh={()=>props.refresh()}
|
|
|
|
|
|
|
+ return <FoodTimelineItem data={item} index={index} key={index}
|
|
|
|
|
+ delete={() => del(index)}
|
|
|
|
|
+ preview={() => preview(index)}
|
|
|
|
|
+ update={(data) => updateItem(index, data)}
|
|
|
|
|
+ forceRefresh={() => props.forceRefresh()}
|
|
|
|
|
+ refresh={() => props.refresh()}
|
|
|
/>
|
|
/>
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|