about summary refs log tree commit diff
path: root/src/view/com/lightbox/Lightbox.web.tsx
diff options
context:
space:
mode:
authorJohn Fawcett <jrf0110@gmail.com>2023-03-27 10:18:14 -0500
committerGitHub <noreply@github.com>2023-03-27 10:18:14 -0500
commitdef8be2137846adac1afd09fa237e08656f97c5c (patch)
tree79970ac3826b723bdbc3b555a2c534e2e95fe2e1 /src/view/com/lightbox/Lightbox.web.tsx
parent2789d5c05647e3d6d6ae5d6e226b4218ed4a16d1 (diff)
downloadvoidsky-def8be2137846adac1afd09fa237e08656f97c5c.tar.zst
Fixes the lightbox image index not being passed through to the web version (#306) (#324)
Diffstat (limited to 'src/view/com/lightbox/Lightbox.web.tsx')
-rw-r--r--src/view/com/lightbox/Lightbox.web.tsx28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/view/com/lightbox/Lightbox.web.tsx b/src/view/com/lightbox/Lightbox.web.tsx
index f12839fba..f10548351 100644
--- a/src/view/com/lightbox/Lightbox.web.tsx
+++ b/src/view/com/lightbox/Lightbox.web.tsx
@@ -23,16 +23,20 @@ export const Lightbox = observer(function Lightbox() {
     return null
   }
 
+  const activeLightbox = store.shell.activeLightbox
+  const initialIndex =
+    activeLightbox instanceof models.ImagesLightbox ? activeLightbox.index : 0
+
   const onClose = () => store.shell.closeLightbox()
 
   let imgs: Img[] | undefined
-  if (store.shell.activeLightbox?.name === 'profile-image') {
-    const opts = store.shell.activeLightbox as models.ProfileImageLightbox
+  if (activeLightbox instanceof models.ProfileImageLightbox) {
+    const opts = activeLightbox
     if (opts.profileView.avatar) {
       imgs = [{uri: opts.profileView.avatar}]
     }
-  } else if (store.shell.activeLightbox?.name === 'images') {
-    const opts = store.shell.activeLightbox as models.ImagesLightbox
+  } else if (activeLightbox instanceof models.ImagesLightbox) {
+    const opts = activeLightbox
     imgs = opts.uris.map(uri => ({uri}))
   }
 
@@ -40,11 +44,21 @@ export const Lightbox = observer(function Lightbox() {
     return null
   }
 
-  return <LightboxInner imgs={imgs} onClose={onClose} />
+  return (
+    <LightboxInner imgs={imgs} initialIndex={initialIndex} onClose={onClose} />
+  )
 })
 
-function LightboxInner({imgs, onClose}: {imgs: Img[]; onClose: () => void}) {
-  const [index, setIndex] = React.useState<number>(0)
+function LightboxInner({
+  imgs,
+  initialIndex = 0,
+  onClose,
+}: {
+  imgs: Img[]
+  initialIndex: number
+  onClose: () => void
+}) {
+  const [index, setIndex] = React.useState<number>(initialIndex)
 
   const canGoLeft = index >= 1
   const canGoRight = index < imgs.length - 1