fix: delete profile now use ProfileService.delProfile(name)
continuous-integration/drone/push Build is passing Details

pull/23/head
Rémi REGNAULT 1 year ago
parent 996d656d18
commit 8e27377e08

@ -2,5 +2,6 @@ import Profil from "../../Models/Profil";
export default interface IProfileService {
getProfiles(): Promise<Profil[]>,
addProfile(new_profile: Profil): Promise<boolean>
addProfile(new_profile: Profil): Promise<boolean>,
delProfile(profile_name_to_del: String): Promise<boolean>
}

@ -25,4 +25,17 @@ export default class ProfileService implements IProfileService {
return true
}
async delProfile(profile_name_to_del: String): Promise<boolean> {
const existing_profiles = await this.getProfiles()
let key: number = -1
for (let current_profile of existing_profiles) {
if (current_profile.name == profile_name_to_del) {
let updated_profile = existing_profiles.splice(key, 1)
await AsyncStorage.setItem('profiles', JSON.stringify(updated_profile))
return true
}
key ++
}
return false
}
}

@ -44,8 +44,7 @@ export default function Profiles({navigation, props}) {
const handleDeleteProfile = async (index) => {
try {
const updatedProfiles = profiles.filter((profile, i) => i !== index);
await AsyncStorage.setItem('profiles', JSON.stringify(updatedProfiles));
await profile_service.delProfile(profiles[index].name)
fetchProfiles();
setSelectedProfileIndex(index);
erasePopUp();

Loading…
Cancel
Save