Skip to content

Commit e5d6516

Browse files
committed
Added download button for file
1 parent cf14e21 commit e5d6516

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

smoosense-gui/src/components/common/FileInfoPopover.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
'use client'
22

3-
import { Info, Loader2, AlertCircle } from 'lucide-react'
3+
import { Info, Loader2, AlertCircle, Download } from 'lucide-react'
44
import IconPopover from '@/components/common/IconPopover'
55
import { useFileInfo } from '@/lib/hooks/useFileInfo'
66
import { useAppSelector } from '@/lib/hooks'
77
import CopyToClipboard from '@/components/ui/CopyToClipboard'
88
import { pathBasename } from '@/lib/utils/pathUtils'
99
import { CLS } from '@/lib/utils/styles'
10+
import { getFileUrl } from '@/lib/utils/apiUtils'
1011

1112
export default function FileInfoPopover() {
1213
const filePath = useAppSelector((state) => state.ui.filePath)
@@ -17,6 +18,13 @@ export default function FileInfoPopover() {
1718
return null
1819
}
1920

21+
const handleDownload = () => {
22+
if (filePath) {
23+
const url = getFileUrl(filePath, true)
24+
window.open(url, '_blank')
25+
}
26+
}
27+
2028
const renderContent = () => {
2129
if (loading) {
2230
return (
@@ -62,6 +70,13 @@ export default function FileInfoPopover() {
6270
<span className="text-muted-foreground">Name:</span>
6371
<div className="flex items-center gap-1">
6472
<span className="truncate max-w-[150px]">{pathBasename(filePath)}</span>
73+
<button
74+
onClick={handleDownload}
75+
className={CLS.ICON_BUTTON_SM_SUBTLE}
76+
title="Download file"
77+
>
78+
<Download className="h-3 w-3" />
79+
</button>
6580
<CopyToClipboard value={pathBasename(filePath)} />
6681
</div>
6782
</div>

smoosense-gui/src/components/ui/CellPopover.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export default function CellPopover({
8989
{cellContent}
9090
{isHovered && copyValue && (
9191
<div className="absolute top-0 right-0 z-10">
92-
<CopyToClipboard value={copyValue} />
92+
<CopyToClipboard value={copyValue} className="bg-background/80" />
9393
</div>
9494
)}
9595
</div>

smoosense-gui/src/components/ui/CopyToClipboard.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import { CLS } from '@/lib/utils/styles'
77

88
interface CopyToClipboardProps {
99
value: unknown
10+
className?: string
1011
}
1112

12-
export default function CopyToClipboard({
13-
value
13+
export default function CopyToClipboard({
14+
value,
15+
className = ''
1416
}: CopyToClipboardProps) {
1517
const [copied, setCopied] = useState(false)
1618

@@ -36,7 +38,7 @@ export default function CopyToClipboard({
3638
}
3739

3840
const iconSize = 'h-3 w-3'
39-
const buttonClass = CLS.ICON_BUTTON_SM_SUBTLE
41+
const buttonClass = `${CLS.ICON_BUTTON_SM_SUBTLE} ${className}`
4042

4143
return (
4244
<button

smoosense-gui/src/lib/utils/styles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const BUTTON_SECONDARY = 'bg-secondary text-secondary-foreground hover:bg-primar
1414
const BUTTON_DESTRUCTIVE = 'bg-secondary text-secondary-foreground hover:bg-destructive/30'
1515

1616
// Icon button variants
17-
const ICON_BUTTON_SUBTLE = 'bg-background/80 hover:bg-accent border border-border shadow-sm opacity-80 hover:opacity-100'
17+
const ICON_BUTTON_SUBTLE = ' border border-border shadow-sm opacity-80 hover:opacity-100'
1818

1919
// Hyperlink styles
2020
const HYPERLINK = 'dark:text-sky-400 dark:hover:text-sky-300 text-blue-600 hover:text-blue-800 underline underline-offset-4 transition-colors'

0 commit comments

Comments
 (0)