optimize remote #2

This commit is contained in:
2022-11-10 16:58:53 +01:00
parent 34cb19dfd0
commit beecbdfb22
7 changed files with 24 additions and 24 deletions

View File

@@ -1,6 +1,6 @@
<div *ngIf="shows$ | async as shows"> <div *ngIf="shows$ | async as shows">
<app-card> <app-card>
<p *ngIf="!shows.length" @fade> <p *ngIf="!shows.length">
Es ist derzeit keine Veranstaltung vorhanden Es ist derzeit keine Veranstaltung vorhanden
</p> </p>
@@ -34,7 +34,7 @@
</div> </div>
</div> </div>
<div *ngFor="let song of presentationSongs; trackBy: trackBy" @fade class="song"> <div *ngFor="let song of presentationSongs; trackBy: trackBy" class="song">
<div *ngIf="show" <div *ngIf="show"
[class.active]="show.presentationSongId === song.id" [class.active]="show.presentationSongId === song.id"
class="title song-part" class="title song-part"
@@ -101,7 +101,7 @@
*ngIf="show" *ngIf="show"
[addedLive]="true" [addedLive]="true"
[showSongs]="showSongs" [showSongs]="showSongs"
[songs]="songs" [songs]="songs$|async"
[show]="show" [show]="show"
></app-add-song> ></app-add-song>
</ng-container> </ng-container>

View File

