Gallery card patched component (#5880)

* Gallery card patched component
* Define in pluginApi.d.ts
This commit is contained in:
QxxxGit
2025-06-02 03:20:34 -04:00
committed by GitHub
parent 8e697b50eb
commit 044ed2708f
3 changed files with 174 additions and 132 deletions

View File

@@ -16,6 +16,7 @@ import { StudioOverlay } from "../Shared/GridCard/StudioOverlay";
import { GalleryPreviewScrubber } from "./GalleryPreviewScrubber"; import { GalleryPreviewScrubber } from "./GalleryPreviewScrubber";
import cx from "classnames"; import cx from "classnames";
import { useHistory } from "react-router-dom"; import { useHistory } from "react-router-dom";
import { PatchComponent } from "src/patch";
interface IGalleryPreviewProps { interface IGalleryPreviewProps {
gallery: GQL.SlimGalleryDataFragment; gallery: GQL.SlimGalleryDataFragment;
@@ -53,7 +54,7 @@ export const GalleryPreview: React.FC<IGalleryPreviewProps> = ({
); );
}; };
interface IProps { interface IGalleryCardProps {
gallery: GQL.SlimGalleryDataFragment; gallery: GQL.SlimGalleryDataFragment;
cardWidth?: number; cardWidth?: number;
selecting?: boolean; selecting?: boolean;
@@ -62,9 +63,9 @@ interface IProps {
onSelectedChanged?: (selected: boolean, shiftKey: boolean) => void; onSelectedChanged?: (selected: boolean, shiftKey: boolean) => void;
} }
export const GalleryCard: React.FC<IProps> = (props) => { const GalleryCardPopovers = PatchComponent(
const history = useHistory(); "GalleryCard.Popovers",
(props: IGalleryCardProps) => {
function maybeRenderScenePopoverButton() { function maybeRenderScenePopoverButton() {
if (props.gallery.scenes.length === 0) return; if (props.gallery.scenes.length === 0) return;
@@ -171,14 +172,39 @@ export const GalleryCard: React.FC<IProps> = (props) => {
} }
} }
return <>{maybeRenderPopoverButtonGroup()}</>;
}
);
const GalleryCardDetails = PatchComponent(
"GalleryCard.Details",
(props: IGalleryCardProps) => {
return (
<div className="gallery-card__details">
<span className="gallery-card__date">{props.gallery.date}</span>
<TruncatedText
className="gallery-card__description"
text={props.gallery.details}
lineCount={3}
/>
</div>
);
}
);
const GalleryCardOverlays = PatchComponent(
"GalleryCard.Overlays",
(props: IGalleryCardProps) => {
return <StudioOverlay studio={props.gallery.studio} />;
}
);
const GalleryCardImage = PatchComponent(
"GalleryCard.Image",
(props: IGalleryCardProps) => {
const history = useHistory();
return ( return (
<GridCard
className={`gallery-card zoom-${props.zoomIndex}`}
url={`/galleries/${props.gallery.id}`}
width={props.cardWidth}
title={galleryTitle(props.gallery)}
linkClassName="gallery-card-header"
image={
<> <>
<GalleryPreview <GalleryPreview
gallery={props.gallery} gallery={props.gallery}
@@ -188,22 +214,28 @@ export const GalleryCard: React.FC<IProps> = (props) => {
/> />
<RatingBanner rating={props.gallery.rating100} /> <RatingBanner rating={props.gallery.rating100} />
</> </>
);
} }
overlays={<StudioOverlay studio={props.gallery.studio} />} );
details={
<div className="gallery-card__details"> export const GalleryCard = PatchComponent(
<span className="gallery-card__date">{props.gallery.date}</span> "GalleryCard",
<TruncatedText (props: IGalleryCardProps) => {
className="gallery-card__description" return (
text={props.gallery.details} <GridCard
lineCount={3} className={`gallery-card zoom-${props.zoomIndex}`}
/> url={`/galleries/${props.gallery.id}`}
</div> width={props.cardWidth}
} title={galleryTitle(props.gallery)}
popovers={maybeRenderPopoverButtonGroup()} linkClassName="gallery-card-header"
image={<GalleryCardImage {...props} />}
overlays={<GalleryCardOverlays {...props} />}
details={<GalleryCardDetails {...props} />}
popovers={<GalleryCardPopovers {...props} />}
selected={props.selected} selected={props.selected}
selecting={props.selecting} selecting={props.selecting}
onSelectedChanged={props.onSelectedChanged} onSelectedChanged={props.onSelectedChanged}
/> />
); );
}; }
);

View File

@@ -154,6 +154,11 @@ Returns `void`.
- `ExternalLinksButton` - `ExternalLinksButton`
- `FolderSelect` - `FolderSelect`
- `FrontPage` - `FrontPage`
- `GalleryCard`
- `GalleryCard.Details`
- `GalleryCard.Image`
- `GalleryCard.Overlays`
- `GalleryCard.Popovers`
- `GalleryIDSelect` - `GalleryIDSelect`
- `GallerySelect` - `GallerySelect`
- `GallerySelect.sort` - `GallerySelect.sort`

View File

@@ -715,6 +715,11 @@ declare namespace PluginApi {
"ScenePage.TabContent": React.FC<any>; "ScenePage.TabContent": React.FC<any>;
ScenePlayer: React.FC<any>; ScenePlayer: React.FC<any>;
FrontPage: React.FC<any>; FrontPage: React.FC<any>;
GalleryCard: React.FC<any>;
"GalleryCard.Details": React.FC<any>;
"GalleryCard.Image": React.FC<any>;
"GalleryCard.Overlays": React.FC<any>;
"GalleryCard.Popovers": React.FC<any>;
}; };
type PatchableComponentNames = keyof typeof components | string; type PatchableComponentNames = keyof typeof components | string;
namespace utils { namespace utils {