import React, { useState } from "react"; import { Button, ButtonGroup, Card, Form } from "react-bootstrap"; import { Link } from "react-router-dom"; import cx from "classnames"; import * as GQL from "src/core/generated-graphql"; import { StashService } from "src/core/StashService"; import { VideoHoverHook } from "src/hooks"; import { Icon, TagLink, HoverPopover } from "src/components/Shared"; import { TextUtils } from "src/utils"; interface ISceneCardProps { scene: GQL.SlimSceneDataFragment; selected: boolean | undefined; zoomIndex: number; onSelectedChanged: (selected: boolean, shiftKey: boolean) => void; } export const SceneCard: React.FC = ( props: ISceneCardProps ) => { const [previewPath, setPreviewPath] = useState(); const videoHoverHook = VideoHoverHook.useVideoHover({ resetOnMouseLeave: false }); const config = StashService.useConfiguration(); const showStudioAsText = config?.data?.configuration.interface.showStudioAsText ?? false; function maybeRenderRatingBanner() { if (!props.scene.rating) { return; } return (
RATING: {props.scene.rating}
); } function maybeRenderSceneSpecsOverlay() { return (
{props.scene.file.height ? ( {" "} {TextUtils.resolution(props.scene.file.height)} ) : ( "" )} {(props.scene.file.duration ?? 0) >= 1 ? TextUtils.secondsToTimestamp(props.scene.file.duration ?? 0) : ""}
); } function maybeRenderSceneStudioOverlay() { if (!props.scene.studio) return; let style: React.CSSProperties = { backgroundImage: `url('${props.scene.studio.image_path}')` }; let text = ""; if (showStudioAsText) { style = {}; text = props.scene.studio.name; } return (
{text}
); } function maybeRenderTagPopoverButton() { if (props.scene.tags.length <= 0) return; const popoverContent = props.scene.tags.map(tag => ( )); return ( ); } function maybeRenderPerformerPopoverButton() { if (props.scene.performers.length <= 0) return; const popoverContent = props.scene.performers.map(performer => (
)); return ( ); } function maybeRenderSceneMarkerPopoverButton() { if (props.scene.scene_markers.length <= 0) return; const popoverContent = props.scene.scene_markers.map(marker => { const markerPopover = { ...marker, scene: { id: props.scene.id } }; return ; }); return ( ); } function maybeRenderPopoverButtonGroup() { if ( props.scene.tags.length > 0 || props.scene.performers.length > 0 || props.scene.scene_markers.length > 0 ) { return ( <>
{maybeRenderTagPopoverButton()} {maybeRenderPerformerPopoverButton()} {maybeRenderSceneMarkerPopoverButton()} ); } } function onMouseEnter() { if (!previewPath || previewPath === "") { setPreviewPath(props.scene.paths.preview || ""); } VideoHoverHook.onMouseEnter(videoHoverHook); } function onMouseLeave() { VideoHoverHook.onMouseLeave(videoHoverHook); setPreviewPath(""); } function isPortrait() { const { file } = props.scene; const width = file.width ? file.width : 0; const height = file.height ? file.height : 0; return height > width; } let shiftKey = false; return ( props.onSelectedChanged(!props.selected, shiftKey)} onClick={(event: React.MouseEvent) => { // eslint-disable-next-line prefer-destructuring shiftKey = event.shiftKey; event.stopPropagation(); }} /> {maybeRenderSceneStudioOverlay()}
{maybeRenderRatingBanner()} {maybeRenderSceneSpecsOverlay()}
{props.scene.title ? props.scene.title : TextUtils.fileNameFromPath(props.scene.path)}
{props.scene.date}

{TextUtils.truncate( props.scene.details ?? "", 100, "... (continued)" )}

{maybeRenderPopoverButtonGroup()}
); };