Skip to content

Commit

Permalink
UPDATE
Browse files Browse the repository at this point in the history
  • Loading branch information
YongZL committed Oct 23, 2024
1 parent 3e14f6e commit 262cc06
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
21 changes: 16 additions & 5 deletions src/components/ATable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC } from "react";
import { FC, useEffect } from "react";
import { data } from "../pages/files";
import { copyTextToClipboard, formatBytes, timestampToDateTime, truncateMiddle } from "../utils/utils";
import { Loading } from "./ALoading";
Expand All @@ -10,17 +10,28 @@ type ATableProps = {

const ATable: FC<ATableProps> = ({ header = [], data = [], loading }) => {


const fileHost = (item: data) => {
const cru_host = import.meta.env.VITE_API_DOWNLOAD_CRU_URL || ''
const ton_host = import.meta.env.VITE_API_DOWNLOAD_TON_URL || ''
if (!cru_host || !ton_host) return
let host = `${item.bagId ? ton_host : cru_host}/${item.cid || item.bagId}?filename=${encodeURI(item.fileName)}`
return host
}

const onDownloadFile = (item: data) => {
const host = ` https://ton-gateway.crust.network/gateway/${item.bagId}?filename=${item.fileName}`
const host = fileHost(item)
const link = document.createElement("a");
link.href = host;
link.href = host || '';
link.click();
URL.revokeObjectURL(link.href);
window.open()
}

const onShare = (item: data) => {
return fileHost(item)
}


return <>

<table className=" overflow-auto mb-[5px] ">
Expand Down Expand Up @@ -53,7 +64,7 @@ const ATable: FC<ATableProps> = ({ header = [], data = [], loading }) => {
<td><div className="w-[150px]">{timestampToDateTime(Number(item.uploadDate))}</div></td>
<td><div className="w-[100px]">{truncateMiddle(item.from, 5, 5)}</div></td>
<td><div className="w-[100px] flex gap-2">
<button onClick={() => copyTextToClipboard(`https://ton-gateway.crust.network/gateway/${item.bagId}?filename=${item.fileName}`)}>
<button onClick={() => copyTextToClipboard(onShare(item))}>
<img src="share.svg" className="w-5" />
</button>
<button onClick={() => onDownloadFile(item)}>
Expand Down
2 changes: 1 addition & 1 deletion src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function getCurrentUrlParams() {
return paramsObj;
}

export const copyTextToClipboard = async (text: string) => {
export const copyTextToClipboard = async (text?: string) => {
if (!text) return;
try {
await navigator.clipboard.writeText(text);
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"experimentalDecorators": false,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"target": "es6",
"target": "ESNext",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
Expand All @@ -22,7 +22,7 @@
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"module": "commonjs",
"module": "ESNext",
"moduleResolution": "node",
"sourceMap": true,
"useUnknownInCatchVariables": false,
Expand Down

0 comments on commit 262cc06

Please sign in to comment.