Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/components/FolderTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
8 changes: 6 additions & 2 deletions src/pages/home/toolbar/CopyMove.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 14 additions & 12 deletions src/pages/home/toolbar/Decompress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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("")
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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(),
Expand Down
2 changes: 2 additions & 0 deletions src/pages/home/toolbar/RecursiveMove.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down