Skip to content
Open
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
51 changes: 51 additions & 0 deletions client/src/components/Home/MyFiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
Upload,
Trash2,
Share2,
Check,
Link,
Download,
Copy,
Search,
Expand Down Expand Up @@ -122,6 +124,7 @@ const MyFiles: React.FC = () => {

// Share modal state
const [shareModalOpen, setShareModalOpen] = useState(false);
const [copiedFileId, setCopiedFileId] = useState<string | null>(null);
const [selectedFileForShare, setSelectedFileForShare] = useState<{
_id: string;
fileName: string;
Expand Down Expand Up @@ -854,6 +857,15 @@ const MyFiles: React.FC = () => {
toast.success("Share link copied to clipboard!");
};

// ✅ Copy link directly without opening modal
const handleCopyLink = async (fileId: string, fileName: string) => {
const shareLink = `${window.location.origin}/share/${fileId}`;
await navigator.clipboard.writeText(shareLink);
await trackLinkCopy(fileId, fileName, shareLink);
setCopiedFileId(fileId);
setTimeout(() => setCopiedFileId(null), 2000);
};

// ✅ Download file with tracking
const handleDownload = async (
fileId: string,
Expand Down Expand Up @@ -1745,6 +1757,26 @@ formatFileSize
>
<Share2 className="w-4 h-4" />
</button>

<button
onClick={(e) => {
e.stopPropagation();
if (file.scanStatus !== "safe") {
toast.error(`Cannot copy link. Status: ${file.scanStatus}`);
return;
}
handleCopyLink(file.id, file.name);
}}
className={`p-2 rounded-full text-white ${file.scanStatus === 'safe' ? 'bg-gray-800 hover:bg-gray-700' : 'bg-gray-500 cursor-not-allowed'}`}
title={file.scanStatus === 'safe' ? "Copy Link" : "Scan in progress or failed"}
>
{copiedFileId === file.id ? (
<Check className="w-4 h-4 text-green-400" />
) : (
<Link className="w-4 h-4" />
)}
</button>

<button
onClick={(e) => {
e.stopPropagation();
Expand Down Expand Up @@ -2092,6 +2124,25 @@ formatFileSize
>
<Share2 className={`w-4 h-4 ${file.scanStatus === 'safe' ? 'text-gray-400 hover:text-white' : 'text-gray-600'}`} />
</button>

<button
onClick={() => {
if (file.scanStatus !== "safe") {
toast.error(`Cannot copy link. Status: ${file.scanStatus}`);
return;
}
handleCopyLink(file.id, file.name);
}}
className="p-1.5 hover:bg-gray-700 rounded"
title="Copy Link"
>
{copiedFileId === file.id ? (
<Check className="w-4 h-4 text-green-400" />
) : (
<Link className="w-4 h-4 text-gray-400 hover:text-white" />
)}
</button>

<button
onClick={() => setShowFileStats(file.id)}
className="p-1.5 hover:bg-gray-700 rounded"
Expand Down
Loading