mirror of
https://github.com/ershisan99/DevToysWeb.git
synced 2025-12-17 12:32:56 +00:00
refactor: unify repeated tool definitions
This commit is contained in:
@@ -1,31 +1,19 @@
|
|||||||
import {
|
import { Home } from "@mui/icons-material";
|
||||||
Code,
|
|
||||||
DataObject,
|
|
||||||
DragHandle,
|
|
||||||
Filter,
|
|
||||||
Fingerprint,
|
|
||||||
Home,
|
|
||||||
Image as ImageIcon,
|
|
||||||
Key,
|
|
||||||
Link,
|
|
||||||
NoteAdd,
|
|
||||||
Numbers,
|
|
||||||
Sort,
|
|
||||||
SyncAlt,
|
|
||||||
TextFields,
|
|
||||||
TextIncrease,
|
|
||||||
Transform,
|
|
||||||
} from "@mui/icons-material";
|
|
||||||
import { Box, Divider, Drawer, List, Stack } from "@mui/material";
|
import { Box, Divider, Drawer, List, Stack } from "@mui/material";
|
||||||
import { css } from "@mui/material/styles";
|
import { css } from "@mui/material/styles";
|
||||||
import { memo } from "react";
|
import { ComponentPropsWithoutRef, memo } from "react";
|
||||||
|
|
||||||
|
import { drawerToolGroups } from "@/data/tools";
|
||||||
import { pagesPath } from "@/libs/$path";
|
import { pagesPath } from "@/libs/$path";
|
||||||
|
|
||||||
import DrawerCollapseItem from "./DrawerCollapseItem";
|
import DrawerCollapseItem from "./DrawerCollapseItem";
|
||||||
import DrawerItem from "./DrawerItem";
|
import DrawerItem from "./DrawerItem";
|
||||||
import SearchBar from "./SearchBar";
|
import SearchBar from "./SearchBar";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
toolGroups: ComponentPropsWithoutRef<typeof DrawerCollapseItem>[];
|
||||||
|
};
|
||||||
|
|
||||||
export const drawerWidth = 300;
|
export const drawerWidth = 300;
|
||||||
|
|
||||||
const drawer = css`
|
const drawer = css`
|
||||||
@@ -42,75 +30,7 @@ const divider = css`
|
|||||||
border-color: rgba(0, 0, 0, 0.08);
|
border-color: rgba(0, 0, 0, 0.08);
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const toolGroups = [
|
const StyledComponent = ({ toolGroups }: Props) => (
|
||||||
{
|
|
||||||
icon: <Transform />,
|
|
||||||
title: "Converters",
|
|
||||||
tools: [
|
|
||||||
{
|
|
||||||
icon: <Transform />,
|
|
||||||
title: "Json <> Yaml",
|
|
||||||
href: pagesPath.converters.json_yaml.$url(),
|
|
||||||
disabled: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: <Numbers />,
|
|
||||||
title: "Number Base",
|
|
||||||
href: pagesPath.converters.number_base.$url(),
|
|
||||||
disabled: false,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: <SyncAlt />,
|
|
||||||
title: "Encoders / Decoders",
|
|
||||||
tools: [
|
|
||||||
{
|
|
||||||
icon: <Code />,
|
|
||||||
title: "HTML",
|
|
||||||
href: pagesPath.encoders_decoders.html.$url(),
|
|
||||||
disabled: false,
|
|
||||||
},
|
|
||||||
{ icon: <Link />, title: "URL", href: pagesPath.$url(), disabled: true },
|
|
||||||
{ icon: <DragHandle />, title: "Base 64", href: pagesPath.$url(), disabled: true },
|
|
||||||
{ icon: <Key />, title: "JWT", href: pagesPath.$url(), disabled: true },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: <Sort />,
|
|
||||||
title: "Formatters",
|
|
||||||
tools: [{ icon: <DataObject />, title: "Json", href: pagesPath.$url(), disabled: true }],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: <NoteAdd />,
|
|
||||||
title: "Generators",
|
|
||||||
tools: [
|
|
||||||
{ icon: <Fingerprint />, title: "Hash", href: pagesPath.$url(), disabled: true },
|
|
||||||
{ icon: <Numbers />, title: "UUID", href: pagesPath.$url(), disabled: true },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: <TextFields />,
|
|
||||||
title: "Text",
|
|
||||||
tools: [
|
|
||||||
{ icon: <TextIncrease />, title: "Regex Tester", href: pagesPath.$url(), disabled: true },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: <ImageIcon />,
|
|
||||||
title: "Graphic",
|
|
||||||
tools: [
|
|
||||||
{
|
|
||||||
icon: <Filter />,
|
|
||||||
title: "PNG / JPEG Compressor",
|
|
||||||
href: pagesPath.$url(),
|
|
||||||
disabled: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const StyledComponent = () => (
|
|
||||||
<Drawer variant="permanent" css={drawer}>
|
<Drawer variant="permanent" css={drawer}>
|
||||||
<Box paddingLeft={2} paddingRight={2} marginTop="1px">
|
<Box paddingLeft={2} paddingRight={2} marginTop="1px">
|
||||||
<SearchBar />
|
<SearchBar />
|
||||||
@@ -131,4 +51,6 @@ const StyledComponent = () => (
|
|||||||
|
|
||||||
export const Component = memo(StyledComponent);
|
export const Component = memo(StyledComponent);
|
||||||
|
|
||||||
export default Component;
|
const Container = () => <Component toolGroups={drawerToolGroups} />;
|
||||||
|
|
||||||
|
export default Container;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { ComponentPropsWithoutRef, memo } from "react";
|
import { ComponentPropsWithoutRef, memo } from "react";
|
||||||
|
|
||||||
import { Main, ToolCardGrid } from "@/components/common";
|
import { Main, ToolCardGrid } from "@/components/common";
|
||||||
import { allTools } from "@/data/tools";
|
import { homeTools } from "@/data/tools";
|
||||||
|
|
||||||
type Props = ComponentPropsWithoutRef<typeof ToolCardGrid>;
|
type Props = ComponentPropsWithoutRef<typeof ToolCardGrid>;
|
||||||
|
|
||||||
@@ -13,6 +13,6 @@ const StyledComponent = ({ tools }: Props) => (
|
|||||||
|
|
||||||
export const Component = memo(StyledComponent);
|
export const Component = memo(StyledComponent);
|
||||||
|
|
||||||
const Container = () => <Component tools={allTools} />;
|
const Container = () => <Component tools={homeTools} />;
|
||||||
|
|
||||||
export default Container;
|
export default Container;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { selector, useRecoilValue } from "recoil";
|
|||||||
|
|
||||||
import { Main, ToolCardGrid } from "@/components/common";
|
import { Main, ToolCardGrid } from "@/components/common";
|
||||||
import { searchTextState } from "@/components/layout/states";
|
import { searchTextState } from "@/components/layout/states";
|
||||||
import { allTools } from "@/data/tools";
|
import { homeTools } from "@/data/tools";
|
||||||
|
|
||||||
type Props = ComponentPropsWithoutRef<typeof ToolCardGrid>;
|
type Props = ComponentPropsWithoutRef<typeof ToolCardGrid>;
|
||||||
|
|
||||||
@@ -23,12 +23,12 @@ const filteredToolsState = selector({
|
|||||||
const searchText = get(searchTextState).trim();
|
const searchText = get(searchTextState).trim();
|
||||||
|
|
||||||
if (searchText === "") {
|
if (searchText === "") {
|
||||||
return { filteredTools: allTools };
|
return { filteredTools: homeTools };
|
||||||
}
|
}
|
||||||
|
|
||||||
const searchWords = searchText.split(" ").map(word => ({ keywords: word }));
|
const searchWords = searchText.split(" ").map(word => ({ keywords: word }));
|
||||||
|
|
||||||
const fuse = new Fuse(allTools, { keys: ["keywords"], threshold: 0.5 });
|
const fuse = new Fuse(homeTools, { keys: ["keywords"], threshold: 0.5 });
|
||||||
const result = fuse.search({ $and: searchWords });
|
const result = fuse.search({ $and: searchWords });
|
||||||
const filteredTools = result.map(({ item }) => item);
|
const filteredTools = result.map(({ item }) => item);
|
||||||
|
|
||||||
|
|||||||
@@ -4,19 +4,29 @@ import {
|
|||||||
DragHandle,
|
DragHandle,
|
||||||
Filter,
|
Filter,
|
||||||
Fingerprint,
|
Fingerprint,
|
||||||
|
Image as ImageIcon,
|
||||||
Key,
|
Key,
|
||||||
Link,
|
Link,
|
||||||
|
NoteAdd,
|
||||||
Numbers,
|
Numbers,
|
||||||
|
Sort,
|
||||||
|
SyncAlt,
|
||||||
|
TextFields,
|
||||||
TextIncrease,
|
TextIncrease,
|
||||||
Transform,
|
Transform,
|
||||||
} from "@mui/icons-material";
|
} from "@mui/icons-material";
|
||||||
|
|
||||||
import { pagesPath } from "@/libs/$path";
|
import { pagesPath } from "@/libs/$path";
|
||||||
|
|
||||||
export const allTools = [
|
const toolGroups = [
|
||||||
{
|
{
|
||||||
icon: <Transform />,
|
icon: <Transform />,
|
||||||
title: "Json <> Yaml Converter",
|
title: "Converters",
|
||||||
|
tools: [
|
||||||
|
{
|
||||||
|
icon: <Transform />,
|
||||||
|
shortTitle: "Json <> Yaml",
|
||||||
|
longTitle: "Json <> Yaml Converter",
|
||||||
description: "Convert Json data to Yaml and vice versa",
|
description: "Convert Json data to Yaml and vice versa",
|
||||||
keywords: "json yaml converter",
|
keywords: "json yaml converter",
|
||||||
href: pagesPath.converters.json_yaml.$url(),
|
href: pagesPath.converters.json_yaml.$url(),
|
||||||
@@ -24,15 +34,23 @@ export const allTools = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: <Numbers />,
|
icon: <Numbers />,
|
||||||
title: "Number Base Converter",
|
shortTitle: "Number Base",
|
||||||
|
longTitle: "Number Base Converter",
|
||||||
description: "Convert numbers from one base to another",
|
description: "Convert numbers from one base to another",
|
||||||
keywords: "number base converter",
|
keywords: "number base converter",
|
||||||
href: pagesPath.converters.number_base.$url(),
|
href: pagesPath.converters.number_base.$url(),
|
||||||
disabled: false,
|
disabled: false,
|
||||||
},
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: <SyncAlt />,
|
||||||
|
title: "Encoders / Decoders",
|
||||||
|
tools: [
|
||||||
{
|
{
|
||||||
icon: <Code />,
|
icon: <Code />,
|
||||||
title: "HTML Encoder / Decoder",
|
shortTitle: "HTML",
|
||||||
|
longTitle: "HTML Encoder / Decoder",
|
||||||
description:
|
description:
|
||||||
"Encode or decode all the applicable characters to their corresponding HTML entities",
|
"Encode or decode all the applicable characters to their corresponding HTML entities",
|
||||||
keywords: "html encoder escaper decocder unescaper",
|
keywords: "html encoder escaper decocder unescaper",
|
||||||
@@ -41,7 +59,8 @@ export const allTools = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: <Link />,
|
icon: <Link />,
|
||||||
title: "URL Encoder / Decoder",
|
shortTitle: "URL",
|
||||||
|
longTitle: "URL Encoder / Decoder",
|
||||||
description:
|
description:
|
||||||
"Encode or decode all the applicable characters to their corresponding URL entities",
|
"Encode or decode all the applicable characters to their corresponding URL entities",
|
||||||
keywords: "url encoder escaper decocder unescaper",
|
keywords: "url encoder escaper decocder unescaper",
|
||||||
@@ -50,7 +69,8 @@ export const allTools = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: <DragHandle />,
|
icon: <DragHandle />,
|
||||||
title: "Base 64 Encoder / Decoder",
|
shortTitle: "Base 64",
|
||||||
|
longTitle: "Base 64 Encoder / Decoder",
|
||||||
description: "Encode and decode Base64 data",
|
description: "Encode and decode Base64 data",
|
||||||
keywords: "base64 encoder decocder",
|
keywords: "base64 encoder decocder",
|
||||||
href: pagesPath.$url(),
|
href: pagesPath.$url(),
|
||||||
@@ -58,23 +78,38 @@ export const allTools = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: <Key />,
|
icon: <Key />,
|
||||||
title: "JWT Decoder",
|
shortTitle: "JWT",
|
||||||
|
longTitle: "JWT Decoder",
|
||||||
description: "Decode a JWT header, payload and signature",
|
description: "Decode a JWT header, payload and signature",
|
||||||
keywords: "jwt json web token decocder",
|
keywords: "jwt json web token decocder",
|
||||||
href: pagesPath.$url(),
|
href: pagesPath.$url(),
|
||||||
disabled: true,
|
disabled: true,
|
||||||
},
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: <Sort />,
|
||||||
|
title: "Formatters",
|
||||||
|
tools: [
|
||||||
{
|
{
|
||||||
icon: <DataObject />,
|
icon: <DataObject />,
|
||||||
title: "JSON Formatter",
|
shortTitle: "Json",
|
||||||
|
longTitle: "JSON Formatter",
|
||||||
description: "Indent or minify JSON data",
|
description: "Indent or minify JSON data",
|
||||||
keywords: "json formatter",
|
keywords: "json formatter",
|
||||||
href: pagesPath.$url(),
|
href: pagesPath.$url(),
|
||||||
disabled: true,
|
disabled: true,
|
||||||
},
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: <NoteAdd />,
|
||||||
|
title: "Generators",
|
||||||
|
tools: [
|
||||||
{
|
{
|
||||||
icon: <Fingerprint />,
|
icon: <Fingerprint />,
|
||||||
title: "Hash Generator",
|
shortTitle: "Hash",
|
||||||
|
longTitle: "Hash Generator",
|
||||||
description: "Calculate MD5, SHA1, SHA256 and SHA512 hash from text data",
|
description: "Calculate MD5, SHA1, SHA256 and SHA512 hash from text data",
|
||||||
keywords: "hash generator md5 sha1 sha256 sha512",
|
keywords: "hash generator md5 sha1 sha256 sha512",
|
||||||
href: pagesPath.$url(),
|
href: pagesPath.$url(),
|
||||||
@@ -82,26 +117,61 @@ export const allTools = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: <Numbers />,
|
icon: <Numbers />,
|
||||||
title: "UUID Generator",
|
shortTitle: "UUID",
|
||||||
|
longTitle: "UUID Generator",
|
||||||
description: "Generate UUIDs version 1 and 4",
|
description: "Generate UUIDs version 1 and 4",
|
||||||
keywords: "guid uuid1 uuid4 generator",
|
keywords: "guid uuid1 uuid4 generator",
|
||||||
href: pagesPath.$url(),
|
href: pagesPath.$url(),
|
||||||
disabled: true,
|
disabled: true,
|
||||||
},
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: <TextFields />,
|
||||||
|
title: "Text",
|
||||||
|
tools: [
|
||||||
{
|
{
|
||||||
icon: <TextIncrease />,
|
icon: <TextIncrease />,
|
||||||
title: "Regex Tester",
|
shortTitle: "Regex Tester",
|
||||||
|
longTitle: "Regex Tester",
|
||||||
description: "Validate and test regular expressions",
|
description: "Validate and test regular expressions",
|
||||||
keywords: "regular expression regex validator tester",
|
keywords: "regular expression regex validator tester",
|
||||||
href: pagesPath.$url(),
|
href: pagesPath.$url(),
|
||||||
disabled: true,
|
disabled: true,
|
||||||
},
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: <ImageIcon />,
|
||||||
|
title: "Graphic",
|
||||||
|
tools: [
|
||||||
{
|
{
|
||||||
icon: <Filter />,
|
icon: <Filter />,
|
||||||
title: "PNG / JPEG Compressor",
|
shortTitle: "PNG / JPEG Compressor",
|
||||||
|
longTitle: "PNG / JPEG Compressor",
|
||||||
description: "Lossless PNG and JPEG optimizer",
|
description: "Lossless PNG and JPEG optimizer",
|
||||||
keywords: "png jpeg compressor optimizer image",
|
keywords: "png jpeg compressor optimizer image",
|
||||||
href: pagesPath.$url(),
|
href: pagesPath.$url(),
|
||||||
disabled: true,
|
disabled: true,
|
||||||
},
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export const homeTools = toolGroups.flatMap(({ tools }) =>
|
||||||
|
tools.map(({ shortTitle: _, longTitle, ...rest }) => ({
|
||||||
|
...rest,
|
||||||
|
title: longTitle,
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
|
export const drawerToolGroups = toolGroups.map(({ tools, ...rest }) => ({
|
||||||
|
...rest,
|
||||||
|
tools: tools.map(({ icon, shortTitle, description, href, disabled }) => ({
|
||||||
|
icon,
|
||||||
|
title: shortTitle,
|
||||||
|
description,
|
||||||
|
href,
|
||||||
|
disabled,
|
||||||
|
})),
|
||||||
|
}));
|
||||||
|
|||||||
Reference in New Issue
Block a user