@@ -3,7 +3,6 @@ import {combineLatest, Observable} from 'rxjs';
import {PresentationBackground, Show} from '../../shows/services/show'; import {PresentationBackground, Show} from '../../shows/services/show';
import {ShowSongService} from '../../shows/services/show-song.service'; import {ShowSongService} from '../../shows/services/show-song.service';
import {SongService} from '../../songs/services/song.service'; import {SongService} from '../../songs/services/song.service';
import {Song} from '../../songs/services/song';
import {faDesktop} from '@fortawesome/free-solid-svg-icons'; import {faDesktop} from '@fortawesome/free-solid-svg-icons';
import {ShowService} from '../../shows/services/show.service'; import {ShowService} from '../../shows/services/show.service';
import {ShowSong} from '../../shows/services/show-song'; import {ShowSong} from '../../shows/services/show-song';
@@ -32,7 +31,7 @@ export class RemoteComponent {
public shows$: Observable<Show[]>; public shows$: Observable<Show[]>;
public show: Show | null = null; public show: Show | null = null;
public showSongs: ShowSong[] = []; public showSongs: ShowSong[] = [];
public songs: Song[] = []; public songs$ = this.songService.list$();
public presentationSongs: PresentationSong[] = []; public presentationSongs: PresentationSong[] = [];
public currentShowId: string | null = null; public currentShowId: string | null = null;
public progress = false; public progress = false;
@@ -55,7 +54,6 @@ export class RemoteComponent {
this.shows$ = showService this.shows$ = showService
.list$(true) .list$(true)
.pipe(map(_ => _.filter(_ => _.date.toDate() > new Date(new Date().setMonth(new Date().getMonth() - 1))).sort((a, b) => (b.date < a.date ? -1 : b.date > a.date ? 1 : 0)))); .pipe(map(_ => _.filter(_ => _.date.toDate() > new Date(new Date().setMonth(new Date().getMonth() - 1))).sort((a, b) => (b.date < a.date ? -1 : b.date > a.date ? 1 : 0))));
songService.list$().subscribe(_ => (this.songs = _));
globalSettingsService.get$ globalSettingsService.get$
.pipe( .pipe(
@@ -72,29 +70,28 @@ export class RemoteComponent {
} }
public async onShowChanged(change: string, updateShow = true): Promise<void> { public async onShowChanged(change: string, updateShow = true): Promise<void> {
this.presentationSongs = [];
this.cRef.markForCheck();
if (updateShow) { if (updateShow) {
await this.globalSettingsService.set({currentShow: change}); await this.globalSettingsService.set({currentShow: change});
await this.showService.update$(change, {presentationSongId: 'title'}); await this.showService.update$(change, {presentationSongId: 'title'});
} }
this.currentShowId = change; this.currentShowId = change;
this.showService
.read$(change)
.pipe(debounceTime(10))
.subscribe(show => {
this.show = show;
this.cRef.markForCheck();
});
combineLatest([this.showService.read$(change), this.showSongService.list$(change)]) combineLatest([this.showService.read$(change), this.showSongService.list$(change)])
.pipe(debounceTime(10)) .pipe(debounceTime(300))
.subscribe(([show, list]) => { .subscribe(([show, list]) => {
this.showSongs = list; this.showSongs = list;
this.show = show;
const presentationSongs = list.map(song => ({ const presentationSongs = list.map(song => ({
id: song.id, id: song.id,
title: song.title, title: song.title,
sections: this.textRenderingService.parse(song.text, null), sections: this.textRenderingService.parse(song.text, null),
})); }));
this.presentationSongs = show?.order.map(_ => presentationSongs.filter(f => f.id === _)[0]) ?? []; this.presentationSongs = show?.order.map(_ => presentationSongs.filter(f => f.id === _)[0]) ?? [];
this.cRef.markForCheck();
}); });
} }

View File

@@ -8,7 +8,6 @@
<ng-container *ngIf="shows$ | async as shows"> <ng-container *ngIf="shows$ | async as shows">
<app-card <app-card
*ngIf="getPrivateSongs(shows).length > 0" *ngIf="getPrivateSongs(shows).length > 0"
@fade
[padding]="false" [padding]="false"
heading="meine Veranstaltungen" heading="meine Veranstaltungen"
> >
@@ -24,7 +23,6 @@
<ng-container *ngIf="publicShows$ | async as shows"> <ng-container *ngIf="publicShows$ | async as shows">
<app-card <app-card
*ngIf="shows.length > 0" *ngIf="shows.length > 0"
@fade
[padding]="false" [padding]="false"
heading="veröffentlichte Veranstaltungen" heading="veröffentlichte Veranstaltungen"
> >

View File

@@ -23,7 +23,7 @@ export class NewComponent implements OnInit {
public faSave = faSave; public faSave = faSave;
public constructor(private showService: ShowService, showDataService: ShowDataService, private router: Router) { public constructor(private showService: ShowService, showDataService: ShowDataService, private router: Router) {
this.shows$ = showDataService.list$(); this.shows$ = showDataService.list$;
} }
public ngOnInit(): void { public ngOnInit(): void {

View File

@@ -1,8 +1,8 @@
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {Observable} from 'rxjs'; import {BehaviorSubject, Observable} from 'rxjs';
import {DbService} from '../../../services/db.service'; import {DbService} from '../../../services/db.service';
import {Show} from './show'; import {Show} from './show';
import {QueryFn} from '@angular/fire/compat/firestore/interfaces'; import {map} from 'rxjs/operators';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
@@ -10,10 +10,15 @@ import {QueryFn} from '@angular/fire/compat/firestore/interfaces';
export class ShowDataService { export class ShowDataService {
private collection = 'shows'; private collection = 'shows';
public constructor(private dbService: DbService) {} public constructor(private dbService: DbService) {
this.dbService.col$<Show>(this.collection).subscribe(_ => this.list$.next(_));
}
public list$ = (queryFn?: QueryFn): Observable<Show[]> => this.dbService.col$(this.collection, queryFn); public list$ = new BehaviorSubject<Show[]>([]);
public read$ = (showId: string): Observable<Show | null> => this.dbService.doc$(`${this.collection}/${showId}`); public read$ = (showId: string): Observable<Show | null> => this.list$.pipe(map(_ => _.find(s => s.id === showId) || null));
// public list$ = (): Observable<Show[]> => this.dbService.col$(this.collection);
// public read$ = (showId: string): Observable<Show | null> => this.dbService.doc$(`${this.collection}/${showId}`);
public update = async (showId: string, data: Partial<Show>): Promise<void> => await this.dbService.doc(`${this.collection}/${showId}`).update(data); public update = async (showId: string, data: Partial<Show>): Promise<void> => await this.dbService.doc(`${this.collection}/${showId}`).update(data);
public add = async (data: Partial<Show>): Promise<string> => (await this.dbService.col(this.collection).add(data)).id; public add = async (data: Partial<Show>): Promise<string> => (await this.dbService.col(this.collection).add(data)).id;
} }

View File

@@ -24,7 +24,7 @@ export class ShowService {
public list$(publishedOnly = false): Observable<Show[]> { public list$(publishedOnly = false): Observable<Show[]> {
return this.userService.user$.pipe( return this.userService.user$.pipe(
switchMap( switchMap(
() => this.showDataService.list$(), () => this.showDataService.list$,
(user: User | null, shows: Show[]) => ({user, shows}) (user: User | null, shows: Show[]) => ({user, shows})
), ),
map(s => s.shows.filter(_ => !_.archived).filter(show => show.published || (show.owner === s.user?.id && !publishedOnly))) map(s => s.shows.filter(_ => !_.archived).filter(show => show.published || (show.owner === s.user?.id && !publishedOnly)))

View File

@@ -1,4 +1,4 @@
<div *ngIf="songs$ | async as songs" @fade> <div *ngIf="songs$ | async as songs">
<app-list-header [anyFilterActive]="anyFilterActive"> <app-list-header [anyFilterActive]="anyFilterActive">
<app-filter [songs]="songs" route="songs"></app-filter> <app-filter [songs]="songs" route="songs"></app-filter>
</app-list-header> </app-list-header>