From b84f81611a781a8750e07d9461f8f81c087c8908 Mon Sep 17 00:00:00 2001 From: Lumither Tao Date: Sun, 13 Oct 2024 21:11:57 -0700 Subject: [PATCH] feat(json parser) export, formatter --- app/Header.tsx | 10 +-- app/jsonparser/ExportModal.tsx | 127 +++++++++++++++++++++++++++++++++ app/jsonparser/JsonEditor.tsx | 34 +++++++++ app/jsonparser/page.tsx | 4 +- app/public/MonacoEditor.tsx | 62 ++++++++++++---- 5 files changed, 218 insertions(+), 19 deletions(-) create mode 100644 app/jsonparser/ExportModal.tsx create mode 100644 app/jsonparser/JsonEditor.tsx diff --git a/app/Header.tsx b/app/Header.tsx index 339753f..3eddf0d 100644 --- a/app/Header.tsx +++ b/app/Header.tsx @@ -1,7 +1,6 @@ -'use client'; - import React from 'react'; import ThemeSwitcher from '@/Components/ThemeSwitcher'; +import Link from 'next/link'; const Header = () => { @@ -13,9 +12,12 @@ const Header = () => {
-
+ LMTLab -
+
diff --git a/app/jsonparser/ExportModal.tsx b/app/jsonparser/ExportModal.tsx new file mode 100644 index 0000000..63fbd18 --- /dev/null +++ b/app/jsonparser/ExportModal.tsx @@ -0,0 +1,127 @@ +'use client'; + +import React, { useEffect, useState } from 'react'; +import { + Button, + Checkbox, + CheckboxGroup, + Modal, + ModalBody, + ModalContent, + ModalFooter, + ModalHeader, + Textarea +} from '@nextui-org/react'; +import { toast } from 'react-toastify'; +import { HiOutlineDownload, HiOutlineDuplicate } from 'react-icons/hi'; + +const workflows = new Map string>([ + [ 'minify', (json) => { + try { + const value = JSON.parse(json); + return JSON.stringify(value); + } catch (e) { + toast.error(`Operation Failed: ${ e }`, { autoClose: 5000 }); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-expect-error + return e.toString(); + } + } ] +]); + +type Props = { isOpen: boolean, onOpenChange: () => void, value: string }; + +const ExportModal = ({ isOpen, onOpenChange, value }: Props) => { + const [ workflow, setWorkflow ] = useState([]); + const [ editorValue, setEditorValue ] = useState(value); + useEffect(() => { + setEditorValue(value); + }, [ value ]); + + const [ exportValue, setExportValue ] = useState(editorValue); + useEffect(() => { + let value = editorValue; + for (const fn of workflow) { + const func = workflows.get(fn); + value = func ? func(value) : value; + } + setExportValue(value); + }, [ workflow, editorValue ]); + + return ( + + + { (onClose) => ( + <> + Export + + + Minify + + +