From a84b2f9f2f64b1d434c5adbb12af6f7d76ba42ea Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Thu, 16 Nov 2023 08:18:59 -0800 Subject: Close active elems (react-query refactor) (#1926) * Refactor closeAny and closeAllActiveElements * Add close lightbox * Switch to hooks * Fixes --- src/state/lightbox.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/state/lightbox.tsx') diff --git a/src/state/lightbox.tsx b/src/state/lightbox.tsx index 613cd638e..d5528ac28 100644 --- a/src/state/lightbox.tsx +++ b/src/state/lightbox.tsx @@ -31,10 +31,10 @@ const LightboxContext = React.createContext<{ const LightboxControlContext = React.createContext<{ openLightbox: (lightbox: Lightbox) => void - closeLightbox: () => void + closeLightbox: () => boolean }>({ openLightbox: () => {}, - closeLightbox: () => {}, + closeLightbox: () => false, }) export function Provider({children}: React.PropsWithChildren<{}>) { @@ -50,8 +50,10 @@ export function Provider({children}: React.PropsWithChildren<{}>) { ) const closeLightbox = React.useCallback(() => { + let wasActive = !!activeLightbox setActiveLightbox(null) - }, [setActiveLightbox]) + return wasActive + }, [setActiveLightbox, activeLightbox]) const state = React.useMemo( () => ({ -- cgit 1.4.1