Skip to content
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

Fix photoswipe gallery incorrect behaviour #76

Merged
merged 1 commit into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions components/pages/Gallery/GalleryItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,23 @@ import {MutableRefObject} from 'react';
import {Item} from 'react-photoswipe-gallery';
import 'photoswipe/dist/photoswipe.css';
import GalleryImage from './GalleryImage';
import {GalleryConfigItem} from './config';

/**
* Props.
*/
type GalleryItemProps = {
src: string;
blurDataURL: string;
dimensions: {
width: number;
height: number;
};
};
type GalleryItemProps = GalleryConfigItem;

/**
* @param {GalleryItemProps} props Props.
* @returns React component.
*/
export default function GalleryItem({
src,
blurDataURL,
dimensions: {width, height},
}: GalleryItemProps) {
export default function GalleryItem({src, blurDataURL, width, height, alt}: GalleryItemProps) {
return (
<Item
original={src}
thumbnail={src}
alt=""
alt={alt}
width={width}
height={height}
key={src}
Expand Down
45 changes: 27 additions & 18 deletions components/pages/Gallery/config.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
// eslint-disable-next-line jsdoc/require-jsdoc
export type GalleryConfigItem = {
src: string;
blurDataURL: string;
width: number;
height: number;
alt?: string;
};

/**
* Gallery images configuration.
*/
const config = [
{fileName: 'gallery.0.jpg', dimensions: {width: 920, height: 1200}},
{fileName: 'gallery.1.jpg', dimensions: {width: 920, height: 600}},
{fileName: 'gallery.2.jpg', dimensions: {width: 920, height: 600}},
{fileName: 'gallery.3.jpg', dimensions: {width: 920, height: 600}},
{fileName: 'gallery.4.jpg', dimensions: {width: 920, height: 600}},
{fileName: 'gallery.5.jpg', dimensions: {width: 920, height: 600}},
{fileName: 'gallery.6.jpg', dimensions: {width: 920, height: 600}},
{fileName: 'gallery.7.jpg', dimensions: {width: 920, height: 600}},
{fileName: 'gallery.8.jpg', dimensions: {width: 920, height: 600}},
{fileName: 'gallery.9.jpg', dimensions: {width: 920, height: 600}},
{fileName: 'gallery.10.jpg', dimensions: {width: 920, height: 600}},
{fileName: 'gallery.11.jpg', dimensions: {width: 920, height: 600}},
{fileName: 'gallery.12.jpg', dimensions: {width: 920, height: 600}},
{fileName: 'gallery.13.jpg', dimensions: {width: 920, height: 600}},
{fileName: 'gallery.14.jpg', dimensions: {width: 920, height: 600}},
{fileName: 'gallery.15.jpg', dimensions: {width: 920, height: 600}},
{fileName: 'gallery.0.jpg', width: 640, height: 425, alt: ''},
{fileName: 'gallery.1.jpg', width: 920, height: 600, alt: ''},
{fileName: 'gallery.2.jpg', width: 920, height: 600, alt: ''},
{fileName: 'gallery.3.jpg', width: 920, height: 600, alt: ''},
{fileName: 'gallery.4.jpg', width: 920, height: 600, alt: ''},
{fileName: 'gallery.5.jpg', width: 920, height: 600, alt: ''},
{fileName: 'gallery.6.jpg', width: 920, height: 600, alt: ''},
{fileName: 'gallery.7.jpg', width: 920, height: 600, alt: ''},
{fileName: 'gallery.8.jpg', width: 920, height: 600, alt: ''},
{fileName: 'gallery.9.jpg', width: 920, height: 600, alt: ''},
{fileName: 'gallery.10.jpg', width: 920, height: 600, alt: ''},
{fileName: 'gallery.11.jpg', width: 920, height: 600, alt: ''},
{fileName: 'gallery.12.jpg', width: 920, height: 600, alt: ''},
{fileName: 'gallery.13.jpg', width: 920, height: 600, alt: ''},
{fileName: 'gallery.14.jpg', width: 920, height: 600, alt: ''},
{fileName: 'gallery.15.jpg', width: 1280, height: 854, alt: ''},
] as const;

export default config.map(({fileName, dimensions}) => ({
dimensions,
export default config.map<GalleryConfigItem>(({fileName, ...rest}) => ({
...rest,
src: `/images/${fileName}`,
blurDataURL: `/images/blured/${fileName}`,
}));
12 changes: 6 additions & 6 deletions lib/shared/useDisableBodyScroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import {useEffect} from 'react';
export default function useDisableBodyScroll(open: boolean) {
useEffect(() => {
if (open) {
document.body.style.overflow = 'hidden';

if (getBosyHasOevrflow()) {
if (getBodyHasOverflow()) {
const scrollbarWidth = window.innerWidth - document.body.clientWidth;
document.body.style.paddingRight = `${scrollbarWidth}px`;
}

document.body.style.overflow = 'hidden';
} else {
document.body.style.overflow = 'unset';
document.body.style.overflow = 'auto';
document.body.style.paddingRight = 'unset';
}
}, [open]);
}

// eslint-disable-next-line jsdoc/require-jsdoc
function getBosyHasOevrflow() {
return document.body.scrollHeight > document.body.clientHeight;
function getBodyHasOverflow() {
return window.innerHeight < document.body.clientHeight;
}
Binary file modified public/images/gallery.15.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"start_url": "/",
"icons": [
{
"src": "/icons/logo.png",
"src": "/icons/logo_192.png",
"type": "image/png",
"sizes": "192x192"
},
Expand Down