gestion des ressources fonctionnelle, mais pas fini
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import { Chantier, Ressources } from '@/class/class';
|
||||
import { ThemedView, } from '@/components/theme/themed-view';
|
||||
import React, { useState } from 'react';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Image, StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
|
||||
import { ThemedText } from '@/components/theme/themed-text';
|
||||
import { ThemedButton } from '@/components/theme/themed-button';
|
||||
import { getNbUseRessources } from '@/class/utils';
|
||||
import { useReservations } from '@/app/ContextReservation';
|
||||
import { getReservations } from '@/services/ressourcesService';
|
||||
|
||||
type RessourcesQte = [Ressources, number];
|
||||
|
||||
@@ -16,11 +19,11 @@ type Props = {
|
||||
|
||||
export default function RessourceSummary({ressource: ressource,qte,style,sendRessource: sendRessource, ...otherProps }: Props) {
|
||||
|
||||
|
||||
const { reservations, setReservations } = useReservations();
|
||||
const [count,setCount] = useState(qte);
|
||||
|
||||
function onPressAdd(ressource: Ressources): void {
|
||||
if(count<ressource.quantity){
|
||||
if(count<ressource.quantity-getNbUseRessources(ressource,reservations)){
|
||||
setCount(count+1);
|
||||
sendRessource([ressource, count+1]);
|
||||
}
|
||||
@@ -33,20 +36,28 @@ export default function RessourceSummary({ressource: ressource,qte,style,sendRes
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
async function loadReservations() {
|
||||
const list = await getReservations();
|
||||
setReservations(list);
|
||||
}
|
||||
|
||||
loadReservations();
|
||||
}, []);
|
||||
|
||||
|
||||
return(
|
||||
<View style={style}>
|
||||
<ThemedView lvl={2} border={3} style={{padding:10,width:"100%",borderRadius:10,flexDirection: 'row',justifyContent: 'space-between',}}>
|
||||
<View>
|
||||
<ThemedText>{ressource.id}</ThemedText>
|
||||
<ThemedText>{ressource.name}</ThemedText>
|
||||
<ThemedText>{ressource.quantity}</ThemedText>
|
||||
<ThemedText>{ressource.type}</ThemedText>
|
||||
<ThemedText>Nom : {ressource.name}</ThemedText>
|
||||
<ThemedText>Restant : {ressource.quantity-getNbUseRessources(ressource,reservations)}/{ressource.quantity}</ThemedText>
|
||||
</View>
|
||||
<View style={{alignItems:"center"}}>
|
||||
<ThemedButton style={styles.button} lvl={3} onPress={() => onPressAdd(ressource)}>
|
||||
<ThemedText>+</ThemedText>
|
||||
</ThemedButton>
|
||||
<ThemedText>{count}/{ressource.quantity}</ThemedText>
|
||||
<ThemedText>{count}/{ressource.quantity-getNbUseRessources(ressource,reservations)}</ThemedText>
|
||||
<ThemedButton style={styles.button} lvl={3} onPress={() => onPressSub(ressource)}>
|
||||
<ThemedText>-</ThemedText>
|
||||
</ThemedButton>
|
||||
|
||||
Reference in New Issue
Block a user