optimize song list load

This commit is contained in:
2023-01-21 20:46:51 +01:00
parent b47513209f
commit 66af7ea1e7
5 changed files with 36 additions and 2 deletions

12
.run/start.run.xml Normal file
View File

@@ -0,0 +1,12 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="start" type="js.build_tools.npm" nameIsGenerated="true">
<package-json value="$PROJECT_DIR$/package.json"/>
<command value="run"/>
<scripts>
<script value="start"/>
</scripts>
<node-interpreter value="project"/>
<envs/>
<method v="2"/>
</configuration>
</component>

View File

@@ -21,7 +21,7 @@ export class AppComponent implements OnInit {
public static hideLoader: () => void = () => document.querySelector('#load-bg')?.classList.add('hidden'); public static hideLoader: () => void = () => document.querySelector('#load-bg')?.classList.add('hidden');
public ngOnInit(): void { public ngOnInit(): void {
setTimeout(() => AppComponent.hideLoader(), 2000); setTimeout(() => AppComponent.hideLoader(), 1000);
} }
public onScoll($event: {srcElement: {scrollTop: number}}): void { public onScoll($event: {srcElement: {scrollTop: number}}): void {

View File

@@ -0,0 +1,17 @@
import {Injectable} from '@angular/core';
import {Resolve} from '@angular/router';
import {Observable} from 'rxjs';
import {SongService} from './song.service';
import {Song} from './song';
import {filter} from 'rxjs/operators';
@Injectable({
providedIn: 'root',
})
export class SongListResolver implements Resolve<Song[]> {
public constructor(private songService: SongService) {}
public resolve(): Observable<Song[]> {
return this.songService.list$().pipe(filter(_ => _.length > 0));
}
}

View File

@@ -20,7 +20,10 @@ import {faBalanceScaleRight, faCheck, faPencilRuler} from '@fortawesome/free-sol
export class SongListComponent implements OnInit, OnDestroy { export class SongListComponent implements OnInit, OnDestroy {
public songs$: Observable<Song[]> | null = combineLatest([ public songs$: Observable<Song[]> | null = combineLatest([
this.activatedRoute.queryParams.pipe(map(_ => _ as FilterValues)), this.activatedRoute.queryParams.pipe(map(_ => _ as FilterValues)),
this.songService.list$().pipe(map(songs => songs.sort((a, b) => a.number - b.number))), this.activatedRoute.data.pipe(
map(data => data.songList as Song[]),
map(songs => songs.sort((a, b) => a.number - b.number))
),
]).pipe( ]).pipe(
map(_ => { map(_ => {
const songs = _[1]; const songs = _[1];

View File

@@ -5,11 +5,13 @@ import {SongListComponent} from './song-list/song-list.component';
import {EditComponent} from './song/edit/edit.component'; import {EditComponent} from './song/edit/edit.component';
import {NewComponent} from './song/new/new.component'; import {NewComponent} from './song/new/new.component';
import {EditSongGuard} from './song/edit/edit-song.guard'; import {EditSongGuard} from './song/edit/edit-song.guard';
import {SongListResolver} from './services/song-list.resolver';
const routes: Routes = [ const routes: Routes = [
{ {
path: '', path: '',
component: SongListComponent, component: SongListComponent,
resolve: {songList: SongListResolver},
pathMatch: 'full', pathMatch: 'full',
}, },
{ {