diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-11-15 18:17:03 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-15 18:17:03 -0800 |
commit | e749f2f3a52f5c1e137ce8262701b9c9df96324f (patch) | |
tree | 0ca385ae3306a0a2b1cc5ec1b0de953c183b07f6 /src/view/com/lightbox/Lightbox.web.tsx | |
parent | 03b20c70e48f07d6011f632a2aeac954b9de2d96 (diff) | |
download | voidsky-e749f2f3a52f5c1e137ce8262701b9c9df96324f.tar.zst |
Factor lightbox out into hook/context (#1919)
Diffstat (limited to 'src/view/com/lightbox/Lightbox.web.tsx')
-rw-r--r-- | src/view/com/lightbox/Lightbox.web.tsx | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/src/view/com/lightbox/Lightbox.web.tsx b/src/view/com/lightbox/Lightbox.web.tsx index 4b6ad59f3..45e1fa5a3 100644 --- a/src/view/com/lightbox/Lightbox.web.tsx +++ b/src/view/com/lightbox/Lightbox.web.tsx @@ -7,41 +7,42 @@ import { View, Pressable, } from 'react-native' -import {observer} from 'mobx-react-lite' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' -import {useStores} from 'state/index' -import * as models from 'state/models/ui/shell' import {colors, s} from 'lib/styles' import ImageDefaultHeader from './ImageViewing/components/ImageDefaultHeader' import {Text} from '../util/text/Text' import {useLingui} from '@lingui/react' import {msg} from '@lingui/macro' +import { + useLightbox, + useLightboxControls, + ImagesLightbox, + ProfileImageLightbox, +} from '#/state/lightbox' interface Img { uri: string alt?: string } -export const Lightbox = observer(function Lightbox() { - const store = useStores() - - const onClose = useCallback(() => store.shell.closeLightbox(), [store.shell]) +export function Lightbox() { + const {activeLightbox} = useLightbox() + const {closeLightbox} = useLightboxControls() - if (!store.shell.isLightboxActive) { + if (!activeLightbox) { return null } - const activeLightbox = store.shell.activeLightbox const initialIndex = - activeLightbox instanceof models.ImagesLightbox ? activeLightbox.index : 0 + activeLightbox instanceof ImagesLightbox ? activeLightbox.index : 0 let imgs: Img[] | undefined - if (activeLightbox instanceof models.ProfileImageLightbox) { + if (activeLightbox instanceof ProfileImageLightbox) { const opts = activeLightbox if (opts.profile.avatar) { imgs = [{uri: opts.profile.avatar}] } - } else if (activeLightbox instanceof models.ImagesLightbox) { + } else if (activeLightbox instanceof ImagesLightbox) { const opts = activeLightbox imgs = opts.images } @@ -51,9 +52,13 @@ export const Lightbox = observer(function Lightbox() { } return ( - <LightboxInner imgs={imgs} initialIndex={initialIndex} onClose={onClose} /> + <LightboxInner + imgs={imgs} + initialIndex={initialIndex} + onClose={closeLightbox} + /> ) -}) +} function LightboxInner({ imgs, |