import styles from './pluginCard.module.css'; import { PluginCardVO } from '@/app/home/plugins/plugin-installed/PluginCardVO'; import { useState } from 'react'; import { httpClient } from '@/app/infra/http/HttpClient'; import { Badge } from "@/components/ui/badge" import { Switch } from "@/components/ui/switch" import { Button } from "@/components/ui/button" export default function PluginCardComponent({ cardVO, onCardClick, }: { cardVO: PluginCardVO; onCardClick: () => void; }) { const [enabled, setEnabled] = useState(cardVO.enabled); const [switchEnable, setSwitchEnable] = useState(true); function handleEnable(e: React.MouseEvent) { e.stopPropagation(); // 阻止事件冒泡 setSwitchEnable(false); httpClient .togglePlugin(cardVO.author, cardVO.name, !enabled) .then(() => { setEnabled(!enabled); }) .catch((err) => { console.log('error: ', err); }) .finally(() => { setSwitchEnable(true); }); } return (