import clsx from "clsx"; import React, { useRef, useState } from "react"; import { ChromePicker } from "react-color"; import { usePagination } from "react-use-pagination"; import plugins from "../../static/plugins.json"; import { Tag, useFilteredObjs } from "../libs/store"; import Card from "./Card"; import Modal from "./Modal"; import ModalAction from "./ModalAction"; import ModalContent from "./ModalContent"; import ModalTitle from "./ModalTitle"; import Paginate from "./Paginate"; import TagComponent from "./Tag"; export default function Plugin(): JSX.Element { const [modalOpen, setModalOpen] = useState(false); const { filter, setFilter, filteredObjs: filteredPlugins, } = useFilteredObjs(plugins); const props = usePagination({ totalItems: filteredPlugins.length, initialPageSize: 10, }); const { startIndex, endIndex } = props; const currentPlugins = filteredPlugins.slice(startIndex, endIndex + 1); const [form, setForm] = useState<{ projectLink: string; moduleName: string; }>({ projectLink: "", moduleName: "" }); const ref = useRef(null); const [tags, setTags] = useState([]); const [label, setLabel] = useState(""); const [color, setColor] = useState("#ea5252"); const urlEncode = (str: string) => encodeURIComponent(str).replace(/%2B/gi, "+"); const onSubmit = () => { setModalOpen(false); const queries: { key: string; value: string }[] = [ { key: "template", value: "plugin_publish.yml" }, { key: "title", value: form.projectLink && `Plugin: ${form.projectLink}`, }, { key: "labels", value: "Plugin" }, { key: "pypi", value: form.projectLink }, { key: "module", value: form.moduleName }, { key: "tags", value: JSON.stringify(tags) }, ]; const urlQueries = queries .filter((query) => !!query.value) .map((query) => `${query.key}=${urlEncode(query.value)}`) .join("&"); window.open(`https://github.com/nonebot/nonebot2/issues/new?${urlQueries}`); }; const onChange = (event) => { const target = event.target; const value = target.type === "checkbox" ? target.checked : target.value; const name = target.name; setForm({ ...form, [name]: value, }); event.preventDefault(); }; const onChangeLabel = (event) => { setLabel(event.target.value); }; const onChangeColor = (color) => { setColor(color.hex); }; const validateTag = () => { return label.length >= 1 && label.length <= 10; }; const newTag = () => { if (tags.length >= 3) { return; } if (validateTag()) { const tag = { label, color }; setTags([...tags, tag]); } }; const delTag = (index: number) => { setTags(tags.filter((_, i) => i !== index)); }; return ( <>
setFilter(event.target.value)} />
{currentPlugins.map((plugin, index) => ( ))}
); }