mirror of
https://github.com/ershisan99/DevToysWeb.git
synced 2025-12-17 04:59:23 +00:00
refactor: use Options instead of Errors
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback, useMemo, useState } from "react";
|
||||
import * as O from "fp-ts/lib/Option";
|
||||
import { constant } from "fp-ts/lib/function";
|
||||
|
||||
import { toolGroups } from "@/config/tools";
|
||||
import { safeDecodeURIComponent, safeEncodeURIComponent } from "@/lib/uri";
|
||||
import { Textarea, TextareaProps } from "@/components/ui/textarea";
|
||||
import { ClearButton } from "@/components/buttons/clear";
|
||||
import { CopyButton } from "@/components/buttons/copy";
|
||||
@@ -18,22 +21,12 @@ export default function Page() {
|
||||
|
||||
const setDecodedReactively = useCallback((text: string) => {
|
||||
setDecoded(text);
|
||||
|
||||
try {
|
||||
setEncoded(encodeURIComponent(text));
|
||||
} catch {
|
||||
setEncoded("");
|
||||
}
|
||||
setEncoded(O.getOrElse(constant(""))(safeEncodeURIComponent(text)));
|
||||
}, []);
|
||||
|
||||
const setEncodedReactively = useCallback((text: string) => {
|
||||
setEncoded(text);
|
||||
|
||||
try {
|
||||
setDecoded(decodeURIComponent(text));
|
||||
} catch {
|
||||
setDecoded("");
|
||||
}
|
||||
setDecoded(O.getOrElse(constant(""))(safeDecodeURIComponent(text)));
|
||||
}, []);
|
||||
|
||||
const clearBoth = useCallback(() => {
|
||||
|
||||
Reference in New Issue
Block a user