2024-07-31 19:01:45 +02:00
|
|
|
import { Product, priceDisplay, pricePerUnitDisplay } from "@/lib/product"
|
2024-07-01 04:49:41 +02:00
|
|
|
import { ImageBackground, StyleProp, StyleSheet, Text, TouchableHighlight, View, ViewStyle } from "react-native";
|
2024-06-27 23:31:59 +02:00
|
|
|
import { AnimatedStyle } from "react-native-reanimated";
|
|
|
|
|
|
|
|
export type OnProductSelectedFunc = (product : Product) => any;
|
|
|
|
|
|
|
|
type MyStyle = StyleProp<AnimatedStyle<StyleProp<ViewStyle>>>;
|
|
|
|
|
2024-07-01 21:23:45 +02:00
|
|
|
type StyleSpec = {
|
|
|
|
highlight?: MyStyle,
|
|
|
|
text?: MyStyle,
|
|
|
|
image?: MyStyle,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-06-27 23:31:59 +02:00
|
|
|
export type ProductTileProps = {
|
|
|
|
product: (Product),
|
|
|
|
onProductSelected?: OnProductSelectedFunc,
|
2024-07-01 04:49:41 +02:00
|
|
|
isActive: boolean,
|
2024-06-27 23:31:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const FALLBACK_IMAGE = "";
|
|
|
|
|
2024-07-01 21:23:45 +02:00
|
|
|
export function ProductTile ({product, onProductSelected, isActive} : ProductTileProps) {
|
|
|
|
const k = isActive ? "active" : "default";
|
2024-07-31 19:01:45 +02:00
|
|
|
|
|
|
|
const priceDisplay = pricePerUnitDisplay(product);
|
2024-06-27 23:31:59 +02:00
|
|
|
return (
|
2024-07-01 04:49:41 +02:00
|
|
|
|
|
|
|
<TouchableHighlight
|
2024-08-10 19:06:25 +02:00
|
|
|
aria-label={`product ${product.id}`}
|
2024-07-01 21:23:45 +02:00
|
|
|
style={styles[k].highlight}
|
2024-07-01 04:49:41 +02:00
|
|
|
onPress={() => onProductSelected && onProductSelected(product)}>
|
2024-07-31 19:01:45 +02:00
|
|
|
<Text style={styles[k].text}>{product.attributes?.name || `Product ${product.id}`} ({priceDisplay})</Text>
|
2024-07-01 04:49:41 +02:00
|
|
|
</TouchableHighlight>
|
2024-06-27 23:31:59 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-07-01 21:23:45 +02:00
|
|
|
const styles = {
|
|
|
|
active: StyleSheet.create({
|
|
|
|
highlight: {
|
|
|
|
padding: 10,
|
|
|
|
margin: 2,
|
|
|
|
color: "lightblue",
|
|
|
|
},
|
|
|
|
text: {
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
default: StyleSheet.create({
|
|
|
|
highlight: {
|
|
|
|
padding: 10,
|
|
|
|
margin: 2,
|
|
|
|
backgroundColor: "lightgrey",
|
|
|
|
},
|
|
|
|
text: {
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
}
|