-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: Use SeriesPoster component for all series posters outside o…
…f main collection page
- Loading branch information
1 parent
8ac186e
commit f19fe52
Showing
10 changed files
with
316 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import React, { useMemo } from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
import cx from 'classnames'; | ||
|
||
import BackgroundImagePlaceholderDiv from '@/components/BackgroundImagePlaceholderDiv'; | ||
|
||
import type { ImageType } from '@/core/types/api/common'; | ||
|
||
type Props = { | ||
children?: React.ReactNode; | ||
title: string; | ||
subtitle?: string; | ||
image: ImageType | null; | ||
shokoId?: number | null; | ||
anidbSeriesId?: number; | ||
anidbEpisodeId?: number; | ||
inCollection?: boolean; | ||
}; | ||
|
||
const baseClassName = 'w-56 flex flex-col shrink-0'; | ||
|
||
const SeriesPoster = React.memo((props: Props) => { | ||
const { | ||
anidbEpisodeId, | ||
anidbSeriesId, | ||
children, | ||
image, | ||
inCollection, | ||
shokoId, | ||
subtitle, | ||
title, | ||
} = props; | ||
|
||
const isAnidb = useMemo(() => { | ||
if (shokoId) return false; | ||
return anidbSeriesId !== undefined || anidbEpisodeId !== undefined; | ||
}, [anidbEpisodeId, anidbSeriesId, shokoId]); | ||
|
||
const content = ( | ||
<> | ||
<BackgroundImagePlaceholderDiv | ||
image={image} | ||
className="h-80 rounded-lg border border-panel-border drop-shadow-md" | ||
hidePlaceholderOnHover | ||
overlayOnHover | ||
zoomOnHover | ||
> | ||
{isAnidb && ( | ||
<div className="absolute inset-0 z-10 flex flex-col items-center justify-center gap-y-3 text-sm font-semibold opacity-0 transition-opacity group-hover:opacity-100"> | ||
<div className="metadata-link-icon AniDB" /> | ||
View on AniDB | ||
</div> | ||
)} | ||
|
||
{children} | ||
|
||
{inCollection && ( | ||
<div className="absolute bottom-4 left-3 flex w-[90%] justify-center rounded-lg bg-panel-background-overlay py-2 text-sm font-semibold text-panel-text opacity-100 transition-opacity group-hover:opacity-0"> | ||
In Collection | ||
</div> | ||
)} | ||
</BackgroundImagePlaceholderDiv> | ||
|
||
<div | ||
className="mt-3 truncate text-center text-sm font-semibold" | ||
data-tooltip-id="tooltip" | ||
data-tooltip-content={title} | ||
data-tooltip-delay-show={500} | ||
> | ||
{title} | ||
</div> | ||
|
||
{subtitle && ( | ||
<div | ||
className="truncate text-center text-sm font-semibold opacity-65" | ||
title={subtitle} | ||
> | ||
{subtitle} | ||
</div> | ||
)} | ||
</> | ||
); | ||
|
||
if (shokoId) { | ||
return ( | ||
<Link className={cx(baseClassName, 'group')} to={`/webui/collection/series/${shokoId}`}> | ||
{content} | ||
</Link> | ||
); | ||
} | ||
|
||
if (anidbSeriesId ?? anidbEpisodeId) { | ||
return ( | ||
<a | ||
href={`https://anidb.net/${anidbSeriesId ? `anime/${anidbSeriesId}` : `episode/${anidbEpisodeId}`}`} | ||
className={cx(baseClassName, 'group')} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
{content} | ||
</a> | ||
); | ||
} | ||
|
||
return <div className={baseClassName}>{content}</div>; | ||
}); | ||
|
||
export default SeriesPoster; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.