Mercurial > hg > ugly-duckling
diff src/app/notebook-feed/notebook-feed.component.ts @ 464:50f61d1945db
Hook up some buttons for navigating history (undo / redo). Some refactoring to allow for the audio player to get updated as a consequence of a state change (the audio related to the current top of the stack is used).
author | Lucas Thompson <dev@lucas.im> |
---|---|
date | Fri, 30 Jun 2017 14:01:22 +0100 |
parents | ccce2c09502e |
children | 3a76205e06b6 |
line wrap: on
line diff
--- a/src/app/notebook-feed/notebook-feed.component.ts Fri Jun 30 13:59:51 2017 +0100 +++ b/src/app/notebook-feed/notebook-feed.component.ts Fri Jun 30 14:01:22 2017 +0100 @@ -19,6 +19,7 @@ import {Dimension} from '../app.module'; import {Subscription} from 'rxjs/Subscription'; import {OnSeekHandler} from '../playhead/PlayHeadHelpers'; +import {AudioPlayerService} from '../services/audio-player/audio-player.service'; @Component({ selector: 'ugly-notebook-feed', @@ -27,25 +28,38 @@ changeDetection: ChangeDetectionStrategy.OnPush }) export class NotebookFeedComponent implements OnDestroy { - @Input() analyses: Item[]; - @Input() set rootAudioUri(uri: string) { - this._rootAudioUri = uri; + @Input() set analyses(analyses: Item[]) { + const front = analyses[0]; + if (analyses !== this.mAnalyses) { + if (front && getRootUri(front) !== this.currentAudioUri) { + this.audioService.unload(); + this.audioService.loadAudioFromUri(getRootUri(front)); + } + } + this.mAnalyses = analyses; + if (front) { + this.currentAudioUri = this.getCurrentAudioUri(); + } } + + get analyses(): Item[] { + return this.mAnalyses; + } + @Input() onSeek: OnSeekHandler; @Output() removeItem: EventEmitter<Item>; - get rootAudioUri(): string { - return this._rootAudioUri; - } - private _rootAudioUri: string; private resizeSubscription: Subscription; private width: number; private lastWidth: number; private timelines: Map<string, Timeline>; + private mAnalyses: Item[]; + private currentAudioUri: string; constructor( private ref: ChangeDetectorRef, - @Inject('DimensionObservable') private onResize: Observable<Dimension> + @Inject('DimensionObservable') private onResize: Observable<Dimension>, + private audioService: AudioPlayerService ) { this.removeItem = new EventEmitter<Item>(); this.timelines = new Map(); @@ -86,7 +100,7 @@ } isActiveItem(item: Item): boolean { - return this.rootAudioUri === getRootUri(item); + return this.getCurrentAudioUri() === getRootUri(item); } getOnSeekForItem(item: Item): (timeSeconds: number) => any { @@ -98,4 +112,15 @@ this.resizeSubscription.unsubscribe(); } } + + private getCurrentAudioUri(): string { + if (this.analyses.length === 0) { + return ''; + } + try { + return getRootUri(this.analyses[0]); + } catch (e) { + return ''; + } + } }