Ajout d'un reset de cache après un ajout

This commit is contained in:
Sébastien André
2021-04-28 14:21:02 +02:00
parent 05ed51db66
commit 790cc33a39
3 changed files with 19 additions and 9 deletions

View File

@@ -30,26 +30,26 @@ export class DropzoneService extends BaseService {
return this.serviceRefData.get<Array<DropZoneResp>>(RefData.Dropzone, callToApi);
}
public SetFavoriteDropZone(selectedDz: DropZoneResp): boolean {
public SetFavoriteDropZone(selectedDz: DropZoneResp) {
selectedDz.isFavorite = true;
this.http.put(`${this.apiUrl}/DropZone/AddToFavorite/${selectedDz.id}`,
selectedDz,
{ headers: this.headers })
.subscribe();
return true;
.subscribe(() => {
this.serviceRefData.delete(RefData.Dropzone);
});
}
public RemoveFavoriteDropZone(selectedDz: DropZoneResp): boolean {
public RemoveFavoriteDropZone(selectedDz: DropZoneResp) {
selectedDz.isFavorite = false;
this.http.put(`${this.apiUrl}/DropZone/RemoveToFavorite${selectedDz.id}`,
selectedDz,
{ headers: this.headers })
.subscribe();
return true;
.subscribe(() => {
this.serviceRefData.delete(RefData.Dropzone);
});
}
public AddDropZone(latitude: string,
@@ -72,6 +72,7 @@ export class DropzoneService extends BaseService {
isFavorite: isFavorite
};
this.serviceRefData.delete(RefData.Dropzone);
return this.http.post(`${this.apiUrl}/DropZone`,
bodyNewDropZone,
{ headers: this.headers });

View File

@@ -37,6 +37,7 @@ export class GearService extends BaseService {
reserveCanopy: reserveCanopy
};
this.serviceRefData.delete(RefData.Gear);
return this.http.post(`${this.apiUrl}/Gear`, bodyNewGear, { headers: this.headers});
}
}

View File

@@ -15,7 +15,11 @@ export class ServiceRefData {
this.cache = new Map<RefData, Observable<any>>();
}
public get<T>(key: RefData, callToApi: Observable<T>) : Observable<T> {
public get<T>(key: RefData, callToApi: Observable<T>, withResetCache: boolean = false) : Observable<T> {
if (withResetCache === true) {
this.cache.delete(key);
}
const cached = this.cache.get(key);
if (cached) {
@@ -27,4 +31,8 @@ export class ServiceRefData {
}));
}
}
public delete(key: RefData) {
this.cache.delete(key);
}
}