react-photoswipe icon indicating copy to clipboard operation
react-photoswipe copied to clipboard

Gallery won't open on load page with pid and gid in params

Open tomasztomys opened this issue 7 years ago • 2 comments

Gallery won't open on load page with pid and gid in params: http://localhost:3000/dashboard/company/1/gallery#&gid=1&pid=1 should open gallery with photo (gid = 1, pid = 1)

tomasztomys avatar Jan 14 '17 20:01 tomasztomys

https://codepen.io/daveclay/pen/LLPwKP

I'm trying to just get the instance of PhotoSwipe to open by default, but setting isOpen={true} doesn't do anything. It results in an empty photoswipe instance.

daveclay avatar Jun 02 '17 14:06 daveclay

Hi, faced the same issue, isOpen should be definitely working, but it's not here is how I made it work

  1. is items add id <PhotoSwipeGallery items={[ {src, thumbnail, id: pictureId} ]}

  2. add id to img in thumbnailContent={item => <img id={item.id} src={item.thumbnail} width={400} height={400} style={{cursor: 'zoom-in'}} /> }

  3. if gid is in url then call this function: openGallery(gid) { const image = document.getElementById(gid) var evObj = document.createEvent('Events'); evObj.initEvent('click', true, false); image.dispatchEvent(evObj); }

if you have more than 1 picture per gallery then you can use pid instead and simulate click by pid

Stas-Buzunko avatar Sep 30 '17 14:09 Stas-Buzunko