Massive/WeightItem.tsx

50 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-10-20 22:57:31 +00:00
import { NavigationProp, useNavigation } from "@react-navigation/native";
import { format } from "date-fns";
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;
}) {
const navigation = useNavigation<NavigationProp<StackParams>>();
2023-10-20 22:57:31 +00:00
const press = useCallback(() => {
navigation.navigate("EditWeight", { weight: item });
}, [item, navigation]);
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"}`}
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")}
</Text>
)}
2023-10-20 22:57:31 +00:00
/>
);
}