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 6dfce74 commit 5135395
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
2 changes: 2 additions & 0 deletions domain/player/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
loadSoundcloud,
} from "./repositories/track";
import { saveAutoplayChoice } from "./repositories/autoplay";
import { updateVolume } from "./repositories/volume";

export {
Track,
Expand All @@ -29,4 +30,5 @@ export {
loadBandcamp,
loadSoundcloud,
saveAutoplayChoice,
updateVolume,
};
6 changes: 4 additions & 2 deletions domain/player/src/repositories/playPause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
return pipe(
Store.write(() => pipe(state, Tracks.selectTrack(track), Tracks.playing)),
IO.chain(() => TrackRepo.play(track))
IO.chain(() => TrackRepo.play(track)),
IO.chain(setVolumeForCurrentTrack)
);
};
}
Expand All @@ -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)) {
Expand Down
24 changes: 11 additions & 13 deletions domain/player/src/repositories/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,17 @@ export function pause(track: Track.Initialized): IO.IO<void> {
);
}

export function setVolume(
track: Track.Initialized,
volume: number
): IO.IO<void> {
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<void> =>
pipe(
track,
Track.source,
Source.fold({
Youtube: setVolumeYoutube(volume),
Soundcloud: setVolumeSoundcloud(volume),
Bandcamp: setVolumeBandcamp(volume),
})
);
}

const aborted = doIfSelectedTrack((track: Track.Initialized) =>
Expand Down

0 comments on commit 5135395

Please sign in to comment.