Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for a hub page in the header navigation #579

Open
ChristiaanScheermeijer opened this issue Jul 16, 2024 · 0 comments
Open

Add support for a hub page in the header navigation #579

ChristiaanScheermeijer opened this issue Jul 16, 2024 · 0 comments

Comments

@ChristiaanScheermeijer
Copy link
Collaborator

We have added a playlist with a single item in the menu items that contain a media item with contentType hub. I have tested a custom playlist screen that redirects to the hub page when the playlist contains a single hub item.

utils/hub.ts

export const getHubMediaFromPlaylist = (playlist: Playlist) => {
  return playlist.playlist.length === 1 && isContentType(playlist.playlist[0], MEDIA_CONTENT_TYPE.hub) ? playlist.playlist[0] : null;
};

export const isHubOnlyPlaylist = (playlist: Playlist | undefined) => {
  return !!(playlist && getHubMediaFromPlaylist(playlist));
};

PlaylistHubRedirect.tsx

const PlaylistHubRedirect: ScreenComponent<Playlist> = ({ data, isLoading }) => {
  const media = getHubMediaFromPlaylist(data);

  if (data && !isLoading && media) {
    return <Navigate to={mediaURL({ media })} replace={true}></Navigate>;
  }

  if (!media) {
    return <PlaylistGrid data={data} isLoading={isLoading} />;
  }

  return <Loading />;
};

screenMapping.ts

export default function registerCustomScreens() {
  // Hub is an example screen for the media router
  mediaScreenMap.registerByContentType(MediaHub, MEDIA_CONTENT_TYPE.hub);
  playlistScreenMap.register(PlaylistHubRedirect, isHubOnlyPlaylist);
  // ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant