Skip to content

Commit

Permalink
Merge pull request #1163 from dipamsen/form-group-videos
Browse files Browse the repository at this point in the history
[Showcase Form] Group track videos into chapters
  • Loading branch information
shiffman authored Jul 25, 2023
2 parents d7025c5 + 1210b6a commit 2ef11b9
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions src/components/PassengerShowcaseForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,23 @@ const useVideosWithShowcase = function () {

return useMemo(() => {
const tracks = data.tracks.nodes
.map((track) => {
// gather all videos from chapters (main track)
if (!track.videos && track.chapters) {
track.videos = track.chapters.flatMap((chapter) => chapter.videos);
}
delete track.chapters;
return track;
})
.map((track) => {
// keep only videos that can be contributed to
// keep only videos that belong to this track
track.videos = track.videos.filter(
(video) =>
video.canContribute && video.canonicalTrack?.slug === track.slug
);
const videoFilter = (video) =>
video.canContribute && video.canonicalTrack?.slug === track.slug;

track.videos = track.videos?.filter(videoFilter);
track.chapters = track.chapters
?.map((chapter) => {
chapter.videos = chapter.videos.filter(videoFilter);
return chapter;
})
.filter((chapter) => chapter.videos.length);

return track;
})
.filter((track) => track.videos.length > 0);
.filter((track) => track.videos?.length || track.chapters?.length);

// create a "challenges track"
const challengesTrack = {
Expand Down Expand Up @@ -211,6 +209,8 @@ const PassengerShowcaseForm = () => {
};
};

const selectedTrack = data.find((track) => track.slug === state.track);

return (
<div className={css.root}>
<form onSubmit={onSubmit} className={css.form}>
Expand Down Expand Up @@ -238,9 +238,24 @@ const PassengerShowcaseForm = () => {
Video
<select name="video" value={state.video} onChange={onChange}>
<option value="">Select a video</option>
{(
data.find((track) => track.slug === state.track)?.videos || []
).map((node) => {

{selectedTrack?.chapters?.map((node) => (
<optgroup label={node.title}>
{node.videos.map((video) => {
let label = video.title;
if (label.length > 50) {
label = label.substring(0, 50) + '...';
}
return (
<option value={video.slug} key={video.slug}>
{label}
</option>
);
})}
</optgroup>
))}

{selectedTrack?.videos?.map((node) => {
let label = node.title;
if (label.length > 50) {
label = label.substring(0, 50) + '...';
Expand Down

0 comments on commit 2ef11b9

Please sign in to comment.