Skip to content

Commit

Permalink
feat(series): modify i18n keys for seasons
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLantukh committed Jun 13, 2023
1 parent 32eec64 commit bcbfa1c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion public/locales/en/video.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"live": "Live",
"remove_from_favorites": "Remove from favorites",
"season": "season",
"season_prefix": "Season ",
"season_number_filter_template": "Season {{seasonNumber}}",
"series_error": "An error occurred while requesting series",
"share": "Share",
"share_video": "Share this video",
Expand Down
2 changes: 1 addition & 1 deletion public/locales/es/video.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"live": "EN VIVO",
"remove_from_favorites": "Eliminar de favoritos",
"season": "temporada",
"season_prefix": "Temporada ",
"season_number_filter_template": "Temporada {{seasonNumber}}",
"series_error": "Se produjo un error al solicitar la serie",
"share": "Compartir",
"share_video": "Compartir este video",
Expand Down
4 changes: 2 additions & 2 deletions src/pages/LegacySeries/LegacySeries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const LegacySeries = () => {
const inlineLayout = Boolean(custom?.inlinePlayer);

// Filters
const filters = useMemo(() => getFiltersFromSeries(seriesPlaylist, t), [seriesPlaylist, t]);
const filters = useMemo(() => getFiltersFromSeries(seriesPlaylist), [seriesPlaylist]);
const [seasonFilter, setSeasonFilter] = useState<string | undefined>(undefined);

const firstEpisode = useMemo(() => seriesPlaylist?.playlist?.[0], [seriesPlaylist]);
Expand Down Expand Up @@ -96,7 +96,7 @@ const LegacySeries = () => {
}

if (seasonFilter === undefined) {
setSeasonFilter(parseInt(episodeMetadata?.seasonNumber, 10) ? episodeMetadata?.seasonNumber : filters?.[0] || '');
setSeasonFilter(parseInt(episodeMetadata?.seasonNumber, 10) ? episodeMetadata?.seasonNumber : filters?.[0]?.value || '');
}
}, [episodeMetadata, seasonFilter, isSeriesPlaylistLoading, isEpisodeLoading, filters]);

Expand Down
20 changes: 11 additions & 9 deletions src/pages/LegacySeries/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { TFunction } from 'i18next';
import i18next from 'i18next';

import { legacySeriesURL } from '#src/utils/formatting';
import { secondsToISO8601 } from '#src/utils/datetime';
Expand All @@ -8,17 +8,19 @@ import type { EpisodeMetadata } from '#types/series';
/**
* Get an array of options for a season filter
*/
export const getFiltersFromSeries = (playlist: Playlist | undefined, t: TFunction): string[] => {
export const getFiltersFromSeries = (playlist: Playlist | undefined): { value: string; label: string }[] => {
// Old series doesn't have sorting supported and just aggregates all episodes in one playlist
// So we need to sort the playlist manually based on the selected filter (season).
return (playlist?.playlist || [])
.reduce(
(filters: string[], item) =>
item.seasonNumber && filters.includes(item.seasonNumber)
? filters
: filters.concat(item.seasonNumber ? `${t('season_prefix')} ${item.seasonNumber}` : ''),
[],
)
.reduce((filters, item) => {
if (filters.some((el) => el?.value === item?.seasonNumber)) {
return filters;
}

return filters.concat(
item.seasonNumber ? [{ label: i18next.t('video:season_number_filter_template', { seasonNumber: item.seasonNumber }), value: item.seasonNumber }] : [],
);
}, [] as { value: string; label: string }[])
.slice()
.sort();
};
Expand Down

0 comments on commit bcbfa1c

Please sign in to comment.