Skip to content

Commit e0bca63

Browse files
Merge pull request #347 from JaneliaSciComp/mkitti-download-button
feat: add download button to FileViewer header
2 parents 580c73d + da0300e commit e0bca63

1 file changed

Lines changed: 22 additions & 12 deletions

File tree

frontend/src/components/ui/BrowsePage/FileViewer.tsx

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import {
55
materialDark,
66
coy
77
} from 'react-syntax-highlighter/dist/esm/styles/prism';
8+
import { HiOutlineDownload } from 'react-icons/hi';
89
import { Formatter } from 'fracturedjsonjs';
910

1011
import { useFileBrowserContext } from '@/contexts/FileBrowserContext';
11-
import { formatFileSize, formatUnixTimestamp } from '@/utils';
12+
import { formatFileSize, formatUnixTimestamp, getFileURL } from '@/utils';
1213
import type { FileOrFolder } from '@/shared.types';
1314
import {
1415
useFileContentQuery,
@@ -220,6 +221,8 @@ export default function FileViewer({ file }: FileViewerProps) {
220221
// Determine if we should show JSON format toggle
221222
const showJsonToggle = isJsonFile && !isBinary;
222223

224+
const downloadUrl = fspName ? getFileURL(fspName, file.path) : null;
225+
223226
return (
224227
<div className="flex flex-col h-full w-full overflow-hidden">
225228
{/* File info header */}
@@ -233,17 +236,24 @@ export default function FileViewer({ file }: FileViewerProps) {
233236
{formatUnixTimestamp(file.last_modified)}
234237
</Typography>
235238
</div>
236-
{showJsonToggle ? (
237-
<div className="flex items-center gap-2 shrink-0">
238-
<Typography className="text-foreground text-sm whitespace-nowrap">
239-
Format JSON
240-
</Typography>
241-
<Switch
242-
checked={formatJson}
243-
onChange={() => setFormatJson(!formatJson)}
244-
/>
245-
</div>
246-
) : null}
239+
<div className="flex items-center gap-3 shrink-0">
240+
{showJsonToggle ? (
241+
<div className="flex items-center gap-2">
242+
<Typography className="text-foreground text-sm whitespace-nowrap">
243+
Format JSON
244+
</Typography>
245+
<Switch
246+
checked={formatJson}
247+
onChange={() => setFormatJson(!formatJson)}
248+
/>
249+
</div>
250+
) : null}
251+
{downloadUrl ? (
252+
<a download={file.name} href={downloadUrl} title="Download file">
253+
<HiOutlineDownload className="text-foreground hover:text-primary text-xl" />
254+
</a>
255+
) : null}
256+
</div>
247257
</div>
248258

249259
{/* File content viewer */}

0 commit comments

Comments
 (0)