Skip to content

Commit

Permalink
feat(web): disabled upload button when fileList is empty (#589)
Browse files Browse the repository at this point in the history
  • Loading branch information
kongwy229 authored Dec 28, 2022
1 parent 7795fb1 commit 5de333c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
5 changes: 3 additions & 2 deletions web/src/pages/app/storages/mods/CreateFolderModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@ import {
} from "@chakra-ui/react";
import { t } from "i18next";

import useStorageStore, { TFile } from "../../store";
import useStorageStore from "../../store";

function CreateModal() {
const { isOpen, onOpen, onClose } = useDisclosure();
const { prefix, setPrefix } = useStorageStore();
const { prefix, setPrefix, currentStorage } = useStorageStore();

const { register, setFocus, handleSubmit } = useForm<{ prefix: string }>();

return (
<>
<Button
size="xs"
disabled={currentStorage === undefined}
onClick={() => {
onOpen();
setTimeout(() => {
Expand Down
2 changes: 2 additions & 0 deletions web/src/pages/app/storages/mods/StorageListPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export default function StorageListPanel() {
onSuccess(data) {
if (data?.data?.items?.length) {
if (!store.currentStorage) store.setCurrentStorage(data?.data?.items[0]);
} else {
store.setCurrentStorage(undefined);
}
},
});
Expand Down
7 changes: 6 additions & 1 deletion web/src/pages/app/storages/mods/UploadButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ function UploadButton({ onUploadSuccess }: { onUploadSuccess: () => void }) {
return (
<div>
<Menu placement="bottom-start">
<MenuButton size="xs" as={Button} rightIcon={<ChevronDownIcon />}>
<MenuButton
size="xs"
as={Button}
rightIcon={<ChevronDownIcon />}
disabled={currentStorage === undefined}
>
上传
</MenuButton>
<MenuList>
Expand Down
4 changes: 2 additions & 2 deletions web/src/pages/app/storages/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export type TFile = {
};

type State = {
currentStorage?: TBucket;
setCurrentStorage: (currentStorage: TBucket) => void;
currentStorage?: TBucket | undefined;
setCurrentStorage: (currentStorage: TBucket | undefined) => void;
prefix?: string;
setPrefix: (prefix: string) => void;
};
Expand Down

0 comments on commit 5de333c

Please sign in to comment.