MaJ Profiles Home Page after Delete
continuous-integration/drone/push Build is passing Details

pull/23/head
Louison PARANT 1 year ago
parent dfcf2a646f
commit 8fdddda189

@ -0,0 +1,30 @@
export default class Profile {
private _name: string;
private _avatar: string;
private _allergy: string[];
private _diets: string[];
constructor( name: string, avatar: string, allergy: string[], diets: string[]) {
this._name = name;
this._avatar = avatar;
this._allergy = allergy;
this._diets = diets;
}
get name(): string {
return this._name;
}
get avatar(): string{
return this._avatar;
}
get allergy(): string[]{
return this._allergy;
}
get diets(): string[]{
return this._diets;
}
}

@ -18,7 +18,6 @@ export default class RecipesService implements IRecipesService {
async getRecipeById(id: number): Promise<Recipes | null>{
try {
const response = await axios.get(`${this.API_URL}/${id}`);
//console.log(response.name);
return response.data as Recipes;
} catch (error) {
throw new Error('Erreur lors de la récupération des ingrédients : ' + error.message);

@ -37,11 +37,10 @@ export default function ProfileElement(props : Profile) {
let imageSource
if(props.avatar == null){
console.log("NUUUULLLLLE" + props.avatar)
imageSource=require("../assets/images/logo.png")
}
else{
imageSource = { uri: props.avatar };
console.log("MAAARCHHEEE" + props.avatar)
}
const styles = StyleSheet.create({

@ -1,7 +1,8 @@
import React from 'react';
import React, {useContext} from 'react';
import {StyleSheet, Text, View, Image} from 'react-native';
import brochette from '../assets/images/brochette.png';
import background from '../assets/images/Background.png';
import ColorContext from '../theme/ColorContext';
interface RecipeElementReduceProps {
@ -12,20 +13,7 @@ interface RecipeElementReduceProps {
}
export default function RecipeElementReduce(props: RecipeElementReduceProps) {
return (
<View style={styles.button}>
<View style={styles.view}>
<Text style={styles.text}>{props.number}</Text>
<Text style={styles.title}>{props.title}</Text>
<Image source={props.image ? props.image : brochette} style={{ width: 100, height: 100, resizeMode: "contain", zIndex: 2}}/>
<View style={{marginBottom: "20%"}}/>
<Image source={background} style={{width: "80%", resizeMode: "contain", position: "absolute", zIndex: 1, top: "90%"}}></Image>
<Text style={styles.smallText}>{props.duration}</Text>
</View>
</View>
);
}
const {colors} = useContext(ColorContext)
const styles = StyleSheet.create({
button: {
@ -34,12 +22,12 @@ const styles = StyleSheet.create({
width : 250,
height: 250,
borderRadius: 40,
backgroundColor: '#E3DEC9',
backgroundColor: colors.recipeElementBackground,
},
text: {
fontSize: 15,
fontWeight: 'bold',
color: '#756C28',
color: '#6F6532',
marginTop: "4%",
zIndex: 2
},
@ -70,3 +58,18 @@ const styles = StyleSheet.create({
justifyContent: "center",
},
});
return (
<View style={styles.button}>
<View style={styles.view}>
<Text style={styles.text}>{props.number}</Text>
<Text style={styles.title}>{props.title}</Text>
<Image source={props.image ? props.image : brochette} style={{ width: 100, height: 100, resizeMode: "contain", zIndex: 2}}/>
<View style={{marginBottom: "20%"}}/>
<Image source={background} style={{width: "80%", resizeMode: "contain", position: "absolute", zIndex: 1, top: "90%"}}></Image>
<Text style={styles.smallText}>{props.duration}</Text>
</View>
</View>
);
}

@ -47,6 +47,9 @@ export default function CreateProfile(props) {
else if (props.avatar == "plus_small.png"){
imageSource = {uri: avatar}
}
else if (props.avatar == ""){
imageSource = require("../assets/images/logo.png")
}
else{
imageSource = {uri: avatar}
}
@ -67,11 +70,8 @@ export default function CreateProfile(props) {
const updatedProfiles = [...existingProfiles, newProfile];
await AsyncStorage.setItem('profiles', JSON.stringify(updatedProfiles));
EventEmitter.emit('profileAdded');
console.log('Profil créé :', newProfile);
props.navigation.goBack();
alert('Profil créé !');
} catch (error) {
console.error('Erreur lors de la création du profil :', error);
@ -169,7 +169,7 @@ export default function CreateProfile(props) {
</View>
<View style={styles.filterBar}>
<Text style={styles.filters}>Filters</Text>
<Text style={styles.nbSelected}>"0 diets selected</Text>
<Text style={styles.nbSelected}>0 diets selected</Text>
</View>
<ListSelect title="Diets" content={die} setSelected={handleSelectedDiets}></ListSelect>
<View style={{marginTop: "6%"}}/>

@ -46,6 +46,10 @@ export default function HomePage({ navigation, props }) {
fetchProfiles();
});
const subscriptionDeleteProfile = EventEmitter.addListener('profileDeleted', async () => {
fetchProfiles();
});
useEffect(() => {
fetchProfiles();
console.log(profiles.length)

@ -44,24 +44,22 @@ export default function Profiles({navigation, props}) {
try {
const updatedProfiles = profiles.filter((profile, i) => i !== index);
await AsyncStorage.setItem('profiles', JSON.stringify(updatedProfiles));
EventEmitter.emit('profileDeleted');
fetchProfiles();
setSelectedProfileIndex(index);
erasePopUp();
alert('Profile Deleted!');
} catch (error) {
console.error('Erreur lors de la suppression du profil :', error);
}
};
const confirmDelete = () => {
erasePopUp();
};
const handleGetProfiles = async () => {
try {
const existingProfiles = await AsyncStorage.getItem('profiles');
return JSON.parse(existingProfiles) || [];
} catch (error) {
console.log("ça maaaaaaaaarche poaaaaaaaaaaaas");
console.log(error);
return [];
}
}
@ -204,8 +202,8 @@ export default function Profiles({navigation, props}) {
avatar={profile.avatar}
diets={profile.diets}
allergies={profile.allergies}
onDeleteProfile={() => raisePopUp(index)}
/>
onModification={() => navigation.navigate("ProfileModification")}
onDeleteProfile={() => raisePopUp(index)}/>
<Portal>
<Modal visible={visible} onDismiss={erasePopUp} contentContainerStyle={containerStyle} style={{marginTop: 0, justifyContent: "flex-start"}}>
<View style={styles.modal}>
@ -255,7 +253,6 @@ export default function Profiles({navigation, props}) {
<View style={{marginBottom: "20%"}}/>
</LinearGradient>
</ScrollView>
</PaperProvider>
</SafeAreaProvider>
);

Loading…
Cancel
Save