mirror of
https://github.com/khairul169/garage-webui.git
synced 2025-10-14 14:59:32 +07:00

- Updated HTTP methods for bucket and key operations to align with the official Garage Admin API v2 specifications, changing DELETE methods to POST where necessary. - Modified frontend hooks and documentation to reflect these changes, ensuring consistency across the application. - Completed tasks for verifying and aligning delete operations and reviewing other HTTP methods.
33 lines
762 B
TypeScript
33 lines
762 B
TypeScript
import { useEffect, useRef, useState } from "react";
|
|
|
|
export const useDisclosure = <T = unknown>() => {
|
|
const dialogRef = useRef<HTMLDialogElement>(null);
|
|
const [isOpen, setIsOpen] = useState(false);
|
|
const [data, setData] = useState<T | null | undefined>(null);
|
|
|
|
useEffect(() => {
|
|
const dlg = dialogRef.current;
|
|
if (!dlg || !isOpen) return;
|
|
|
|
const onDialogClose = () => {
|
|
setIsOpen(false);
|
|
};
|
|
|
|
dlg.addEventListener("close", onDialogClose);
|
|
return () => dlg.removeEventListener("close", onDialogClose);
|
|
}, [dialogRef, isOpen]);
|
|
|
|
return {
|
|
dialogRef,
|
|
isOpen,
|
|
data,
|
|
onOpen: (data?: T | null) => {
|
|
setIsOpen(true);
|
|
setData(data);
|
|
},
|
|
onClose: () => {
|
|
setIsOpen(false);
|
|
},
|
|
};
|
|
};
|