Skip to content

Commit

Permalink
fixup! add saveVolume method
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumewuip committed Apr 4, 2022
1 parent ee2d517 commit 6dfce74
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions domain/player/src/repositories/volume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,39 @@ import { pipe } from "fp-ts/function";

import * as Volume from "../entities/Volume";
import * as Tracks from "../entities/Tracks";
import * as Track from "../entities/Track";

import * as Store from "../store";
import { volume } from "../localStorage";

export function saveVolume(newVolume: Volume.Volume): IO.IO<void> {
import * as TrackRepo from "./track";

export function setVolumeForCurrentTrack(): IO.IO<void> {
return () => {
const state = Store.read();

// nothing to do here
if (Tracks.isEmpty(state)) {
return IO.of(undefined);
}

const selectedTrack = Tracks.selectedTrack(state);

// nothing to do here
if (!Track.isInteractive(selectedTrack)) {
return IO.of(undefined);
}

const value = pipe(state, Tracks.volume, Volume.value);

return TrackRepo.setVolume(value)(selectedTrack);
};
}

export function updateVolume(newVolume: Volume.Volume): IO.IO<void> {
return pipe(
volume.silentWrite(Volume.value(newVolume)),
IO.chainFirst(() => Store.write(Tracks.setVolume(newVolume)))
IO.chainFirst(() => Store.write(Tracks.setVolume(newVolume))),
IO.chain(setVolumeForCurrentTrack)
);
}

0 comments on commit 6dfce74

Please sign in to comment.