diff --git a/web/src/screens/filters/list.tsx b/web/src/screens/filters/list.tsx index f679cc4..07fa91a 100644 --- a/web/src/screens/filters/list.tsx +++ b/web/src/screens/filters/list.tsx @@ -17,8 +17,8 @@ import { DocumentDuplicateIcon, EllipsisHorizontalIcon, PencilSquareIcon, - TrashIcon, - ExclamationTriangleIcon + ChatBubbleBottomCenterTextIcon, + TrashIcon } from "@heroicons/react/24/outline"; import { queryClient } from "../../App"; @@ -87,10 +87,13 @@ export default function Filters({}: FilterProps){ const queryClient = useQueryClient(); - const [createFilterIsOpen, toggleCreateFilter] = useToggle(false); + const [createFilterIsOpen, setCreateFilterIsOpen] = useState(false); + const toggleCreateFilter = () => { + setCreateFilterIsOpen(!createFilterIsOpen); + }; const [showImportModal, setShowImportModal] = useState(false); - const [importJson, setImportJson] = useState(""); + const [importJson, setImportJson] = useState(""); // This function handles the import of a filter from a JSON string const handleImportJson = async () => { @@ -140,53 +143,71 @@ export default function Filters({}: FilterProps){ } }; - const [showDropdown, setShowDropdown] = useState(false); - return ( - - - Filters - + Filters - - - Add Filter - - setShowDropdown(!showDropdown)} - > - - - {showDropdown && ( - - setShowImportModal(true)} - > - Import Filter - - - )} + + {({ open }) => ( + <> + void; }) => { + if (!open) { + e.stopPropagation(); + toggleCreateFilter(); + } + }} + > + + Add Filter + + + + + + + + {({ active }) => ( + setShowImportModal(true)} + > + Import Filter + + )} + + + + > + )} + + {showImportModal && ( Import Filter JSON setImportJson(event.target.value)} @@ -198,20 +219,19 @@ export default function Filters({}: FilterProps){ className="bg-white dark:bg-gray-700 py-2 px-4 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm text-sm font-medium text-gray-700 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 dark:focus:ring-blue-500" onClick={() => setShowImportModal(false)} > - Cancel + Cancel - Import + Import )} - ); @@ -326,8 +346,7 @@ interface FilterItemDropdownProps { const FilterItemDropdown = ({ filter, onToggle }: FilterItemDropdownProps) => { // This function handles the export of a filter to a JSON string - const handleExportJson = useCallback(async () => { - try { + const handleExportJson = useCallback(async (discordFormat = false) => { try { type CompleteFilterType = { id: number; name: string; @@ -386,16 +405,20 @@ const FilterItemDropdown = ({ filter, onToggle }: FilterItemDropdownProps) => { null, 4 ); + + const finalJson = discordFormat ? "```JSON\n" + json + "\n```" : json; + - navigator.clipboard.writeText(json).then(() => { + navigator.clipboard.writeText(finalJson).then(() => { toast.custom((t) => ); }, () => { toast.custom((t) => ); }); - } catch (error) { - console.error(error); - toast.custom((t) => ); - } + + } catch (error) { + console.error(error); + toast.custom((t) => ); + } }, [filter]); const cancelModalButtonRef = useRef(null); @@ -485,8 +508,7 @@ const FilterItemDropdown = ({ filter, onToggle }: FilterItemDropdownProps) => { active ? "bg-blue-600 text-white" : "text-gray-900 dark:text-gray-300", "font-medium group flex rounded-md items-center w-full px-2 py-2 text-sm" )} - onClick={handleExportJson} - > + onClick={() => handleExportJson(false)} > { )} + + {({ active }) => ( + handleExportJson(true)} + > + + Export JSON to Discord + + )} + {({ active }) => (