Shares #109

Merged
amigan merged 59 commits from shareUI into trunk 2025-02-14 00:25:03 -05:00
2 changed files with 22 additions and 4 deletions
Showing only changes of commit 57f6e1254b - Show all commits

View file

@ -4,12 +4,21 @@ import { map, Observable, switchMap } from 'rxjs';
import { IncidentRecord } from '../incidents'; import { IncidentRecord } from '../incidents';
import { CallRecord } from '../calls'; import { CallRecord } from '../calls';
import { Share, ShareType } from '../shares'; import { Share, ShareType } from '../shares';
import { ActivatedRoute, Router } from '@angular/router';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
}) })
export class ShareService { 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<Share> { getShare(id: string): Observable<Share> {
return this.http.get<Share>(`/share/${id}`); return this.http.get<Share>(`/share/${id}`);

View file

@ -5,11 +5,13 @@ import {
Observable, Observable,
ReplaySubject, ReplaySubject,
shareReplay, shareReplay,
Subject,
Subscription, Subscription,
switchMap, switchMap,
} from 'rxjs'; } from 'rxjs';
import { Talkgroup, TalkgroupUpdate, TGID } from '../talkgroup'; import { Talkgroup, TalkgroupUpdate, TGID } from '../talkgroup';
import { Share } from '../shares'; import { Share } from '../shares';
import { ShareService } from '../share/share.service';
export interface Pagination { export interface Pagination {
page: number; page: number;
@ -29,9 +31,9 @@ export class TalkgroupService {
private readonly _getTalkgroup = new Map<string, ReplaySubject<Talkgroup>>(); private readonly _getTalkgroup = new Map<string, ReplaySubject<Talkgroup>>();
private tgs$: Observable<Talkgroup[]>; private tgs$: Observable<Talkgroup[]>;
private tags$!: Observable<string[]>; private tags$!: Observable<string[]>;
private fetchAll = new BehaviorSubject<Share|null>(null); private fetchAll = new Subject<Share|null>();
private subscriptions = new Subscription(); private subscriptions = new Subscription();
constructor(private http: HttpClient) { constructor(private http: HttpClient, private shareSvc: ShareService) {
this.tgs$ = this.fetchAll.pipe( this.tgs$ = this.fetchAll.pipe(
switchMap((share) => this.getTalkgroups(share)), switchMap((share) => this.getTalkgroups(share)),
shareReplay(), shareReplay(),
@ -40,10 +42,17 @@ export class TalkgroupService {
switchMap(() => this.getAllTags()), switchMap(() => this.getAllTags()),
shareReplay(), 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(); this.fillTgMap();
} }
setShare(share: Share) { setShare(share: Share|null) {
this.fetchAll.next(share); this.fetchAll.next(share);
} }