Skip to content
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
8 changes: 8 additions & 0 deletions src/app/components/FileUploadUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
FILE_SIZE_CONFIG,
UPLOAD_TIMEOUT_CONFIG,
SWARM_DEFERRED_UPLOAD,
BEE_GATEWAY_URL,
} from './constants';
import { processTarFile, TarProcessingResult } from './FolderUploadUtils';
import { getStampUsage, formatDateEU } from './utils';
Expand Down Expand Up @@ -131,6 +132,13 @@ export const isArchiveFile = (filename?: string): boolean => {
return archiveExtensions.some(ext => filename.toLowerCase().endsWith(ext));
};

export const getFileReferenceUrl = (reference: string, filename?: string): string => {
if (filename && !isArchiveFile(filename)) {
return `${BEE_GATEWAY_URL}${reference}/${filename}`;
}
return `${BEE_GATEWAY_URL}${reference}/`;
};

/**
* Interface for XHR upload response
*/
Expand Down
56 changes: 47 additions & 9 deletions src/app/components/SwapComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import {
handleFileUpload as uploadFile,
handleMultiFileUpload,
isArchiveFile,
getFileReferenceUrl,
MultiFileResult,
getUserFriendlyErrorMessage,
} from './FileUploadUtils';
Expand Down Expand Up @@ -1915,15 +1916,52 @@ const SwapComponent: React.FC = () => {
</span>
</div>
{result.success && result.reference && (
<div
className={styles.fileResultReference}
onClick={() => {
navigator.clipboard.writeText(result.reference);
}}
title="Click to copy reference"
>
{result.reference}
</div>
<>
<div className={styles.referenceCopyWrapper}>
<code
className={`${styles.referenceCode} ${styles.fileResultReferenceCode}`}
onClick={e => {
navigator.clipboard.writeText(result.reference);
const el = e.currentTarget;
el.setAttribute('data-copied', 'true');
setTimeout(() => {
el.setAttribute('data-copied', 'false');
}, 2000);
}}
title="Click to copy reference"
data-copied="false"
>
{result.reference}
</code>
</div>
<div className={styles.fileResultLinkButtons}>
<button
type="button"
className={styles.fileResultLink}
onClick={e => {
navigator.clipboard.writeText(
getFileReferenceUrl(result.reference, result.filename)
);
const button = e.currentTarget;
const originalText = button.textContent;
button.textContent = 'Copied!';
setTimeout(() => {
button.textContent = originalText;
}, 2000);
}}
>
Copy link
</button>
<a
href={getFileReferenceUrl(result.reference, result.filename)}
target="_blank"
rel="noopener noreferrer"
className={styles.fileResultLink}
>
Open link
</a>
</div>
</>
)}
{!result.success && result.error && (
<div className={styles.fileResultError}>{result.error}</div>
Expand Down
71 changes: 59 additions & 12 deletions src/app/components/css/SwapComponent.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@
font-family: monospace;
font-size: 14px;
cursor: pointer;
transition: background-color 0.2s;
transition: background-color 0.2s, color 0.2s;
position: relative;
}

Expand Down Expand Up @@ -615,6 +615,11 @@
z-index: 10;
}

.referenceCode[data-copied="true"] {
color: #3fb950;
background-color: rgba(63, 185, 80, 0.15);
}

.referenceLink {
display: inline-block;
margin-top: 10px;
Expand Down Expand Up @@ -1423,6 +1428,24 @@
margin: 20px 0;
max-height: 300px;
overflow-y: auto;
padding-bottom: 4px;
scrollbar-width: thin;
scrollbar-color: #30363d #161b22;
}

.multiFileResults::-webkit-scrollbar {
width: 8px;
}

.multiFileResults::-webkit-scrollbar-track {
background: #161b22;
border-radius: 4px;
}

.multiFileResults::-webkit-scrollbar-thumb {
background-color: #30363d;
border-radius: 4px;
border: 2px solid #161b22;
}

.fileResult {
Expand Down Expand Up @@ -1469,21 +1492,45 @@
background-color: #ff5a52;
}

.fileResultReference {
font-family: monospace;
.fileResultReferenceCode {
font-size: 12px;
color: #8b949e;
word-break: break-all;
cursor: pointer;
padding: 4px;
background-color: #0d1117;
border-radius: 4px;
margin-top: 5px;
transition: background-color 0.2s;
margin: 5px 0 0;
}

.fileResultReference:hover {
background-color: #1f2937;
.fileResultReferenceCode[data-copied="true"]::after {
top: auto;
bottom: -26px;
font-size: 11px;
padding: 3px 6px;
}

.fileResultLinkButtons {
display: flex;
gap: 6px;
margin-top: 6px;
}

.fileResultLink {
flex: 1;
text-align: center;
padding: 4px 8px;
font-size: 11px;
border-radius: 6px;
color: #ff7a00;
text-decoration: none;
border: 1px solid #ff7a00;
transition: all 0.2s;
background: transparent;
cursor: pointer;
font-family: inherit;
line-height: 1.2;
}

.fileResultLink:hover {
background-color: #ff7a00;
color: #ffffff;
text-decoration: none;
}

.fileResultError {
Expand Down
Loading