Skip to content

Commit

Permalink
Fix episode wrong prefixes (#701)
Browse files Browse the repository at this point in the history
* Fix episode wrong prefixes
  • Loading branch information
duehoa1211 authored Nov 27, 2023
1 parent aeaf916 commit 3d6fa90
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/pages/dashboard/components/EpisodeDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,28 @@ const TitleSection: React.FC<{ episode: DashboardEpisodeDetailsType, title: stri
</>
);

const anidbEpisodePrefixes = (type: EpisodeTypeEnum, epNumber: number): string => {
const fullPrefixes = (prefix: string) => `${prefix}${epNumber}`;
// Prefixes for episode types base on https://wiki.anidb.net/Content:Episodes#Type
switch (type) {
case EpisodeTypeEnum.ThemeSong:
case EpisodeTypeEnum.OpeningSong:
case EpisodeTypeEnum.EndingSong:
return fullPrefixes('C');
case EpisodeTypeEnum.Special:
case EpisodeTypeEnum.Extra:
return fullPrefixes('S');
case EpisodeTypeEnum.Trailer:
return fullPrefixes('T');
case EpisodeTypeEnum.Other:
return fullPrefixes('O');
case EpisodeTypeEnum.Parody:
return fullPrefixes('P');
default:
return fullPrefixes('');
}
};

function EpisodeDetails({ episode, isInCollection = false, showDate = false }: Props): React.ReactNode {
const percentage = useMemo(() => {
if (episode.ResumePosition == null) return null;
Expand All @@ -69,7 +91,7 @@ function EpisodeDetails({ episode, isInCollection = false, showDate = false }: P
const airDate = useMemo(() => dayjs(episode.AirDate), [episode.AirDate]);
const relativeTime = useMemo(() => airDate.calendar(null, CalendarConfig), [airDate]);
const title = useMemo(
() => `${episode.Type === EpisodeTypeEnum.Normal ? '' : episode.Type[0]}${episode.Number} - ${episode.Title}`,
() => `${anidbEpisodePrefixes(episode.Type, episode.Number)} - ${episode.Title}`,
[episode.Type, episode.Title, episode.Number],
);

Expand Down

0 comments on commit 3d6fa90

Please sign in to comment.