diff --git a/LeftOvers/Services/Profiles/IProfileService.ts b/LeftOvers/Services/Profiles/IProfileService.ts new file mode 100644 index 0000000..477cc76 --- /dev/null +++ b/LeftOvers/Services/Profiles/IProfileService.ts @@ -0,0 +1,6 @@ +import Profil from "../../Models/Profil"; + +export default interface IProfileService { + getProfiles(): Promise, + addProfile(new_profile: Profil): void +} \ No newline at end of file diff --git a/LeftOvers/Services/Profiles/ProfileService.ts b/LeftOvers/Services/Profiles/ProfileService.ts new file mode 100644 index 0000000..61cd418 --- /dev/null +++ b/LeftOvers/Services/Profiles/ProfileService.ts @@ -0,0 +1,14 @@ +import Profil from "../../Models/Profil"; +import IProfileService from "./IProfileService"; +import AsyncStorage from "@react-native-async-storage/async-storage"; + +export default class ProfileService implements IProfileService { + async getProfiles(): Promise { + const existingProfiles = await AsyncStorage.getItem('profiles'); + return JSON.parse(existingProfiles) || []; + } + addProfile(new_profile : Profil): void { + throw new Error("Method not implemented."); + } + +} \ No newline at end of file diff --git a/LeftOvers/components/ProfileDetails.tsx b/LeftOvers/components/ProfileDetails.tsx index 06ddea2..b0162f1 100644 --- a/LeftOvers/components/ProfileDetails.tsx +++ b/LeftOvers/components/ProfileDetails.tsx @@ -1,5 +1,6 @@ import React, { useContext, useState } from 'react'; import { StyleSheet, Text, View, Image, Pressable } from 'react-native'; +import { useNavigation } from '@react-navigation/native'; import ListWithoutSelect from './ListWithoutSelect'; import ColorContext from '../theme/ColorContext'; diff --git a/LeftOvers/screens/Profiles.tsx b/LeftOvers/screens/Profiles.tsx index b96f90a..dd46e2d 100644 --- a/LeftOvers/screens/Profiles.tsx +++ b/LeftOvers/screens/Profiles.tsx @@ -11,9 +11,11 @@ import AsyncStorage from '@react-native-async-storage/async-storage'; import EventEmitter from './EventEmitter'; import Profil from '../Models/Profil'; import { PaperProvider, Portal } from 'react-native-paper'; +import ProfileService from '../Services/Profiles/ProfileService'; export default function Profiles({navigation, props}) { const colors = useContext(ColorContext).colors + const profile_service = new ProfileService() const all = [] const die = [{value: "Dairy free"}, {value: "Gluten free"}, {value: "Porkless"}, {value: "Vegan"}, {value: "Vegetarian"}, {value: "Pescatarian"}] @@ -56,10 +58,9 @@ export default function Profiles({navigation, props}) { erasePopUp(); }; - const handleGetProfiles = async () => { + const handleGetProfiles = async () => { try { - const existingProfiles = await AsyncStorage.getItem('profiles'); - return JSON.parse(existingProfiles) || []; + return await profile_service.getProfiles() } catch (error) { console.log("ça maaaaaaaaarche poaaaaaaaaaaaas"); return [];