Skip to content

Commit

Permalink
handle removed public lists in subscriber
Browse files Browse the repository at this point in the history
  • Loading branch information
christianaschoff committed Oct 24, 2020
1 parent 25479df commit 7b68b08
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
7 changes: 4 additions & 3 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ export class AppComponent implements OnInit, OnDestroy {

this.currentBookmark = { id, type: BOOKMARK_TYPE.PUBLIC };

// FIX THAT TOO
this.bookmarkService.loadPublicBookmarkList(id, true).subscribe(() => {
this.router.navigateByUrl('/', { skipLocationChange: true }).then(() => this.router.navigate(['/bookmarks']));

/*this.bookmarkService.loadPublicBookmarkList(id, true).subscribe(() => {
this.router.navigate(['/bookmarks']);
});
});*/
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@ <h2>{{ bmk.name }}</h2>
<div class="container">
<div class="left-side">
<ng-container *ngIf="(hasProfilesInBookmark$ | async) === 0">
Füge in der Händerübersicht Deiner Stadt interssante Läden und und spannende Restaurants zu Deinem Einkaufbummel hinzu.
<br />
<br />Unter jedem Geschäft befindet sich ein Herz. Wenn das Herz grün leuchtet, dann hast Du es erfolgreich zugefügt. So einfach geht das!
<br />
<br />Wieviele Geschäfte und Orte Du entdecken willst, erkennst Du an der Zahl über dem Herzsymbol oben im Menü.
<br />
<br />Probiere es gleich aus!
<ng-container *ngIf="!this.isPublicBookmark">
Füge in der Händerübersicht Deiner Stadt interssante Läden und und spannende Restaurants zu Deinem Einkaufbummel hinzu.
<br />
<br />Unter jedem Geschäft befindet sich ein Herz. Wenn das Herz grün leuchtet, dann hast Du es erfolgreich zugefügt. So einfach geht das!
<br />
<br />Wieviele Geschäfte und Orte Du entdecken willst, erkennst Du an der Zahl über dem Herzsymbol oben im Menü.
<br />
<br />Probiere es gleich aus!
</ng-container>
<ng-container *ngIf="this.isPublicBookmark">
Diese Liste ist leider nicht mehr verfügbar :(
<br />
<br />Möchtest Du diese Liste entfernen?
<br />
<br /><lk-button type="button" (click)="deleteBookmark()">Liste Entfernen</lk-button>
</ng-container>
</ng-container>
<ng-container *ngIf="(hasProfilesInBookmark$ | async) > 0">
<div class="button-container">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { MatDialog } from '@angular/material/dialog';
import { BookmarksSharePrivateDialogComponent } from './bookmarks-share-private-dialog/bookmarks-share-private-dialog.component';
import { BookmarksSharePublicDialogComponent } from './bookmarks-share-public-dialog/bookmarks-share-public-dialog.component';
import { MatSelectionList } from '@angular/material/list';
import { Router } from '@angular/router';

export interface TraderProfilesPlus extends TraderProfile {
thumbUrl?: string;
Expand Down Expand Up @@ -42,6 +43,7 @@ export class BookmarksOverviewComponent implements OnInit, OnDestroy {
@ViewChild('lst') private bookmarkUiList: MatSelectionList;

constructor(
public router: Router,
readonly bookmarksService: BookmarksService,
private readonly traderService: TraderService,
private readonly imageService: ImageService,
Expand Down Expand Up @@ -127,6 +129,7 @@ export class BookmarksOverviewComponent implements OnInit, OnDestroy {
deleteBookmark() {
this.bookmarksService.deleteBookmark();
this.hasProfilesInBookmark$ = of(0);
this.router.navigate(['/']);
}

deleteTraderFromBookmark(traderid) {
Expand Down Expand Up @@ -198,8 +201,9 @@ export class BookmarksOverviewComponent implements OnInit, OnDestroy {
}
const currentBookmark = this.storageService.loadActiveBookmarkId();

this.loaderSubscription = this.bookmarksService.loadActiveBookmarkList(currentBookmark).subscribe((bklist: BookmarkList) => {
this.loaderSubscription = this.bookmarksService.loadActiveBookmarkList(currentBookmark, true).subscribe((bklist: BookmarkList) => {
if (!bklist || !bklist.bookmarks) {
this.isPublicBookmark = currentBookmark.type !== BOOKMARK_TYPE.PRIVATE;
return;
}

Expand All @@ -221,6 +225,9 @@ export class BookmarksOverviewComponent implements OnInit, OnDestroy {

this.bookmarkList$ = of(bklist);
this.hasProfilesInBookmark$ = of(bookmarkArray ? bookmarkArray.length : 0);
/* if (this.isPublicBookmark && bookmarkArray) {
this.bookmarksService.overwriteBookmarkTraderCounter(bookmarkArray.length);
}*/
this.map.clearRoute();
if (bklist.geojson) {
this.map.displayGeoJsonOnMap(JSON.parse(atob(bklist.geojson)));
Expand Down
16 changes: 14 additions & 2 deletions src/app/services/bookmarks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AngularFirestore } from '@angular/fire/firestore';
import { BookmarkList } from '../models/bookmarkList';
import { map, tap } from 'rxjs/operators';
import { BookmarkListPublic } from '../models/bookmarkListPublic';
import { count } from 'console';

export interface LocalBookmark {
id: string;
Expand Down Expand Up @@ -135,12 +136,12 @@ export class BookmarksService {
}
}

public loadActiveBookmarkList(activeBookmark: ActiveBookmark): Observable<BookmarkList> {
public loadActiveBookmarkList(activeBookmark: ActiveBookmark, loadIfPublic: boolean = false): Observable<BookmarkList> {
if (!activeBookmark) {
return of(undefined);
}

return activeBookmark.type === BOOKMARK_TYPE.PRIVATE ? this.loadBookmarkList(activeBookmark.id) : this.loadPublicBookmarkList(activeBookmark.id);
return activeBookmark.type === BOOKMARK_TYPE.PRIVATE ? this.loadBookmarkList(activeBookmark.id) : this.loadPublicBookmarkList(activeBookmark.id, loadIfPublic);
}

public loadBookmarkList(id: string): Observable<BookmarkList> {
Expand All @@ -163,6 +164,14 @@ export class BookmarksService {
return of(undefined);
}

public overwriteBookmarkTraderCounter(counter: number) {
if (counter > 0) {
this.bookmarkSubject.next(counter);
} else {
this.bookmarkSubject.next(null);
}
}

public loadPublicBookmarkList(id: string, loadForReal: boolean = false): Observable<BookmarkListPublic> {
if (id) {
return this.db
Expand All @@ -179,6 +188,9 @@ export class BookmarksService {
}
return retval;
} else {
if (loadForReal) {
this.updateLocal(undefined, BOOKMARK_TYPE.PUBLIC);
}
return undefined;
}
})
Expand Down

0 comments on commit 7b68b08

Please sign in to comment.