|
| 1 | +import React, { useEffect, useState } from 'react'; |
| 2 | +import {} from '@emotion/react'; |
| 3 | +import Editor from '@monaco-editor/react'; |
| 4 | +import { Select } from 'antd'; |
| 5 | +import { BaseOptionType } from 'antd/es/select'; |
| 6 | +import { formatFunc, FormatTool } from './utils'; |
| 7 | + |
| 8 | +const convertOption: BaseOptionType[] = Object.keys(FormatTool).map((e) => { |
| 9 | + return { |
| 10 | + label: FormatTool[e as keyof typeof FormatTool], |
| 11 | + value: FormatTool[e as keyof typeof FormatTool], |
| 12 | + }; |
| 13 | +}); |
| 14 | + |
| 15 | +const RemoveLines = () => { |
| 16 | + const [fromValue, setFromValue] = useState(''); |
| 17 | + const [toValue, setToValue] = useState(''); |
| 18 | + const [convertFunction, setConvertFunction] = useState(''); |
| 19 | + const [convertSelected, setConvertSelected] = useState<FormatTool>(FormatTool.DEFAULT); |
| 20 | + |
| 21 | + const handleConvert = () => { |
| 22 | + console.log(convertSelected); |
| 23 | + const _formatFunc = formatFunc[convertSelected]; |
| 24 | + try { |
| 25 | + const _output = _formatFunc(fromValue); |
| 26 | + console.log('🚀 ~ file: index.tsx:26 ~ handleConvert ~ _output:', _output); |
| 27 | + setToValue(_output); |
| 28 | + } catch (e) { |
| 29 | + setToValue(JSON.stringify(e, null, 2)); |
| 30 | + } |
| 31 | + }; |
| 32 | + |
| 33 | + return ( |
| 34 | + <div className="flex h-0 flex-1 flex-shrink items-stretch space-x-3 rounded-md p-1"> |
| 35 | + <div className="flex h-full flex-1 rounded-md bg-white shadow-md"> |
| 36 | + <div className="flex flex-1 flex-col"> |
| 37 | + {/* <div className='h-10'> |
| 38 | + copy |
| 39 | + </div> */} |
| 40 | + <Editor |
| 41 | + theme="vs-dark" |
| 42 | + height="100%" |
| 43 | + width="100%" |
| 44 | + defaultLanguage="plaintext" |
| 45 | + value={fromValue} |
| 46 | + onChange={(value) => value && setFromValue(value)} |
| 47 | + defaultValue="" |
| 48 | + /> |
| 49 | + </div> |
| 50 | + </div> |
| 51 | + <div className="flex h-full min-w-[300px] flex-col items-stretch justify-center space-y-4 rounded-md bg-white shadow-md"> |
| 52 | + <Select |
| 53 | + showSearch |
| 54 | + defaultValue="default" |
| 55 | + onChange={(value) => setConvertSelected(value)} |
| 56 | + value={convertSelected} |
| 57 | + options={convertOption} |
| 58 | + className="w-full" |
| 59 | + /> |
| 60 | + <button className="rounded-lg bg-blue-300 px-3 py-2 " onClick={handleConvert}> |
| 61 | + Convert |
| 62 | + </button> |
| 63 | + {/* <Editor |
| 64 | + theme="vs-dark" |
| 65 | + height="100%" |
| 66 | + width="100%" |
| 67 | + defaultLanguage="javascript" |
| 68 | + defaultValue="" |
| 69 | + value={convertFunction} |
| 70 | + onChange={(value) => value && setConvertFunction(value)} |
| 71 | + options={{ |
| 72 | + minimap: { |
| 73 | + enabled: false, |
| 74 | + }, |
| 75 | + }} |
| 76 | + /> */} |
| 77 | + </div> |
| 78 | + <div className="flex h-full flex-1 rounded-md bg-white shadow-md"> |
| 79 | + <Editor |
| 80 | + theme="vs-dark" |
| 81 | + height="100%" |
| 82 | + width="100%" |
| 83 | + defaultLanguage="plaintext" |
| 84 | + defaultValue="" |
| 85 | + value={toValue} |
| 86 | + onChange={(value) => value && setToValue(value)} |
| 87 | + /> |
| 88 | + </div> |
| 89 | + </div> |
| 90 | + ); |
| 91 | +}; |
| 92 | + |
| 93 | +export default RemoveLines; |
0 commit comments