Merge pull request #288 from UniversityRadioYork/mstratford/webstudio-played

Fix repeat all not triggering
This commit is contained in:
Matthew Stratford 2023-04-13 22:33:01 +01:00 committed by GitHub
commit 87ca8a8106
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -666,32 +666,23 @@ export const load = (
} }
if (state.repeat === "one") { if (state.repeat === "one") {
playerInstance.play(); playerInstance.play();
} else if (state.repeat === "all") { } else if (state.autoAdvance && "channel" in item) {
if ("channel" in item) { // it's not in the CML/libraries "column"
// it's not in the CML/libraries "column" const itsChannel = getState()
const itsChannel = getState() .showplan.plan!.filter((x) => x.channel === item.channel)
.showplan.plan!.filter((x) => x.channel === item.channel) .sort((x, y) => x.weight - y.weight);
.sort((x, y) => x.weight - y.weight); // Sadly, we can't just do .indexOf() item directly,
const itsIndex = itsChannel.indexOf(item); // since the player's idea of an item may be changed over it's lifecycle (setting played,intro/cue/outro etc.)
if (itsIndex === itsChannel.length - 1) { // Therefore we'll find the updated item from the plan and match that.
dispatch(load(player, itsChannel[0])); const itsIndex = itsChannel.findIndex(
} (x) => itemId(x) === itemId(item)
} );
} else if (state.autoAdvance) { if (itsIndex === itsChannel.length - 1 && state.repeat === "all") {
if ("channel" in item) { // Autoadvance and repeat all, we're on last item so jump to top!
// it's not in the CML/libraries "column" dispatch(load(player, itsChannel[0]));
const itsChannel = getState() } else if (itsIndex > -1 && itsIndex !== itsChannel.length - 1) {
.showplan.plan!.filter((x) => x.channel === item.channel) // We found the item and we're not the last item, load the next one!
.sort((x, y) => x.weight - y.weight); dispatch(load(player, itsChannel[itsIndex + 1]));
// Sadly, we can't just do .indexOf() item directly,
// since the player's idea of an item may be changed over it's lifecycle (setting played,intro/cue/outro etc.)
// Therefore we'll find the updated item from the plan and match that.
const itsIndex = itsChannel.findIndex(
(x) => itemId(x) === itemId(item)
);
if (itsIndex > -1 && itsIndex !== itsChannel.length - 1) {
dispatch(load(player, itsChannel[itsIndex + 1]));
}
} }
} }
}); });