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 background from '../assets/images/Background.png';
import ColorContext from '../theme/ColorContext';
interface RecipeElementReduceProps {
@ -12,6 +13,53 @@ interface RecipeElementReduceProps {
}
export default function RecipeElementReduce(props: RecipeElementReduceProps) {
const {colors} = useContext(ColorContext)
const styles = StyleSheet.create({
button: {
alignItems: 'center',
justifyContent: 'center',
width : 250,
height: 250,
borderRadius: 40,
backgroundColor: colors.recipeElementBackground,
},
text: {
fontSize: 15,
fontWeight: 'bold',
color: '#6F6532',
marginTop: "4%",
zIndex: 2
},
smallText: {
position: "absolute",
fontSize: 12,
color: '#F2F0E4',
textAlign: "center",
margin : "2%",
zIndex: 2,
fontWeight: "bold",
top: "89.25%"
},
title:{
fontSize: 18,
fontWeight: 'bold',
color: '#524B1A',
zIndex: 2
},
view: {
width : "95%",
height: "95%",
borderRadius: 40,
borderWidth: 2,
padding: "5%",
borderColor: '#73692A',
alignItems: 'center',
justifyContent: "center",
},
});
return (
<View style={styles.button}>
<View style={styles.view}>
@ -24,49 +72,4 @@ export default function RecipeElementReduce(props: RecipeElementReduceProps) {
</View>
</View>
);
}
const styles = StyleSheet.create({
button: {
alignItems: 'center',
justifyContent: 'center',
width : 250,
height: 250,
borderRadius: 40,
backgroundColor: '#E3DEC9',
},
text: {
fontSize: 15,
fontWeight: 'bold',
color: '#756C28',
marginTop: "4%",
zIndex: 2
},
smallText: {
position: "absolute",
fontSize: 12,
color: '#F2F0E4',
textAlign: "center",
margin : "2%",
zIndex: 2,
fontWeight: "bold",
top: "89.25%"
},
title:{
fontSize: 18,
fontWeight: 'bold',
color: '#524B1A',
zIndex: 2
},
view: {
width : "95%",
height: "95%",
borderRadius: 40,
borderWidth: 2,
padding: "5%",
borderColor: '#73692A',
alignItems: 'center',
justifyContent: "center",
},
});
}

@ -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 [];
}
}
@ -199,13 +197,13 @@ export default function Profiles({navigation, props}) {
const profileComponents = profiles.map((profile, index) => (
<View key={index}>
<ProfileDetails
<ProfileDetails
name={profile.name}
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}>
@ -239,7 +237,7 @@ export default function Profiles({navigation, props}) {
</View>
</Modal>
</Portal>
{index < profiles.length - 1 && <View style={styles.separator} />}
{index < profiles.length - 1 && <View style={styles.separator} />}
</View>
));
@ -255,7 +253,6 @@ export default function Profiles({navigation, props}) {
<View style={{marginBottom: "20%"}}/>
</LinearGradient>
</ScrollView>
</PaperProvider>
</SafeAreaProvider>
);

Loading…
Cancel
Save