Skip to content

Commit

Permalink
Original Language Mapping for Series Page Titles (#1009)
Browse files Browse the repository at this point in the history
* Original Language Mapping for Series Page Titles

- hide the main title or the original title if it equals the preferred title
- fix copy paste error in series info

* Formatting

* Switch to useMemo

* Reformat title check

---------

Co-authored-by: Harshith Mohan <[email protected]>
  • Loading branch information
natyusha and harshithmohan authored Aug 23, 2024
1 parent a43cb9b commit c5354c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/components/Collection/SeriesInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const SeriesInfo = ({ series }: SeriesInfoProps) => {
<span className="mx-1">|</span>
{series?.Sizes.Total.Specials}
&nbsp;
{series?.Sizes.Total.Episodes > 1
{series?.Sizes.Total.Specials > 1
? 'Specials'
: 'Special'}
</div>
Expand Down
23 changes: 16 additions & 7 deletions src/pages/collection/Series.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const SeriesTab: SeriesTabProps = ({ icon, text, to }) => (

const getImagePath = ({ ID, Source, Type }: ImageType) => `/api/v3/Image/${Source}/${Type}/${ID}`;

const languageMapping = { 'x-jat': 'ja', 'x-kot': 'ko', 'x-zht': 'zh-hans' };

const Series = () => {
const navigate = useNavigate();
const { seriesId } = useParams();
Expand All @@ -63,6 +65,17 @@ const Series = () => {

const dispatch = useDispatch();

const [mainTitle, originalTitle] = useMemo(() => {
const tempMainTitle = series.AniDB?.Titles.find(title => title.Type === 'Main');
const tempOriginalTitle = series.AniDB?.Titles.find(
title => title.Language === languageMapping[tempMainTitle?.Language ?? ''],
);
return [
(tempMainTitle && tempMainTitle.Name !== series.Name) ? <span>{tempMainTitle.Name}</span> : null,
(tempOriginalTitle && tempOriginalTitle.Name !== series.Name) ? <span>{tempOriginalTitle.Name}</span> : null,
];
}, [series]);

const onClickHandler = useEventCallback(() => {
dispatch(setSeriesId(toNumber(seriesId) ?? -1));
});
Expand Down Expand Up @@ -118,13 +131,9 @@ const Series = () => {
</div>
<div className="text-4xl font-semibold">{series.Name}</div>
<div className="flex gap-x-3 text-xl font-semibold opacity-65">
<span>
{series.AniDB?.Titles.find(title => title.Type === 'Main')?.Name}
</span>
<span>|</span>
<span>
{series.AniDB?.Titles.find(title => title.Language === 'ja')?.Name}
</span>
{mainTitle}
{mainTitle && originalTitle && <span>|</span>}
{originalTitle}
</div>
</div>
<SeriesTopPanel series={series} />
Expand Down

0 comments on commit c5354c2

Please sign in to comment.