From da3a053a6c60cab14abc16d21d629efd81fb2375 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ph=E1=BA=A1m=20V=C4=83n=20Nguy=C3=AAn?= Date: Mon, 1 Jan 2024 10:33:19 +0700 Subject: [PATCH] update ui --- src/components/AppLayout/index.tsx | 4 +- src/modules/tools/index.tsx | 7 +- src/modules/tools/tools/Convert/index.tsx | 88 ------------------ src/modules/tools/tools/index.tsx | 2 +- .../tools/tools/remove-lines/index.tsx | 93 +++++++++++++++++++ .../tools/tools/remove-lines/utils/index.tsx | 15 +++ .../tools/tools/remove-lines/utils/text.tsx | 24 +++++ 7 files changed, 139 insertions(+), 94 deletions(-) delete mode 100644 src/modules/tools/tools/Convert/index.tsx create mode 100644 src/modules/tools/tools/remove-lines/index.tsx create mode 100644 src/modules/tools/tools/remove-lines/utils/index.tsx create mode 100644 src/modules/tools/tools/remove-lines/utils/text.tsx diff --git a/src/components/AppLayout/index.tsx b/src/components/AppLayout/index.tsx index ce0a574..2bd0767 100644 --- a/src/components/AppLayout/index.tsx +++ b/src/components/AppLayout/index.tsx @@ -84,8 +84,8 @@ const AppLayout: React.FC = ({ children }) => { */} - -
+ +
{children}
diff --git a/src/modules/tools/index.tsx b/src/modules/tools/index.tsx index 2f0cdca..6d8b01c 100644 --- a/src/modules/tools/index.tsx +++ b/src/modules/tools/index.tsx @@ -1,8 +1,8 @@ import ToolsLayout from './components/ToolsLayout'; import { RandomPasswordTool } from './tools'; -import ConvertTool from './tools/Convert'; import { RouteObject } from 'react-router-dom'; +import RemoveLines from './tools/remove-lines'; const ToolsModule: RouteObject = { path: 'tools', @@ -12,9 +12,10 @@ const ToolsModule: RouteObject = { path: 'random-password-tool', element: , }, + { - path: 'convert-tool', - element: , + path: 'Convert', + element: , }, ], }; diff --git a/src/modules/tools/tools/Convert/index.tsx b/src/modules/tools/tools/Convert/index.tsx deleted file mode 100644 index 4a4bc8f..0000000 --- a/src/modules/tools/tools/Convert/index.tsx +++ /dev/null @@ -1,88 +0,0 @@ -import React, { useEffect, useState } from 'react'; -import {} from '@emotion/react'; -import Editor from '@monaco-editor/react'; - -const ConvertTool = () => { - const [fromValue, setFromValue] = useState(''); - const [toValue, setToValue] = useState(''); - const [fromLang, setFromLang] = useState('javascript'); - - function convertSCSSToReactNative(scssCode) { - const styles = {}; - - // Remove comments from the SCSS code - const cleanedCode = scssCode.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, ''); - - // Split the code into individual lines - const lines = cleanedCode.split(';'); - - // Process each line of SCSS code - lines.forEach((line) => { - if (line.trim().length === 0) { - return; - } - - // Split the line into property and value - const [property, value] = line.split(':'); - - // Convert property names - const convertedProperty = property - .trim() - .replace(/-([a-z])/g, (match, letter) => letter.toUpperCase()); - - // Convert values - const convertedValue = value?.trim().replace(/([0-9.]+)px/g, '$1'); - - // Add the converted style to the stylesheet - styles[convertedProperty] = convertedValue; - }); - - return styles; - } - - const handleConvert = () => { - if (!fromValue) return; - setToValue(JSON.stringify(convertSCSSToReactNative(fromValue), null, 2)); - }; - - return ( -
-
-
- {/*
- copy -
*/} - setFromValue(value)} - defaultValue="" - /> -
-
-
-
- -
-
-
- setToValue(value)} - /> -
-
- ); -}; - -export default ConvertTool; diff --git a/src/modules/tools/tools/index.tsx b/src/modules/tools/tools/index.tsx index 49983de..7e269e6 100644 --- a/src/modules/tools/tools/index.tsx +++ b/src/modules/tools/tools/index.tsx @@ -1,2 +1,2 @@ export * from './RandomPasswordTool'; -export * from './Convert'; +export * from "./remove-lines" \ No newline at end of file diff --git a/src/modules/tools/tools/remove-lines/index.tsx b/src/modules/tools/tools/remove-lines/index.tsx new file mode 100644 index 0000000..66aeaf3 --- /dev/null +++ b/src/modules/tools/tools/remove-lines/index.tsx @@ -0,0 +1,93 @@ +import React, { useEffect, useState } from 'react'; +import {} from '@emotion/react'; +import Editor from '@monaco-editor/react'; +import { Select } from 'antd'; +import { BaseOptionType } from 'antd/es/select'; +import { formatFunc, FormatTool } from './utils'; + +const convertOption: BaseOptionType[] = Object.keys(FormatTool).map((e) => { + return { + label: FormatTool[e as keyof typeof FormatTool], + value: FormatTool[e as keyof typeof FormatTool], + }; +}); + +const RemoveLines = () => { + const [fromValue, setFromValue] = useState(''); + const [toValue, setToValue] = useState(''); + const [convertFunction, setConvertFunction] = useState(''); + const [convertSelected, setConvertSelected] = useState(FormatTool.DEFAULT); + + const handleConvert = () => { + console.log(convertSelected); + const _formatFunc = formatFunc[convertSelected]; + try { + const _output = _formatFunc(fromValue); + console.log('🚀 ~ file: index.tsx:26 ~ handleConvert ~ _output:', _output); + setToValue(_output); + } catch (e) { + setToValue(JSON.stringify(e, null, 2)); + } + }; + + return ( +
+
+
+ {/*
+ copy +
*/} + value && setFromValue(value)} + defaultValue="" + /> +
+
+
+