1- import React from 'react' ;
1+ import React , { useState } from 'react' ;
22import PropTypes from 'prop-types' ;
33import { Link , useHistory , useLocation } from 'react-router-dom' ;
44import { usePreviousImmediate } from 'rooks' ;
@@ -12,30 +12,26 @@ import * as icons from '../icons';
1212import { ConfigurationContext } from '../helpers/configuration' ;
1313import { LocalizationContext } from '../helpers/i18n' ;
1414import { useSharers } from '../sharers' ;
15- import SimpleLightbox from 'simplelightbox/dist/simple- lightbox.esm ' ;
15+ import Lightbox from 'yet-another-react- lightbox' ;
1616
17- function setupLightbox ( element ) {
17+ function setupLightbox ( {
18+ element,
19+ setSlides,
20+ setSelectedPhotoIndex,
21+ } ) {
1822 let images = element . querySelectorAll ( 'a[href$=".jpg"], a[href$=".jpeg"], a[href$=".png"], a[href$=".gif"], a[href$=".jpg:large"], a[href$=".jpeg:large"], a[href$=".png:large"], a[href$=".gif:large"]' ) ;
1923
20- if ( images . length === 0 ) {
21- return ;
22- }
23- const gallery = new SimpleLightbox (
24- images ,
25- {
26- loop : false ,
27- // react-router already handles this.
28- history : false ,
29- } ,
30- ) ;
24+ setSlides ( Array . from ( images ) . map ( ( link , index ) => {
25+ link . addEventListener ( 'click' , ( event ) => {
26+ event . preventDefault ( ) ;
3127
32- gallery . on ( 'show.simplelightbox' , function ( ) {
33- selfoss . lightboxActive . update ( true ) ;
34- } ) ;
28+ setSelectedPhotoIndex ( index ) ;
29+ } ) ;
3530
36- gallery . on ( 'close.simplelightbox' , function ( ) {
37- selfoss . lightboxActive . update ( false ) ;
38- } ) ;
31+ return {
32+ src : link . getAttribute ( 'href' ) ,
33+ } ;
34+ } ) ) ;
3935}
4036
4137function stopPropagation ( event ) {
@@ -252,6 +248,9 @@ export default function Item({ currentTime, item, selected, expanded, setNavExpa
252248 const previouslyExpanded = usePreviousImmediate ( expanded ) ;
253249 const configuration = React . useContext ( ConfigurationContext ) ;
254250
251+ const [ slides , setSlides ] = useState ( [ ] ) ;
252+ const [ selectedPhotoIndex , setSelectedPhotoIndex ] = useState ( null ) ;
253+
255254 React . useEffect ( ( ) => {
256255 // Handle entry becoming/ceasing to be expanded.
257256 const parent = document . querySelector ( `.entry[data-entry-id="${ item . id } "]` ) ;
@@ -301,7 +300,11 @@ export default function Item({ currentTime, item, selected, expanded, setNavExpa
301300 } else {
302301 if ( firstExpansion ) {
303302 // setup fancyBox image viewer
304- setupLightbox ( contentBlock . current ) ;
303+ setupLightbox ( {
304+ element : contentBlock . current ,
305+ setSlides,
306+ setSelectedPhotoIndex,
307+ } ) ;
305308 }
306309
307310 // scroll to article header
@@ -501,6 +504,23 @@ export default function Item({ currentTime, item, selected, expanded, setNavExpa
501504
502505 { /* content */ }
503506 < div className = { classNames ( { 'entry-content' : true , 'entry-content-nocolumns' : item . lengthWithoutTags < 500 } ) } >
507+ < Lightbox
508+ open = { selectedPhotoIndex !== null }
509+ index = { selectedPhotoIndex }
510+ close = { ( ) => setSelectedPhotoIndex ( null ) }
511+ carousel = { {
512+ finite : true ,
513+ } }
514+ controller = { {
515+ closeOnBackdropClick : true ,
516+ } }
517+ on = { {
518+ entered : ( ) => selfoss . lightboxActive . update ( true ) ,
519+ exited : ( ) => selfoss . lightboxActive . update ( false ) ,
520+ } }
521+ slides = { slides }
522+ />
523+
504524 < div ref = { contentBlock } />
505525
506526 < div className = "entry-smartphone-share" >
0 commit comments