Skip to content

Commit

Permalink
feat(recursive-move): add overwrite option to preventing unintentio…
Browse files Browse the repository at this point in the history
…nal overwriting (#240)
  • Loading branch information
Lanfei authored Jan 27, 2025
1 parent 656ff95 commit 79c37f7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/pages/home/toolbar/RecursiveMove.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
Button,
Checkbox,
Modal,
ModalBody,
ModalContent,
Expand All @@ -11,7 +12,7 @@ import {
import { ModalFolderChoose } from "~/components"
import { useFetch, usePath, useRouter, useT } from "~/hooks"
import { bus, fsRecursiveMove, handleRespWithNotifySuccess } from "~/utils"
import { onCleanup } from "solid-js"
import { createSignal, onCleanup } from "solid-js"

export const RecursiveMove = () => {
const {
Expand All @@ -23,6 +24,7 @@ export const RecursiveMove = () => {
const [loading, ok] = useFetch(fsRecursiveMove)
const { pathname } = useRouter()
const { refresh } = usePath()
const [overwrite, setOverwrite] = createSignal(false)
const handler = (name: string) => {
if (name === "recursiveMove") {
openConfirmModal()
Expand Down Expand Up @@ -72,8 +74,19 @@ export const RecursiveMove = () => {
opened={isOpen()}
onClose={onClose}
loading={loading()}
footerSlot={
<Checkbox
mr="auto"
checked={overwrite()}
onChange={() => {
setOverwrite(!overwrite())
}}
>
{t("home.overwrite_existing")}
</Checkbox>
}
onSubmit={async (dst) => {
const resp = await ok(pathname(), dst)
const resp = await ok(pathname(), dst, overwrite())
handleRespWithNotifySuccess(resp, () => {
refresh()
onClose()
Expand Down
3 changes: 2 additions & 1 deletion src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ export const fsMove = (
export const fsRecursiveMove = (
src_dir: string,
dst_dir: string,
overwrite: boolean,
): PEmptyResp => {
return r.post("/fs/recursive_move", { src_dir, dst_dir })
return r.post("/fs/recursive_move", { src_dir, dst_dir, overwrite })
}

export const fsCopy = (
Expand Down

0 comments on commit 79c37f7

Please sign in to comment.