feat(archive): auto-locate destination to current path (#327)

This commit is contained in:
KirCute
2025-12-15 21:27:19 +08:00
committed by GitHub
parent 6ed0446500
commit 4cd2e17ff6
4 changed files with 31 additions and 16 deletions

View File

@@ -340,7 +340,7 @@ export type ModalFolderChooseProps = {
onClose: () => void
onSubmit?: (text: string) => void
type?: string
defaultValue?: string
defaultValue?: string | (() => string)
loading?: boolean
footerSlot?: JSXElement
headerSlot?: (handler: FolderTreeHandler | undefined) => JSXElement
@@ -349,12 +349,19 @@ export type ModalFolderChooseProps = {
}
export const ModalFolderChoose = (props: ModalFolderChooseProps) => {
const t = useT()
const [value, setValue] = createSignal(props.defaultValue ?? "/")
const [value, setValue] = createSignal("/")
const [handler, setHandler] = createSignal<FolderTreeHandler>()
createEffect(() => {
if (!props.opened) return
handler()?.setPath(value())
})
if (typeof props.defaultValue === "function") {
createEffect(() => {
setValue((props.defaultValue as () => string)())
})
} else if (typeof props.defaultValue === "string") {
setValue(props.defaultValue)
}
return (
<Modal
size="xl"

View File

@@ -2,11 +2,15 @@ import { Checkbox, createDisclosure, VStack, Button } from "@hope-ui/solid"
import { createSignal, onCleanup } from "solid-js"
import { ModalFolderChoose, FolderTreeHandler } from "~/components"
import { useFetch, usePath, useRouter, useT } from "~/hooks"
import { selectedObjs } from "~/store"
import { me, selectedObjs } from "~/store"
import { bus, fsCopy, fsMove, handleRespWithNotifySuccess } from "~/utils"
import { CgFolderAdd } from "solid-icons/cg"
import { UserMethods, UserPermissions } from "~/types"
const CreateFolderButton = (props: { handler?: FolderTreeHandler }) => {
export const CreateFolderButton = (props: { handler?: FolderTreeHandler }) => {
if (!UserMethods.can(me(), UserPermissions.indexOf("write"))) {
return null
}
const t = useT()
return (
<Button

View File

@@ -11,6 +11,7 @@ import { bus, fsArchiveDecompress, handleRespWithNotifySuccess } from "~/utils"
import { batch, createSignal, onCleanup } from "solid-js"
import { ModalFolderChoose } from "~/components"
import { selectedObjs } from "~/store"
import { CreateFolderButton } from "./CopyMove"
export const Decompress = () => {
const t = useT()
@@ -23,9 +24,14 @@ export const Decompress = () => {
const [cacheFull, setCacheFull] = createSignal(true)
const [putIntoNewDir, setPutIntoNewDir] = createSignal(false)
const [overwrite, setOverwrite] = createSignal(false)
const [srcPath, setSrcPath] = createSignal("")
const [srcName, setSrcName] = createSignal<string[]>()
const handler = (name: string) => {
if (name === "decompress") {
const path = pathname()
batch(() => {
setSrcPath(path)
setSrcName(selectedObjs().map((o) => o.name))
setCacheFull(true)
setInnerPath("/")
setArchivePass("")
@@ -35,7 +41,11 @@ export const Decompress = () => {
}
const extractHandler = (args: string) => {
const { inner, pass } = JSON.parse(args)
const path = pathname()
const idx = path.lastIndexOf("/")
batch(() => {
setSrcPath(path.slice(0, idx))
setSrcName([path.slice(idx + 1)])
setCacheFull(false)
setInnerPath(inner)
setArchivePass(pass)
@@ -54,21 +64,14 @@ export const Decompress = () => {
}
return t("home.toolbar.archive.extract_header", { path: innerPath() })
}
const getPathAndName = () => {
let path = pathname()
if (innerPath() === "/") {
return { path: path, name: selectedObjs().map((o) => o.name) }
} else {
let idx = path.lastIndexOf("/")
return { path: path.slice(0, idx), name: [path.slice(idx + 1)] }
}
}
return (
<ModalFolderChoose
header={header()}
opened={isOpen()}
onClose={onClose}
loading={loading()}
defaultValue={srcPath}
headerSlot={(handler) => <CreateFolderButton handler={handler} />}
footerSlot={
<VStack w="$full" spacing="$2">
<Checkbox
@@ -81,11 +84,10 @@ export const Decompress = () => {
</VStack>
}
onSubmit={async (dst) => {
const { path, name } = getPathAndName()
const resp = await ok(
path,
srcPath(),
dst,
name,
srcName(),
archivePass(),
innerPath(),
cacheFull(),

View File

@@ -15,6 +15,7 @@ import { ModalFolderChoose } from "~/components"
import { useFetch, usePath, useRouter, useT } from "~/hooks"
import { bus, fsRecursiveMove, handleRespWithNotifySuccess } from "~/utils"
import { createSignal, onCleanup } from "solid-js"
import { CreateFolderButton } from "./CopyMove"
export const RecursiveMove = () => {
const {
@@ -77,6 +78,7 @@ export const RecursiveMove = () => {
opened={isOpen()}
onClose={onClose}
loading={loading()}
headerSlot={(handler) => <CreateFolderButton handler={handler} />}
footerSlot={
<HStack mr="auto" flex="0.8" spacing="$1">
<SimpleSelect