From 5135395f473f311710533dd20ca57bc0b19f21c0 Mon Sep 17 00:00:00 2001 From: Guillaume Clochard Date: Mon, 4 Apr 2022 19:21:44 +0200 Subject: [PATCH] fixup! add saveVolume method --- domain/player/src/index.ts | 2 ++ domain/player/src/repositories/playPause.ts | 6 ++++-- domain/player/src/repositories/track.ts | 24 ++++++++++----------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/domain/player/src/index.ts b/domain/player/src/index.ts index cca1afe62..3877ec715 100644 --- a/domain/player/src/index.ts +++ b/domain/player/src/index.ts @@ -13,6 +13,7 @@ import { loadSoundcloud, } from "./repositories/track"; import { saveAutoplayChoice } from "./repositories/autoplay"; +import { updateVolume } from "./repositories/volume"; export { Track, @@ -29,4 +30,5 @@ export { loadBandcamp, loadSoundcloud, saveAutoplayChoice, + updateVolume, }; diff --git a/domain/player/src/repositories/playPause.ts b/domain/player/src/repositories/playPause.ts index 472d7cae1..e1d9419c0 100644 --- a/domain/player/src/repositories/playPause.ts +++ b/domain/player/src/repositories/playPause.ts @@ -7,12 +7,14 @@ import * as Tracks from "../entities/Tracks"; import * as Store from "../store"; import * as TrackRepo from "./track"; +import { setVolumeForCurrentTrack } from "./volume"; function selectAndPlayTrack(track: Track.Initialized) { return (state: Tracks.Loaded): IO.IO => { return pipe( Store.write(() => pipe(state, Tracks.selectTrack(track), Tracks.playing)), - IO.chain(() => TrackRepo.play(track)) + IO.chain(() => TrackRepo.play(track)), + IO.chain(setVolumeForCurrentTrack) ); }; } @@ -25,7 +27,7 @@ export const playOrPause = pipe( return IO.of(undefined); } - const selectedTrack = pipe(state, Tracks.selectedTrack); + const selectedTrack = Tracks.selectedTrack(state); // nothing to do here if (!Track.isInteractive(selectedTrack)) { diff --git a/domain/player/src/repositories/track.ts b/domain/player/src/repositories/track.ts index 7827ca763..ea8f8d46f 100644 --- a/domain/player/src/repositories/track.ts +++ b/domain/player/src/repositories/track.ts @@ -161,19 +161,17 @@ export function pause(track: Track.Initialized): IO.IO { ); } -export function setVolume( - track: Track.Initialized, - volume: number -): IO.IO { - return pipe( - track, - Track.source, - Source.fold({ - Youtube: setVolumeYoutube(volume), - Soundcloud: setVolumeSoundcloud(volume), - Bandcamp: setVolumeBandcamp(volume), - }) - ); +export function setVolume(volume: number) { + return (track: Track.Initialized): IO.IO => + pipe( + track, + Track.source, + Source.fold({ + Youtube: setVolumeYoutube(volume), + Soundcloud: setVolumeSoundcloud(volume), + Bandcamp: setVolumeBandcamp(volume), + }) + ); } const aborted = doIfSelectedTrack((track: Track.Initialized) =>