Turbo Streams - Custom Stream Actions - Video Playlist Management

Managing a video playlist using custom Turbo Stream Actions.

View Solution on Patreon
Turbo Streams - Custom Stream Actions - Video Playlist Management

Premise

In Challenge 9 we already explored Turbo Streams custom stream actions, and today we want to expand this into orchestrating the management of a video playlist. For this I’ve taken some talks from RubyVideo as source material.

Challenge

The centerpiece of this challenge is a list (<ul id="playlist">) whose list elements contain YouTube video ids in their dataset (<li data-youtube-id="foobar">).

Your challenge is to use the given next/previous buttons to advance the playlist state, as well as toggle the indicators on the left. Here’s how that should look like:

Navigating Through a Video Playlist

There are three custom action templates ready for you in the DOM: https://stackblitz.com/edit/turbo-streams-custom-actions-2?file=app.js,index.html%3AL53

Implement their respective actions here:

And use the custom videochange and videochanged events to orchestrate the DOM changes: https://stackblitz.com/edit/turbo-streams-custom-actions-2?file=app.js%3AL43,index.html%3AL53

Caveats

It’s tempting to package everything up into one custom stream action, but it’s better to keep them decoupled. That way it’s already prepared for refactorings like 👇

Teaser

Imagine bringing Stimulus into this scenario. How would you change your solution?

More from

Hotwire Combobox with Real Time Data
12 March 2024

Update combobox options using Websockets and Stimulus outlets

Turbo Streams - Custom Stream Actions - LocalStorage
30 January 2024

Store ephemeral state changes locally using localStorage and custom Turbo Stream Actions.

Turbo Streams - Custom Stream Actions
15 August 2023

Use custom Turbo Stream actions to orchestrate complex UI animations.

Cookies
essential