diff --git a/src/app/services/sync.service.ts b/src/app/services/sync.service.ts index b7b76fa..14c1d45 100644 --- a/src/app/services/sync.service.ts +++ b/src/app/services/sync.service.ts @@ -42,10 +42,8 @@ export class SyncService { private addMapSymbol(s: MapSymbol, key: string) { let map = this.mapData.value; if(!map[key]) map[key] = {}; - do { - s.updated = new Date().getTime(); - s.id = Md5.hashStr(s.updated.toString()).toString(); - } while (!!map[key][s.id]); + s.updated = new Date().getTime(); + if(!s.id) s.id = Md5.hashStr(s.updated.toString()).toString(); map[key][s.id] = s; this.mapData.next(map); this.mapChanged = true; @@ -90,7 +88,10 @@ export class SyncService { delete(...symbols) { let map = this.mapData.value; - Object.keys(map).forEach(key => symbols.filter(s => !!map[key][s.id]).forEach(s => map[key][s.id].deleted = true)); + Object.keys(map).forEach(key => symbols.filter(s => !!map[key][s.id]).forEach(s => { + map[key][s.id].updated = new Date().getTime(); + map[key][s.id].deleted = true + })); this.mapData.next(map); this.mapChanged = true; this.status.next('modified'); @@ -132,15 +133,14 @@ export class SyncService { let map: MapData = {locations: {}}; Object.keys(newMap).forEach(key => { if(!map[key]) map[key] = {}; - Object.keys(newMap[key]).filter(id => !newMap[key][id].deleted) - .forEach(id => map[key][id] = newMap[key][id]); + Object.keys(newMap[key]).forEach(id => map[key][id] = newMap[key][id]); }); Object.keys(oldMap).filter(key => key != 'locations').forEach(key => { if(!map[key]) map[key] = {}; Object.keys(oldMap[key]).filter(id => { let newS = map[key][id] || false; - return newS && newS.updated > map[key][id].updated; + return !newS && !oldMap[key][id].deleted || newS && oldMap[key][id].updated > newS.updated; }).forEach(id => map[key][id] = oldMap[key][id]); }); return map; diff --git a/src/app/views/map/map.component.ts b/src/app/views/map/map.component.ts index 6c3d666..1ed7e18 100644 --- a/src/app/views/map/map.component.ts +++ b/src/app/views/map/map.component.ts @@ -112,11 +112,8 @@ export class MapComponent implements OnDestroy, OnInit { if(e.symbol.noClick) return; this.syncService.freeze.next(true); this.sub = this.bottomSheet.open(EditSymbolComponent, {data: e, disableClose: true, hasBackdrop: false}).afterDismissed().pipe(finalize(() => this.sub = null)).subscribe(symbol => { + this.syncService.addCircle(symbol); this.syncService.freeze.next(false); - this.syncService.delete(e.symbol); - if(e.item instanceof L.Circle) { - this.syncService.addCircle(symbol); - } }); } });