import { useEffect, useState } from "react"; import * as utils from "../helpers/utils"; import useLoading from "../hooks/useLoading"; import { resourceService } from "../services"; import Dropdown from "./common/Dropdown"; import { generateDialog } from "./Dialog"; import { showCommonDialog } from "./Dialog/CommonDialog"; import toastHelper from "./Toast"; import Icon from "./Icon"; import "../less/resources-dialog.less"; interface Props extends DialogProps {} const ResourcesDialog: React.FC = (props: Props) => { const { destroy } = props; const loadingState = useLoading(); const [resources, setResources] = useState([]); useEffect(() => { fetchResources() .catch((error) => { toastHelper.error("Failed to fetch archived memos: ", error); }) .finally(() => { loadingState.setFinish(); }); }, []); const fetchResources = async () => { const data = await resourceService.getResourceList(); setResources(data); }; const handleCopyResourceLinkBtnClick = (resource: Resource) => { utils.copyTextToClipboard(`${window.location.origin}/h/r/${resource.id}/${resource.filename}`); toastHelper.success("Succeed to copy resource link to clipboard"); }; const handleDeleteResourceBtnClick = (resource: Resource) => { showCommonDialog({ title: `Delete Resource`, content: `Are you sure to delete this resource? THIS ACTION IS IRREVERSIABLE.❗️`, style: "warning", onConfirm: async () => { await resourceService.deleteResourceById(resource.id); await fetchResources(); }, }); }; return ( <>

🌄 Resources

(👨‍💻WIP) View your static resources in memos. e.g. images
{loadingState.isLoading ? (

fetching data...

) : (
ID NAME TYPE
{resources.map((resource) => (
{resource.id} {resource.filename} {resource.type}
))}
)}
); }; export default function showResourcesDialog() { generateDialog( { className: "resources-dialog", useAppContext: true, }, ResourcesDialog, {} ); }