Skip to content

Commit

Permalink
refactor(videodetail): fix episode urls
Browse files Browse the repository at this point in the history
  • Loading branch information
royschut committed Jun 17, 2021
1 parent cd5fe77 commit 453cfb4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/screens/Series/Series.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import CardGrid from '../../components/CardGrid/CardGrid';
import { useFavorites } from '../../stores/FavoritesStore';
import { ConfigContext } from '../../providers/ConfigProvider';
import useBlurImageUpdater from '../../hooks/useBlurImageUpdater';
import { cardUrl, episodeURL, videoUrl } from '../../utils/formatting';
import { episodeURL } from '../../utils/formatting';
import type { PlaylistItem } from '../../../types/playlist';
import VideoComponent from '../../components/Video/Video';
import PlaylistContainer from '../../containers/Playlist/PlaylistContainer';
Expand Down Expand Up @@ -51,10 +51,10 @@ const Series = ({

const isFavorited = !!item && hasItem(item);

const startPlay = () => item && history.push(videoUrl(item, searchParams.get('r'), true));
const goBack = () => item && history.push(videoUrl(item, searchParams.get('r'), false));
const startPlay = () => item && seriesPlaylist && history.push(episodeURL(seriesPlaylist, item.mediaid, true));
const goBack = () => item && seriesPlaylist && history.push(episodeURL(seriesPlaylist, item.mediaid, false));

const onCardClick = (item: PlaylistItem) => history.push(cardUrl(item));
const onCardClick = (item: PlaylistItem) => seriesPlaylist && history.push(episodeURL(seriesPlaylist, item.mediaid));

const onShareClick = (): void => {
if (!item) return;
Expand Down
6 changes: 4 additions & 2 deletions src/utils/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ const movieURL = (item: PlaylistItem, playlistId?: string | null) =>
const seriesURL = (item: PlaylistItem, playlistId?: string | null) =>
`/s/${item.seriesId}/${slugify(item.title)}?r=${playlistId}`;

const episodeURL = (seriesPlaylist: Playlist, episodeId?: string) =>
`/s/${seriesPlaylist.feedid}/${slugify(seriesPlaylist.title)}${episodeId ? `?e=${episodeId}` : ''}`;
const episodeURL = (seriesPlaylist: Playlist, episodeId?: string, play: boolean = false) =>
`/s/${seriesPlaylist.feedid}/${slugify(seriesPlaylist.title)}${episodeId ? `?e=${episodeId}` : ''}${
play ? '&play=1' : ''
}`;

const cardUrl = (item: PlaylistItem, playlistId?: string | null) =>
item.seriesId ? seriesURL(item, playlistId) : movieURL(item, playlistId);
Expand Down

0 comments on commit 453cfb4

Please sign in to comment.