Show quantity correctly
Signed-off-by: James Ketrenos <james_eikona@ketrenos.com>
This commit is contained in:
parent
056b388520
commit
afabcd057f
@ -14,20 +14,22 @@ const Whisky = (props : { active?: boolean, whisky: any, style: any }) => {
|
|||||||
|
|
||||||
const locations: any[] = [];
|
const locations: any[] = [];
|
||||||
|
|
||||||
whisky.inventories.forEach((item : { location: any, quantity: number, updated: string }) => {
|
if (whisky.inventories) {
|
||||||
quantity += item.quantity;
|
whisky.inventories.forEach((item : { location: any, quantity: number, updated: string }) => {
|
||||||
const updated = moment(item.updated, 'YYYY-MM-DD');
|
quantity += item.quantity;
|
||||||
if (time < updated) {
|
const updated = moment(item.updated, 'YYYY-MM-DD');
|
||||||
time = updated;
|
if (time < updated) {
|
||||||
}
|
time = updated;
|
||||||
locations.push(
|
}
|
||||||
<View key={item.location.code} style={[styles.horizontal,styles.container]}>
|
locations.push(
|
||||||
<Text style={whiskyStyles.address}>{item.location.address}</Text>
|
<View key={item.location.code} style={[styles.horizontal,styles.container]}>
|
||||||
<Text style={whiskyStyles.phone}>{item.location.phone}</Text>
|
<Text style={whiskyStyles.address}>{item.location.address}</Text>
|
||||||
<Text style={whiskyStyles.quantity}>{item.quantity}</Text>
|
<Text style={whiskyStyles.phone}>{item.location.phone}</Text>
|
||||||
</View>
|
<Text style={whiskyStyles.quantity}>{item.quantity}</Text>
|
||||||
)
|
</View>
|
||||||
});
|
)
|
||||||
|
});
|
||||||
|
}
|
||||||
const date = (time.unix() == 0) ? "" : time.format("YYYY-MM-DD");
|
const date = (time.unix() == 0) ? "" : time.format("YYYY-MM-DD");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -36,7 +38,7 @@ const Whisky = (props : { active?: boolean, whisky: any, style: any }) => {
|
|||||||
<View style={whiskyStyles.code}><Text>{whisky.code}</Text></View>
|
<View style={whiskyStyles.code}><Text>{whisky.code}</Text></View>
|
||||||
<View style={whiskyStyles.description}><Text>{whisky.description}</Text></View>
|
<View style={whiskyStyles.description}><Text>{whisky.description}</Text></View>
|
||||||
<View style={whiskyStyles.date}><Text>{date}</Text></View>
|
<View style={whiskyStyles.date}><Text>{date}</Text></View>
|
||||||
<View style={whiskyStyles.quantity}><Text>{quantity}</Text></View>
|
<View style={whiskyStyles.quantity}><Text>{whisky.quantity}</Text></View>
|
||||||
</View>
|
</View>
|
||||||
{ props.active && <View style={styles.vertical}>
|
{ props.active && <View style={styles.vertical}>
|
||||||
{ locations }
|
{ locations }
|
||||||
@ -85,6 +87,7 @@ const whiskyStyles = StyleSheet.create({
|
|||||||
export default function App() {
|
export default function App() {
|
||||||
const [whiskies, setWhiskies] = useState<any>(null),
|
const [whiskies, setWhiskies] = useState<any>(null),
|
||||||
[search, setSearch] = useState<string>(""),
|
[search, setSearch] = useState<string>(""),
|
||||||
|
[lastSearch, setLastSearch] = useState<string>(""),
|
||||||
[activeWhisky, setActiveWhisky] = useState<string>("");
|
[activeWhisky, setActiveWhisky] = useState<string>("");
|
||||||
|
|
||||||
const onPress = (code : string) => {
|
const onPress = (code : string) => {
|
||||||
@ -92,7 +95,8 @@ export default function App() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const items = whiskies ? whiskies
|
const items = whiskies ? whiskies
|
||||||
.filter((item : any) => item.size == 750 && item.inventories.length)
|
.filter((item : any) => item.size == 750)
|
||||||
|
.sort((a : any, b : any) => a.description.localeCompare(b.description))
|
||||||
.map((whisky : any) => {
|
.map((whisky : any) => {
|
||||||
const active = whisky.code == activeWhisky;
|
const active = whisky.code == activeWhisky;
|
||||||
return (
|
return (
|
||||||
@ -127,40 +131,31 @@ export default function App() {
|
|||||||
}
|
}
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
client.request(query)
|
|
||||||
.then(data => {
|
|
||||||
setWhiskies(data.Whiskies);
|
|
||||||
})
|
|
||||||
.catch (error => {
|
|
||||||
console.error(error);
|
|
||||||
});
|
|
||||||
|
|
||||||
const submitSearch = () => {
|
const submitSearch = () => {
|
||||||
const query = gql` {
|
if (search.trim() == "") {
|
||||||
Whiskies {
|
setWhiskies([]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastSearch == search) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const _query = gql` {
|
||||||
|
Whiskies(code:"${search}") {
|
||||||
code
|
code
|
||||||
description
|
description
|
||||||
price
|
price
|
||||||
size
|
size
|
||||||
lastSeen
|
lastSeen
|
||||||
inventories {
|
quantity
|
||||||
location {
|
updated
|
||||||
code
|
|
||||||
address
|
|
||||||
city
|
|
||||||
phone
|
|
||||||
longitude
|
|
||||||
latitude
|
|
||||||
}
|
|
||||||
quantity
|
|
||||||
updated
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
console.log(search);
|
setLastSearch(search);
|
||||||
|
|
||||||
client.request(query)
|
client.request(_query)
|
||||||
.then(data => {
|
.then(data => {
|
||||||
setWhiskies(data.Whiskies);
|
setWhiskies(data.Whiskies);
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user