diff --git a/client/stillbox/src/app/share/share.service.ts b/client/stillbox/src/app/share/share.service.ts index d13d118..1bebd1f 100644 --- a/client/stillbox/src/app/share/share.service.ts +++ b/client/stillbox/src/app/share/share.service.ts @@ -4,12 +4,21 @@ import { map, Observable, switchMap } from 'rxjs'; import { IncidentRecord } from '../incidents'; import { CallRecord } from '../calls'; import { Share, ShareType } from '../shares'; +import { ActivatedRoute, Router } from '@angular/router'; @Injectable({ providedIn: 'root', }) export class ShareService { - constructor(private http: HttpClient) {} + constructor(private http: HttpClient, private router: Router, private route: ActivatedRoute) {} + + inShare(): string|null { + if(this.router.url.startsWith('/s/')) { + return this.route.snapshot.paramMap.get('id'); + } + + return null; + } getShare(id: string): Observable { return this.http.get(`/share/${id}`); diff --git a/client/stillbox/src/app/talkgroups/talkgroups.service.ts b/client/stillbox/src/app/talkgroups/talkgroups.service.ts index 4c14a19..812edae 100644 --- a/client/stillbox/src/app/talkgroups/talkgroups.service.ts +++ b/client/stillbox/src/app/talkgroups/talkgroups.service.ts @@ -5,11 +5,13 @@ import { Observable, ReplaySubject, shareReplay, + Subject, Subscription, switchMap, } from 'rxjs'; import { Talkgroup, TalkgroupUpdate, TGID } from '../talkgroup'; import { Share } from '../shares'; +import { ShareService } from '../share/share.service'; export interface Pagination { page: number; @@ -29,9 +31,9 @@ export class TalkgroupService { private readonly _getTalkgroup = new Map>(); private tgs$: Observable; private tags$!: Observable; - private fetchAll = new BehaviorSubject(null); + private fetchAll = new Subject(); private subscriptions = new Subscription(); - constructor(private http: HttpClient) { + constructor(private http: HttpClient, private shareSvc: ShareService) { this.tgs$ = this.fetchAll.pipe( switchMap((share) => this.getTalkgroups(share)), shareReplay(), @@ -40,10 +42,17 @@ export class TalkgroupService { switchMap(() => this.getAllTags()), shareReplay(), ); + let sh = this.shareSvc.inShare(); + console.log(sh); + if (sh) { + this.shareSvc.getShare(sh).subscribe(this.fetchAll); + } else { + this.fetchAll.next(null); + } this.fillTgMap(); } - setShare(share: Share) { + setShare(share: Share|null) { this.fetchAll.next(share); }