songlist click causes routing

This commit is contained in:
2019-11-24 16:18:57 +01:00
committed by smuddy
parent d3f8cca4b1
commit 0bfee780e8
7 changed files with 19 additions and 9 deletions

View File

@@ -1,4 +1,5 @@
export interface Song { export interface Song {
id: string;
comment: string; comment: string;
final: boolean; final: boolean;
key: string; key: string;

View File

@@ -2,17 +2,23 @@ import {Injectable} from '@angular/core';
import {AngularFirestore, AngularFirestoreCollection} from '@angular/fire/firestore'; import {AngularFirestore, AngularFirestoreCollection} from '@angular/fire/firestore';
import {Song} from '../models/song'; import {Song} from '../models/song';
import {Observable} from 'rxjs'; import {Observable} from 'rxjs';
import {map} from 'rxjs/operators';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class SongDataService { export class SongDataService {
private songCollection: AngularFirestoreCollection<Song>; private songCollection: AngularFirestoreCollection<Song>;
private songs: Observable<Song[]>; private readonly songs: Observable<Song[]>;
constructor(private afs: AngularFirestore) { constructor(private afs: AngularFirestore) {
this.songCollection = afs.collection<Song>('songs'); this.songCollection = afs.collection<Song>('songs');
this.songs = this.songCollection.valueChanges(); this.songs = this.songCollection.snapshotChanges().pipe(map(actions => {
return actions.map(a => ({
...a.payload.doc.data(),
id: a.payload.doc.id
}));
}));
} }
public list = (): Observable<Song[]> => this.songs; public list = (): Observable<Song[]> => this.songs;

View File

@@ -1,3 +1,3 @@
<app-card [padding]="false"> <app-card [padding]="false">
<app-list-item *ngFor="let song of songs" [song]="song"></app-list-item> <app-list-item *ngFor="let song of songs | async" [song]="song" [routerLink]="song.id"></app-list-item>
</app-card> </app-card>

View File

@@ -1,6 +1,8 @@
import {Component, OnInit} from '@angular/core'; import {Component, OnInit} from '@angular/core';
import {SongService} from '../services/song.service'; import {SongService} from '../services/song.service';
import {Song} from '../models/song'; import {Song} from '../models/song';
import {map} from 'rxjs/operators';
import {Observable} from 'rxjs';
@Component({ @Component({
selector: 'app-songs', selector: 'app-songs',
@@ -8,15 +10,15 @@ import {Song} from '../models/song';
styleUrls: ['./song-list.component.less'] styleUrls: ['./song-list.component.less']
}) })
export class SongListComponent implements OnInit { export class SongListComponent implements OnInit {
public songs: Song[]; public songs: Observable<Song[]>;
constructor(private songService: SongService) { constructor(private songService: SongService) {
} }
ngOnInit() { ngOnInit() {
this.songService.list().subscribe(songs => { this.songs = this.songService.list().pipe(map(songs =>
this.songs = songs.sort((a, b) => a.number - b.number); songs.sort((a, b) => a.number - b.number)
}); ));
} }
} }

View File

@@ -4,6 +4,7 @@ import {SongListComponent} from './song-list.component';
import {ListItemComponent} from './list-item/list-item.component'; import {ListItemComponent} from './list-item/list-item.component';
import {CardModule} from '../../widget-modules/components/card/card.module'; import {CardModule} from '../../widget-modules/components/card/card.module';
import {SongTypeTranslaterModule} from '../../widget-modules/pipes/song-type-translater/song-type-translater.module'; import {SongTypeTranslaterModule} from '../../widget-modules/pipes/song-type-translater/song-type-translater.module';
import {RouterModule} from '@angular/router';
@NgModule({ @NgModule({
@@ -11,6 +12,7 @@ import {SongTypeTranslaterModule} from '../../widget-modules/pipes/song-type-tra
exports: [SongListComponent], exports: [SongListComponent],
imports: [ imports: [
CommonModule, CommonModule,
RouterModule,
CardModule, CardModule,
SongTypeTranslaterModule SongTypeTranslaterModule

View File

@@ -5,14 +5,12 @@ import {SongsRoutingModule} from './songs-routing.module';
import {SongComponent} from './song/song.component'; import {SongComponent} from './song/song.component';
import {SongListModule} from './song-list/song-list.module'; import {SongListModule} from './song-list/song-list.module';
@NgModule({ @NgModule({
declarations: [SongComponent], declarations: [SongComponent],
imports: [ imports: [
CommonModule, CommonModule,
SongsRoutingModule, SongsRoutingModule,
SongListModule, SongListModule,
] ]
}) })
export class SongsModule { export class SongsModule {

View File

@@ -5,6 +5,7 @@
margin: 20px; margin: 20px;
border-radius: 8px; border-radius: 8px;
background: #fffe; background: #fffe;
overflow: hidden;
&.padding { &.padding {
padding: 20px; padding: 20px;