optimize remote #3
This commit is contained in:
@@ -83,8 +83,7 @@ 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),
|
||||||
|
|||||||
@@ -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 => ({
|
|
||||||
|
return combineLatest(
|
||||||
|
ownerIds.map(ownerId =>
|
||||||
|
this.userService.getUserbyId$(ownerId).pipe(
|
||||||
|
map(user => ({
|
||||||
key: ownerId,
|
key: ownerId,
|
||||||
value: users.find(user => user.id === ownerId)?.name,
|
value: user?.name,
|
||||||
}))
|
}))
|
||||||
.sort(dynamicSort('value'));
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
map(owners => {
|
||||||
|
return owners.sort(dynamicSort('value'));
|
||||||
}),
|
}),
|
||||||
distinctUntilChanged(isEqual),
|
distinctUntilChanged(isEqual),
|
||||||
map(_ => _ as {key: string; value: string}[])
|
map(_ => _ as {key: string; value: string}[])
|
||||||
|
|||||||
@@ -35,7 +35,10 @@ 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
|
||||||
|
.list$()
|
||||||
|
.pipe(take(1))
|
||||||
|
.subscribe(songs => {
|
||||||
const freeSongnumber = this.getFreeSongNumber(songs);
|
const freeSongnumber = this.getFreeSongNumber(songs);
|
||||||
this.form.controls.number.setValue(freeSongnumber);
|
this.form.controls.number.setValue(freeSongnumber);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user