garage-webui/src/hooks/useDisclosure.ts
Adekabang 33ed173dec feat: align API endpoints with official specifications for bucket and key management
- 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.
2025-07-31 18:10:39 -04:00

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);
},
};
};