generated from xhofe/solid-lib
-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: empty folder clear, recursive move, regular rename (#78)
* 页面增加递归移动和正则重命名按钮 * 正则重命名操作样式变更 * 增加清理空文件夹按钮 * 正则重命名文件添加提示语 * 技术债 * chore: change ui * fix codefactor --------- Co-authored-by: Andy Hsu <[email protected]>
- Loading branch information
Showing
10 changed files
with
326 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { | ||
Modal, | ||
ModalOverlay, | ||
ModalContent, | ||
ModalHeader, | ||
ModalBody, | ||
ModalFooter, | ||
Button, | ||
Input, | ||
Textarea, | ||
FormHelperText, | ||
VStack, | ||
} from "@hope-ui/solid" | ||
import { createSignal, JSXElement, Show } from "solid-js" | ||
import { useT } from "~/hooks" | ||
import { notify } from "~/utils" | ||
export type ModalTwoInputProps = { | ||
opened: boolean | ||
onClose: () => void | ||
title: string | ||
onSubmit?: (text1: string, text2: string) => void // Update onSubmit to accept two input texts | ||
type?: string | ||
defaultValue1?: string // Update defaultValue to defaultValue1 | ||
defaultValue2?: string // Add defaultValue2 for second input | ||
loading?: boolean | ||
tips?: string | ||
topSlot?: JSXElement | ||
} | ||
export const ModalTwoInput = (props: ModalTwoInputProps) => { | ||
const [value1, setValue1] = createSignal(props.defaultValue1 ?? "") // Update value and setValue to value1 and setValue1 | ||
const [value2, setValue2] = createSignal(props.defaultValue2 ?? "") // Add value2 and setValue2 for second input | ||
const t = useT() | ||
const submit = () => { | ||
if (!value1() || !value2()) { | ||
// Check if both input values are not empty | ||
notify.warning(t("global.empty_input")) | ||
return | ||
} | ||
props.onSubmit?.(value1(), value2()) // Update onSubmit to pass both input values | ||
setValue1("") | ||
setValue2("") | ||
} | ||
return ( | ||
<Modal | ||
blockScrollOnMount={false} | ||
opened={props.opened} | ||
onClose={props.onClose} | ||
initialFocus="#modal-input1" | ||
> | ||
<ModalOverlay /> | ||
<ModalContent> | ||
{/* <ModalCloseButton /> */} | ||
<ModalHeader>{t(props.title)}</ModalHeader> | ||
<ModalBody> | ||
<Show when={props.topSlot}>{props.topSlot}</Show> | ||
<Show | ||
when={props.type === "text"} | ||
fallback={ | ||
<VStack spacing="$2"> | ||
<Input | ||
id="modal-input1" // Update id to "modal-input1" for first input | ||
type={props.type} | ||
value={value1()} // Update value to value1 for first input | ||
onInput={(e) => { | ||
setValue1(e.currentTarget.value) | ||
}} | ||
onKeyDown={(e) => { | ||
if (e.key === "Enter") { | ||
submit() | ||
} | ||
}} | ||
/> | ||
<Input | ||
id="modal-input2" // Add second input with id "modal-input2" | ||
type={props.type} | ||
value={value2()} // Bind value to value2 for second input | ||
onInput={(e) => { | ||
setValue2(e.currentTarget.value) | ||
}} | ||
onKeyDown={(e) => { | ||
if (e.key === "Enter") { | ||
submit() | ||
} | ||
}} | ||
/> | ||
</VStack> | ||
} | ||
> | ||
<div> | ||
<Textarea | ||
id="modal-input1" // Update id to "modal-input1" for first input | ||
value={value1()} // Update value to value1 for first input | ||
onInput={(e) => { | ||
setValue1(e.currentTarget.value) | ||
}} | ||
/> | ||
<Textarea | ||
id="modal-input2" // Add second input with id "modal-input2" | ||
value={value2()} // Bind value to value2 for second input | ||
onInput={(e) => { | ||
setValue2(e.currentTarget.value) | ||
}} | ||
/> | ||
</div> | ||
</Show> | ||
<Show when={props.tips}> | ||
<FormHelperText>{props.tips}</FormHelperText> | ||
</Show> | ||
</ModalBody> | ||
<ModalFooter display="flex" gap="$2"> | ||
<Button onClick={props.onClose} colorScheme="neutral"> | ||
{t("global.cancel")} | ||
</Button> | ||
<Button | ||
loading={props.loading} | ||
onClick={() => submit()} | ||
disabled={!value1() || !value2()} | ||
> | ||
{t("global.ok")} | ||
</Button> | ||
</ModalFooter> | ||
</ModalContent> | ||
</Modal> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { createDisclosure } from "@hope-ui/solid" | ||
import { ModalFolderChoose } from "~/components" | ||
import { useFetch, usePath, useRouter } from "~/hooks" | ||
import { bus, fsRecursiveMove, handleRespWithNotifySuccess } from "~/utils" | ||
import { onCleanup } from "solid-js" | ||
|
||
export const RecursiveMove = () => { | ||
const { isOpen, onOpen, onClose } = createDisclosure() | ||
const [loading, ok] = useFetch(fsRecursiveMove) | ||
const { pathname } = useRouter() | ||
const { refresh } = usePath() | ||
const handler = (name: string) => { | ||
if (name === "recursiveMove") { | ||
onOpen() | ||
} | ||
} | ||
bus.on("tool", handler) | ||
onCleanup(() => { | ||
bus.off("tool", handler) | ||
}) | ||
return ( | ||
<ModalFolderChoose | ||
opened={isOpen()} | ||
onClose={onClose} | ||
loading={loading()} | ||
onSubmit={async (dst) => { | ||
const resp = await ok(pathname(), dst) | ||
handleRespWithNotifySuccess(resp, () => { | ||
refresh() | ||
onClose() | ||
}) | ||
}} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { createDisclosure } from "@hope-ui/solid" | ||
import { ModalTwoInput } from "~/components" | ||
import { useFetch, usePath, useRouter } from "~/hooks" | ||
import { bus, fsRegexRename, handleRespWithNotifySuccess } from "~/utils" | ||
import { onCleanup } from "solid-js" | ||
|
||
export const RegexRename = () => { | ||
const { isOpen, onOpen, onClose } = createDisclosure() | ||
const [loading, ok] = useFetch(fsRegexRename) | ||
const { pathname } = useRouter() | ||
const { refresh } = usePath() | ||
const handler = (name: string) => { | ||
if (name === "regexRename") { | ||
onOpen() | ||
} | ||
} | ||
bus.on("tool", handler) | ||
onCleanup(() => { | ||
bus.off("tool", handler) | ||
}) | ||
return ( | ||
<ModalTwoInput | ||
title="home.toolbar.regular_rename" | ||
opened={isOpen()} | ||
onClose={onClose} | ||
loading={loading()} | ||
onSubmit={async (srcName, newName) => { | ||
const resp = await ok(pathname(), srcName, newName) | ||
handleRespWithNotifySuccess(resp, () => { | ||
refresh() | ||
onClose() | ||
}) | ||
}} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { | ||
Button, | ||
Modal, | ||
ModalBody, | ||
ModalContent, | ||
ModalFooter, | ||
ModalHeader, | ||
ModalOverlay, | ||
createDisclosure, | ||
} from "@hope-ui/solid" | ||
import { useFetch, usePath, useRouter, useT } from "~/hooks" | ||
import { | ||
bus, | ||
fsRemoveEmptyDirectory, | ||
handleRespWithNotifySuccess, | ||
} from "~/utils" | ||
import { onCleanup } from "solid-js" | ||
|
||
export const RemoveEmptyDirectory = () => { | ||
const { isOpen, onOpen, onClose } = createDisclosure() | ||
const { pathname } = useRouter() | ||
const [loading, ok] = useFetch(fsRemoveEmptyDirectory) | ||
const { refresh } = usePath() | ||
const handler = (name: string) => { | ||
if (name === "removeEmptyDirectory") { | ||
onOpen() | ||
} | ||
} | ||
bus.on("tool", handler) | ||
onCleanup(() => { | ||
bus.off("tool", handler) | ||
}) | ||
const t = useT() | ||
return ( | ||
<Modal | ||
blockScrollOnMount={false} | ||
opened={isOpen()} | ||
onClose={onClose} | ||
size={{ | ||
"@initial": "xs", | ||
"@md": "md", | ||
}} | ||
> | ||
<ModalOverlay /> | ||
<ModalContent> | ||
<ModalHeader>{t("home.toolbar.remove_empty_directory")}</ModalHeader> | ||
<ModalBody> | ||
<p>{t("home.toolbar.remove_empty_directory-tips")}</p> | ||
</ModalBody> | ||
<ModalFooter display="flex" gap="$2"> | ||
<Button onClick={onClose} colorScheme="neutral"> | ||
{t("global.cancel")} | ||
</Button> | ||
<Button | ||
colorScheme="danger" | ||
loading={loading()} | ||
onClick={async () => { | ||
const resp = await ok(pathname()) | ||
handleRespWithNotifySuccess(resp, () => { | ||
refresh() | ||
onClose() | ||
}) | ||
}} | ||
> | ||
{t("global.confirm")} | ||
</Button> | ||
</ModalFooter> | ||
</ModalContent> | ||
</Modal> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters