import { useSignal } from '@preact/signals'; import { useEffect } from 'preact/hooks'; import { RequestBody, ResponseBody } from '/routes/api/files/get-share.tsx'; import { FileShare } from '/lib/types.ts'; interface ManageShareModalProps { baseUrl: string; isOpen: boolean; fileShareId: string; onClickSave: (fileShareId: string, password?: string) => Promise; onClickDelete: (fileShareId: string) => Promise; onClose: () => void; } export default function ManageShareModal( { baseUrl, isOpen, fileShareId, onClickSave, onClickDelete, onClose }: ManageShareModalProps, ) { const newPassword = useSignal(''); const isLoading = useSignal(false); const fileShare = useSignal(null); useEffect(() => { fetchFileShare(); }, [fileShareId]); async function fetchFileShare() { if (!fileShareId || isLoading.value) { return; } isLoading.value = true; try { const requestBody: RequestBody = { fileShareId, }; const response = await fetch(`/api/files/get-share`, { method: 'POST', body: JSON.stringify(requestBody), }); if (!response.ok) { throw new Error(`Failed to get file share. ${response.statusText} ${await response.text()}`); } const result = await response.json() as ResponseBody; if (!result.success) { throw new Error('Failed to get file share!'); } fileShare.value = result.fileShare; isLoading.value = false; } catch (error) { console.error(error); } } return ( <>

Manage Public Share Link

Public Share URL:{' '} {baseUrl}/file-share/{fileShareId}
{ newPassword.value = event.currentTarget.value; }} autocomplete='off' />
); }