optimize remote #3

This commit is contained in:
2026-03-09 18:41:43 +01:00
parent a46eeeee04
commit f7be5c082a
4 changed files with 41 additions and 28 deletions

View File

@@ -83,14 +83,13 @@ export class RemoteComponent implements OnDestroy {
globalSettingsService: GlobalSettingsService, globalSettingsService: GlobalSettingsService,
private cRef: ChangeDetectorRef private cRef: ChangeDetectorRef
) { ) {
const currentShowId$ = globalSettingsService.get$ const currentShowId$ = globalSettingsService.get$.pipe(
.pipe( filter((settings): settings is NonNullable<typeof settings> => !!settings),
filter((settings): settings is NonNullable<typeof settings> => !!settings), map(_ => _.currentShow),
map(_ => _.currentShow), filter((showId): showId is string => !!showId),
filter((showId): showId is string => !!showId), distinctUntilChanged(),
distinctUntilChanged(), takeUntil(this.destroy$)
takeUntil(this.destroy$) );
);
const show$ = currentShowId$.pipe( const show$ = currentShowId$.pipe(
switchMap(showId => this.showService.read$(showId)), switchMap(showId => this.showService.read$(showId)),

View File

@@ -5,8 +5,8 @@ import {ReactiveFormsModule, UntypedFormBuilder, UntypedFormGroup} from '@angula
import {FilterValues} from './filter-values'; import {FilterValues} from './filter-values';
import {Show} from '../../services/show'; import {Show} from '../../services/show';
import {ShowService} from '../../services/show.service'; import {ShowService} from '../../services/show.service';
import {distinctUntilChanged, map} from 'rxjs/operators'; import {distinctUntilChanged, map, switchMap} from 'rxjs/operators';
import {combineLatest, Observable} from 'rxjs'; import {combineLatest, Observable, of} from 'rxjs';
import {dynamicSort, onlyUnique} from '../../../../services/filter.helper'; import {dynamicSort, onlyUnique} from '../../../../services/filter.helper';
import {UserService} from '../../../../services/user/user.service'; import {UserService} from '../../../../services/user/user.service';
import {isEqual} from 'lodash'; import {isEqual} from 'lodash';
@@ -66,21 +66,31 @@ export class FilterComponent {
} }
public owners$ = (): Observable<{key: string; value: string}[]> => { public owners$ = (): Observable<{key: string; value: string}[]> => {
return combineLatest([ return this.showService.list$().pipe(
this.showService.list$().pipe( map(shows =>
map(shows => { shows
return shows.map(show => show.owner).filter(onlyUnique); .map(show => show.owner)
}) .filter(onlyUnique)
.filter((ownerId): ownerId is string => !!ownerId)
), ),
this.userService.users$, switchMap(ownerIds => {
]).pipe( if (ownerIds.length === 0) {
map(([owners, users]) => { return of([] as {key: string; value: string}[]);
return owners }
.map(ownerId => ({
key: ownerId, return combineLatest(
value: users.find(user => user.id === ownerId)?.name, ownerIds.map(ownerId =>
})) this.userService.getUserbyId$(ownerId).pipe(
.sort(dynamicSort('value')); map(user => ({
key: ownerId,
value: user?.name,
}))
)
)
);
}),
map(owners => {
return owners.sort(dynamicSort('value'));
}), }),
distinctUntilChanged(isEqual), distinctUntilChanged(isEqual),
map(_ => _ as {key: string; value: string}[]) map(_ => _ as {key: string; value: string}[])

View File

@@ -35,10 +35,13 @@ export class NewComponent implements OnInit, OnDestroy {
this.form.reset(); this.form.reset();
this.subs.push( this.subs.push(
this.songService.list$().pipe(take(1)).subscribe(songs => { this.songService
const freeSongnumber = this.getFreeSongNumber(songs); .list$()
this.form.controls.number.setValue(freeSongnumber); .pipe(take(1))
}) .subscribe(songs => {
const freeSongnumber = this.getFreeSongNumber(songs);
this.form.controls.number.setValue(freeSongnumber);
})
); );
} }

View File

@@ -10,6 +10,7 @@
width: 800px; width: 800px;
position: relative; position: relative;
color: var(--text); color: var(--text);
padding-bottom: 5px;
@media screen and (max-width: 860px) { @media screen and (max-width: 860px) {
width: 100vw; width: 100vw;