Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web): add link copy in oss page #1108

Merged
merged 1 commit into from
May 6, 2023
Merged
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
5 changes: 3 additions & 2 deletions web/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -415,5 +415,6 @@
"item3_2": "Forum"
}
},
"ChatGPT example": "ChatGPT example"
}
"ChatGPT example": "ChatGPT example",
"LinkCopied": "Link Copied"
}
3 changes: 2 additions & 1 deletion web/public/locales/zh-CN/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -415,5 +415,6 @@
"item3_2": "开发者社区"
}
},
"ChatGPT example": "ChatGPT 示例"
"ChatGPT example": "ChatGPT 示例",
"LinkCopied": "链接复制成功"
}
3 changes: 2 additions & 1 deletion web/public/locales/zh/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -415,5 +415,6 @@
"item3_2": "开发者社区"
}
},
"ChatGPT example": "ChatGPT 示例"
"ChatGPT example": "ChatGPT 示例",
"LinkCopied": "链接复制成功"
}
53 changes: 30 additions & 23 deletions web/src/pages/app/storages/mods/FileList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BiCloudUpload, BiRefresh } from "react-icons/bi";
import { DeleteIcon, ViewIcon } from "@chakra-ui/icons";
import { DeleteIcon, LinkIcon, ViewIcon } from "@chakra-ui/icons";
import {
Button,
Center,
Expand All @@ -19,8 +19,8 @@ import clsx from "clsx";
import { t } from "i18next";

import ConfirmButton from "@/components/ConfirmButton";
import CopyText from "@/components/CopyText";
import EmptyBox from "@/components/EmptyBox";
// import CopyText from "@/components/CopyText";
import FileTypeIcon from "@/components/FileTypeIcon";
import IconWrap from "@/components/IconWrap";
import Panel from "@/components/Panel";
Expand All @@ -30,11 +30,9 @@ import { formatDate, formateType, formatSize } from "@/utils/format";
import useStorageStore, { TFile } from "../../store";
import CreateFolderModal from "../CreateFolderModal";
import CreateWebsiteModal from "../CreateWebsiteModal";
// import CreateWebsiteModal from "../CreateWebsiteModal";
import PathLink from "../PathLink";
import UploadButton from "../UploadButton";

// import styles from "../index.module.scss";
import useAwsS3 from "@/hooks/useAwsS3";
export default function FileList() {
const { getList, getFileUrl, deleteFile } = useAwsS3();
Expand All @@ -53,21 +51,23 @@ export default function FileList() {
},
);

const viewAppFile = (file: TFile) => {
if (file.Prefix) {
changeDirectory(file);
return;
}

const getLinkUrl = (file: TFile) => {
let fileUrl = "";

if (bucketType === "private") {
fileUrl = getFileUrl(bucketName!, file.Key);
} else {
fileUrl = getOrigin(currentStorage?.domain?.domain || "") + `/${file.Key}` || "";
}

window.open(fileUrl, "_blank");
return fileUrl;
};

const viewAppFile = (file: TFile) => {
if (file.Prefix) {
changeDirectory(file);
return;
}
window.open(getLinkUrl(file), "_blank");
};

const changeDirectory = (file: TFile) => {
Expand Down Expand Up @@ -213,18 +213,25 @@ export default function FileList() {
<ViewIcon fontSize={12} />
</IconWrap>
{!file.Prefix ? (
<ConfirmButton
onSuccessAction={async () => {
await deleteFile(bucketName!, file.Key);
query.refetch();
}}
headerText={String(t("Delete"))}
bodyText={t("StoragePanel.DeleteFileTip")}
>
<IconWrap tooltip={String(t("Delete"))}>
<DeleteIcon fontSize={14} />
<>
<IconWrap>
<CopyText text={getLinkUrl(file)} tip={String(t("LinkCopied"))}>
<LinkIcon />
</CopyText>
</IconWrap>
</ConfirmButton>
<ConfirmButton
onSuccessAction={async () => {
await deleteFile(bucketName!, file.Key);
query.refetch();
}}
headerText={String(t("Delete"))}
bodyText={t("StoragePanel.DeleteFileTip")}
>
<IconWrap tooltip={String(t("Delete"))}>
<DeleteIcon fontSize={14} />
</IconWrap>
</ConfirmButton>
</>
) : (
<ConfirmButton
onSuccessAction={async () => {
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 @@ -7,6 +7,7 @@ import {
ModalContent,
ModalHeader,
ModalOverlay,
Spinner,
useDisclosure,
} from "@chakra-ui/react";

Expand Down Expand Up @@ -80,7 +81,11 @@ function UploadButton(props: { onUploadSuccess: Function; children: React.ReactE
className="my-2 flex h-10 w-full items-center justify-between px-5 hover:bg-slate-100"
>
<span className="text-slate-500">{item.fileName}</span>
{item.status ? <CheckCircleIcon color="green.500" fontSize={20} /> : ""}
{item.status ? (
<CheckCircleIcon color="green.500" fontSize={20} />
) : (
<Spinner size="xs" className="mr-1" />
)}
</div>
);
})}
Expand Down