Skip to content

Commit da3a053

Browse files
committed
update ui
1 parent 9c09465 commit da3a053

7 files changed

Lines changed: 139 additions & 94 deletions

File tree

src/components/AppLayout/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ const AppLayout: React.FC<PropsWithChildren> = ({ children }) => {
8484
</Col>
8585
</Row>
8686
</Header> */}
87-
<Content className="bg-slate-300 p-2 text-start">
88-
<div className="h-full flex-1 justify-start overflow-auto rounded-xl bg-white p-3 shadow-xl ">
87+
<Content className="bg-slate-300 p-1 text-start">
88+
<div className="h-full flex-1 justify-start overflow-auto rounded-xl bg-white p-1 shadow-xl ">
8989
{children}
9090
</div>
9191
</Content>

src/modules/tools/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import ToolsLayout from './components/ToolsLayout';
22
import { RandomPasswordTool } from './tools';
3-
import ConvertTool from './tools/Convert';
43

54
import { RouteObject } from 'react-router-dom';
5+
import RemoveLines from './tools/remove-lines';
66

77
const ToolsModule: RouteObject = {
88
path: 'tools',
@@ -12,9 +12,10 @@ const ToolsModule: RouteObject = {
1212
path: 'random-password-tool',
1313
element: <RandomPasswordTool />,
1414
},
15+
1516
{
16-
path: 'convert-tool',
17-
element: <ConvertTool />,
17+
path: 'Convert',
18+
element: <RemoveLines />,
1819
},
1920
],
2021
};

src/modules/tools/tools/Convert/index.tsx

Lines changed: 0 additions & 88 deletions
This file was deleted.

src/modules/tools/tools/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export * from './RandomPasswordTool';
2-
export * from './Convert';
2+
export * from "./remove-lines"
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { getUniqueCharacters, removeDuplicatedLines, sortLines } from './text';
2+
3+
export enum FormatTool {
4+
DEFAULT = 'Default',
5+
REMOVE_DUMPLICATE_LINE = 'remove dumplicate line',
6+
SORT_LINE = 'Sort line',
7+
GET_CHAR = 'Get char',
8+
}
9+
10+
export const formatFunc = {
11+
[FormatTool.DEFAULT]: (text: string) => text,
12+
[FormatTool.REMOVE_DUMPLICATE_LINE]: removeDuplicatedLines,
13+
[FormatTool.SORT_LINE]: sortLines,
14+
[FormatTool.GET_CHAR]: getUniqueCharacters,
15+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as _ from 'lodash';
2+
3+
const getLines = (text: string): string[] => {
4+
const lines = _.split(text, /\r?\n/);
5+
return lines;
6+
};
7+
8+
export function removeDuplicatedLines(text: string): string {
9+
const lines = getLines(text);
10+
const uniqueLines = _.uniq(lines);
11+
return uniqueLines.join('\n');
12+
}
13+
14+
export function sortLines(text: string): string {
15+
const lines = _.split(text, /\r?\n/);
16+
const sortedLines = _.sortBy(lines);
17+
return sortedLines.join('\n');
18+
}
19+
20+
export function getUniqueCharacters(text: string): string {
21+
const uniqueChars = new Set(text.split(/\s+|\r\n|\r|\n/));
22+
const sortedUniqueChars = Array.from(uniqueChars).sort();
23+
return sortedUniqueChars.join('\n');
24+
}

0 commit comments

Comments
 (0)