Skip to content

Add useLightbox and useGalleryLightbox in plugin api #5936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2025

Conversation

QxxxGit
Copy link
Contributor

@QxxxGit QxxxGit commented Jun 17, 2025

Adds useLightbox and useGalleryLightbox hooks to the plugin api. Also added to docs.

Tested with my gallery card plugin.

@QxxxGit
Copy link
Contributor Author

QxxxGit commented Jun 17, 2025

Through further testing, I'm noticing a bug with my plugin and I'm not certain if it's related to this PR but I wanted to mention it just in case I've missed something.

When I navigate to the gallery from the card, then hit back, then try to use the gallery lightbox, I get a blank page with some errors in the console.

Starts with

TypeError: r is undefined
    to http://localhost:9996/assets/Lightbox-5bdc230c.js:1

then a couple errors of

Error: [React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry.

My plugin code:

import { components, libraries, React, hooks } from "../globals";
import IGalleryCardProps from "../types/IGalleryCardProps";

const GalleryCardImage: React.FC<{
	props: IGalleryCardProps;
}> = ({ props }) => {
	const { Icon } = components;
	const { faMagnifyingGlass } = libraries.FontAwesomeSolid;
	const [isHovered, setIsHovered] = React.useState(false);
	const { useGalleryLightbox } = hooks;
	const showLightbox = useGalleryLightbox(props.gallery.id, []);

	const openLightbox = async (e: React.MouseEvent) => {
		if (props.gallery.image_count === 0) return;
		e.stopPropagation();
		e.preventDefault();

		showLightbox(0);
	};

	return (
		<div
			className="gallery-card-cover"
			onMouseEnter={() => setIsHovered(true)}
			onMouseLeave={() => setIsHovered(false)}>
			<img
				src={props.gallery.paths?.cover}
				className="gallery-card-image"
			/>
			<div className={`overlay ${isHovered ? "show" : ""}`}>
				<div className="button" onClick={openLightbox}>
					<Icon icon={faMagnifyingGlass} className="icon" />
				</div>
			</div>
		</div>
	);
};

export default GalleryCardImage;

Copy link
Collaborator

@DogmaDragon DogmaDragon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation included.

@WithoutPants
Copy link
Collaborator

@QxxxGit I think I'll need more of the plugin files to test this. I haven't been able to create a working plugin using the code fragment above.

@WithoutPants
Copy link
Collaborator

I managed to get it working to the point where I could see the magnifying glass button and could bring up the lightbox. Running a quick test as described, I wasn't able to reproduce the issue. It does sound very similar to the issue reported here, and I'm wondering if it's related to another plugin. Have you disabled all other plugins?

@WithoutPants
Copy link
Collaborator

The issue you describe is already reported in #5824 so should be unrelated to this change.

@WithoutPants WithoutPants merged commit c09913a into stashapp:develop Jun 20, 2025
2 checks passed
@WithoutPants WithoutPants added the chore Pull requests for refactoring and admin work label Jun 20, 2025
@WithoutPants WithoutPants added this to the Version 0.29.0 milestone Jun 20, 2025
@QxxxGit QxxxGit deleted the lightbox-hooks branch June 26, 2025 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Pull requests for refactoring and admin work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants