|
|
@ -14,7 +14,7 @@ export default class ProfileService implements IProfileService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async addProfile(newProfile : Profile): Promise<boolean> {
|
|
|
|
async addProfile(newProfile : Profile): Promise<boolean> {
|
|
|
|
let existingProfiles = await AsyncStorage.getItem('profiles');
|
|
|
|
let existingProfiles = await AsyncStorage.getItem('profiles')
|
|
|
|
existingProfiles = existingProfiles ? JSON.parse(existingProfiles) : [];
|
|
|
|
existingProfiles = existingProfiles ? JSON.parse(existingProfiles) : [];
|
|
|
|
const updatedProfiles = [...existingProfiles, newProfile];
|
|
|
|
const updatedProfiles = [...existingProfiles, newProfile];
|
|
|
|
await AsyncStorage.setItem('profiles', JSON.stringify(updatedProfiles));
|
|
|
|
await AsyncStorage.setItem('profiles', JSON.stringify(updatedProfiles));
|
|
|
@ -22,17 +22,11 @@ export default class ProfileService implements IProfileService {
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async delProfile(profile_name_to_del: string): Promise<boolean> {
|
|
|
|
async delProfile(index: number): Promise<boolean> {
|
|
|
|
const existing_profiles = await this.getProfiles()
|
|
|
|
const existingProfiles = await this.getProfiles()
|
|
|
|
let key: number = -1
|
|
|
|
const updatedProfiles = existingProfiles.filter((profile, i) => i !== index);
|
|
|
|
for (let current_profile of existing_profiles) {
|
|
|
|
await AsyncStorage.setItem('profiles', JSON.stringify(updatedProfiles));
|
|
|
|
if (current_profile.name == profile_name_to_del) {
|
|
|
|
eventEmitter.emit('profileDeleted');
|
|
|
|
let updated_profile = existing_profiles.splice(key, 1)
|
|
|
|
return true
|
|
|
|
await AsyncStorage.setItem('profiles', JSON.stringify(updated_profile))
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
key ++
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|