mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
Add gallery wall view, and new lightbox (#1008)
This commit is contained in:
73
ui/v2.5/src/hooks/Lightbox/hooks.ts
Normal file
73
ui/v2.5/src/hooks/Lightbox/hooks.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import { useCallback, useContext, useEffect } from "react";
|
||||
import * as GQL from "src/core/generated-graphql";
|
||||
import { LightboxContext, IState } from "./context";
|
||||
|
||||
export const useLightbox = (state: Partial<Omit<IState, "isVisible">>) => {
|
||||
const { setLightboxState } = useContext(LightboxContext);
|
||||
|
||||
useEffect(() => {
|
||||
setLightboxState({
|
||||
images: state.images,
|
||||
showNavigation: state.showNavigation,
|
||||
pageCallback: state.pageCallback,
|
||||
initialIndex: state.initialIndex,
|
||||
pageHeader: state.pageHeader,
|
||||
});
|
||||
}, [
|
||||
setLightboxState,
|
||||
state.images,
|
||||
state.showNavigation,
|
||||
state.pageCallback,
|
||||
state.initialIndex,
|
||||
state.pageHeader,
|
||||
]);
|
||||
|
||||
const show = useCallback(
|
||||
(index?: number) => {
|
||||
setLightboxState({
|
||||
initialIndex: index,
|
||||
isVisible: true,
|
||||
});
|
||||
},
|
||||
[setLightboxState]
|
||||
);
|
||||
return show;
|
||||
};
|
||||
|
||||
export const useGalleryLightbox = (id: string) => {
|
||||
const { setLightboxState } = useContext(LightboxContext);
|
||||
const [fetchGallery, { data }] = GQL.useFindGalleryLazyQuery({
|
||||
variables: { id },
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (data)
|
||||
setLightboxState({
|
||||
images: data.findGallery?.images ?? [],
|
||||
isLoading: false,
|
||||
isVisible: true,
|
||||
});
|
||||
}, [setLightboxState, data]);
|
||||
|
||||
const show = () => {
|
||||
if (data)
|
||||
setLightboxState({
|
||||
isLoading: false,
|
||||
isVisible: true,
|
||||
images: data.findGallery?.images ?? [],
|
||||
pageCallback: undefined,
|
||||
pageHeader: undefined,
|
||||
});
|
||||
else {
|
||||
setLightboxState({
|
||||
isLoading: true,
|
||||
isVisible: true,
|
||||
pageCallback: undefined,
|
||||
pageHeader: undefined,
|
||||
});
|
||||
fetchGallery();
|
||||
}
|
||||
};
|
||||
|
||||
return show;
|
||||
};
|
||||
Reference in New Issue
Block a user