2023-10-20 22:57:31 +00:00
|
|
|
import { NavigationProp, useNavigation } from "@react-navigation/native";
|
|
|
|
import { format } from "date-fns";
|
2023-10-24 03:16:59 +00:00
|
|
|
import { useCallback, useMemo } from "react";
|
2023-10-20 22:57:31 +00:00
|
|
|
import { List, Text } from "react-native-paper";
|
2023-11-14 22:21:49 +00:00
|
|
|
import { StackParams } from "./AppStack";
|
2023-10-20 22:57:31 +00:00
|
|
|
import Settings from "./settings";
|
|
|
|
import Weight from "./weight";
|
|
|
|
|
|
|
|
export default function WeightItem({
|
|
|
|
item,
|
|
|
|
settings,
|
|
|
|
}: {
|
|
|
|
item: Weight;
|
|
|
|
settings: Settings;
|
|
|
|
}) {
|
2023-11-12 04:10:15 +00:00
|
|
|
const navigation = useNavigation<NavigationProp<StackParams>>();
|
2023-10-20 22:57:31 +00:00
|
|
|
|
|
|
|
const press = useCallback(() => {
|
|
|
|
navigation.navigate("EditWeight", { weight: item });
|
|
|
|
}, [item, navigation]);
|
|
|
|
|
2023-10-24 03:16:59 +00:00
|
|
|
const today = useMemo(() => {
|
|
|
|
const now = new Date();
|
|
|
|
const created = new Date(item.created);
|
|
|
|
return (
|
|
|
|
now.getFullYear() === created.getFullYear() &&
|
|
|
|
now.getMonth() === created.getMonth() &&
|
|
|
|
now.getDate() === created.getDate()
|
|
|
|
);
|
|
|
|
}, [item.created]);
|
2023-10-20 22:57:31 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<List.Item
|
|
|
|
onPress={press}
|
|
|
|
title={`${item.value}${item.unit || "kg"}`}
|
2023-10-24 03:16:59 +00:00
|
|
|
right={() => (
|
|
|
|
<Text
|
|
|
|
style={{
|
|
|
|
alignSelf: "center",
|
|
|
|
textDecorationLine: today ? "underline" : "none",
|
|
|
|
fontWeight: today ? "bold" : "normal",
|
|
|
|
}}
|
|
|
|
>
|
2023-11-21 06:14:53 +00:00
|
|
|
{format(new Date(item.created), settings.date || "Pp")}
|
2023-10-24 03:16:59 +00:00
|
|
|
</Text>
|
|
|
|
)}
|
2023-10-20 22:57:31 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|