import { useState } from "@wordpress/element"; import { Database, FlaskConical, Trash2 } from "lucide-react"; import CacheTestDialog from "@/common/CacheTestDialog"; import StatusDialog from "@/common/StatusDialog"; import Button from "@/components/Button"; import Card, { CardContent, CardHeader } from "@/components/Card"; import { ApiResponse, spcApi } from "@/lib/api"; import { useAppStore } from "@/store/store"; import { __ } from "@wordpress/i18n"; import { toast } from "sonner"; const SidebarActions = () => { const { asyncLocked, lockAsync } = useAppStore(); const [purging, setPurging] = useState(false); const [testing, setTesting] = useState(false); const [preloading, setPreloading] = useState(false); const [purgeDialogData, setDialogContent] = useState(null as ApiResponse | null); const [cacheTestDialogData, setCacheTestDialogData] = useState(null as ApiResponse | null); const onCachePurge = async () => { lockAsync(true); setPurging(true); const result = await spcApi.purgeCacheAll(); setDialogContent(result); lockAsync(false); setPurging(false); } const onTestingStart = async () => { lockAsync(true); setTesting(true); const result = await spcApi.testCache(); setCacheTestDialogData(result); lockAsync(false); setTesting(false); } const onPreloadStart = async () => { lockAsync(true); setPreloading(true); const response = await spcApi.startPreloader(); lockAsync(false); setPreloading(false); if (!response.success) { toast.error(response.message); return; } toast.success(response.message); } return ( <> {!!purgeDialogData && setDialogContent(null)} description={purgeDialogData?.message} success={purgeDialogData?.success} />} {!!cacheTestDialogData && setCacheTestDialogData(null)} data={cacheTestDialogData} />}

{__('Actions', 'wp-cloudflare-page-cache')}

); }; export default SidebarActions;