-
-
Notifications
You must be signed in to change notification settings - Fork 840
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add gallery wall view, and new lightbox (#1008)
- Loading branch information
InfiniteTF
authored
Dec 24, 2020
1 parent
c8bcaaf
commit 232a69c
Showing
24 changed files
with
979 additions
and
216 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,36 @@ | ||
import React, { useState } from "react"; | ||
import React from "react"; | ||
import * as GQL from "src/core/generated-graphql"; | ||
import FsLightbox from "fslightbox-react"; | ||
import { useLightbox } from "src/hooks"; | ||
import "flexbin/flexbin.css"; | ||
|
||
interface IProps { | ||
gallery: Partial<GQL.GalleryDataFragment>; | ||
gallery: GQL.GalleryDataFragment; | ||
} | ||
|
||
export const GalleryViewer: React.FC<IProps> = ({ gallery }) => { | ||
const [lightboxToggle, setLightboxToggle] = useState(false); | ||
const [currentIndex, setCurrentIndex] = useState(0); | ||
const images = gallery?.images ?? []; | ||
const showLightbox = useLightbox({ images, showNavigation: false }); | ||
|
||
const openImage = (index: number) => { | ||
setCurrentIndex(index); | ||
setLightboxToggle(!lightboxToggle); | ||
}; | ||
|
||
const photos = !gallery.images | ||
? [] | ||
: gallery.images.map((file) => file.paths.image ?? ""); | ||
const thumbs = !gallery.images | ||
? [] | ||
: gallery.images.map((file, index) => ( | ||
<div | ||
role="link" | ||
tabIndex={index} | ||
key={file.checksum ?? index} | ||
onClick={() => openImage(index)} | ||
onKeyPress={() => openImage(index)} | ||
> | ||
<img | ||
src={file.paths.thumbnail ?? ""} | ||
loading="lazy" | ||
className="gallery-image" | ||
alt={file.title ?? index.toString()} | ||
/> | ||
</div> | ||
)); | ||
const thumbs = images.map((file, index) => ( | ||
<div | ||
role="link" | ||
tabIndex={index} | ||
key={file.checksum ?? index} | ||
onClick={() => showLightbox(index)} | ||
onKeyPress={() => showLightbox(index)} | ||
> | ||
<img | ||
src={file.paths.thumbnail ?? ""} | ||
loading="lazy" | ||
className="gallery-image" | ||
alt={file.title ?? index.toString()} | ||
/> | ||
</div> | ||
)); | ||
|
||
return ( | ||
<div className="gallery"> | ||
<div className="flexbin">{thumbs}</div> | ||
<FsLightbox | ||
sourceIndex={currentIndex} | ||
toggler={lightboxToggle} | ||
sources={photos} | ||
key={gallery.id!} | ||
/> | ||
</div> | ||
); | ||
}; |
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,68 @@ | ||
import React from "react"; | ||
import { useIntl } from "react-intl"; | ||
import { Link } from "react-router-dom"; | ||
import * as GQL from "src/core/generated-graphql"; | ||
import { RatingStars, TruncatedText } from "src/components/Shared"; | ||
import { TextUtils } from "src/utils"; | ||
import { useGalleryLightbox } from "src/hooks"; | ||
|
||
const CLASSNAME = "GalleryWallCard"; | ||
const CLASSNAME_FOOTER = `${CLASSNAME}-footer`; | ||
const CLASSNAME_IMG = `${CLASSNAME}-img`; | ||
const CLASSNAME_TITLE = `${CLASSNAME}-title`; | ||
|
||
interface IProps { | ||
gallery: GQL.GallerySlimDataFragment; | ||
} | ||
|
||
const GalleryWallCard: React.FC<IProps> = ({ gallery }) => { | ||
const intl = useIntl(); | ||
const showLightbox = useGalleryLightbox(gallery.id); | ||
|
||
const orientation = | ||
(gallery?.cover?.file.width ?? 0) > (gallery.cover?.file.height ?? 0) | ||
? "landscape" | ||
: "portrait"; | ||
const cover = gallery?.cover?.paths.thumbnail ?? ""; | ||
const title = gallery.title ?? gallery.path; | ||
const performerNames = gallery.performers.map((p) => p.name); | ||
const performers = | ||
performerNames.length >= 2 | ||
? [...performerNames.slice(0, -2), performerNames.slice(-2).join(" & ")] | ||
: performerNames; | ||
|
||
return ( | ||
<> | ||
<section | ||
className={`${CLASSNAME} ${CLASSNAME}-${orientation}`} | ||
onClick={showLightbox} | ||
onKeyPress={showLightbox} | ||
role="button" | ||
tabIndex={0} | ||
> | ||
<RatingStars rating={gallery.rating} /> | ||
<img src={cover} alt="" className={CLASSNAME_IMG} /> | ||
<footer className={CLASSNAME_FOOTER}> | ||
<Link | ||
to={`/galleries/${gallery.id}`} | ||
onClick={(e) => e.stopPropagation()} | ||
> | ||
{title && ( | ||
<TruncatedText | ||
text={title} | ||
lineCount={1} | ||
className={CLASSNAME_TITLE} | ||
/> | ||
)} | ||
<TruncatedText text={performers.join(", ")} /> | ||
<div> | ||
{gallery.date && TextUtils.formatDate(intl, gallery.date)} | ||
</div> | ||
</Link> | ||
</footer> | ||
</section> | ||
</> | ||
); | ||
}; | ||
|
||
export default GalleryWallCard; |
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.