pdf generation
This commit is contained in:
@@ -2,6 +2,23 @@ import { LastRefresh } from './LastRefresh'
|
||||
import Image from 'next/image'
|
||||
|
||||
export function Navbar({ lastUpdateTime }) {
|
||||
const handleExport = async (timeRange) => {
|
||||
try {
|
||||
const response = await fetch(`/api/export-report?timeRange=${timeRange}`)
|
||||
const blob = await response.blob()
|
||||
const url = window.URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = `solar-report-${timeRange}-${new Date().toISOString().split('T')[0]}.pdf`
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
window.URL.revokeObjectURL(url)
|
||||
document.body.removeChild(a)
|
||||
} catch (error) {
|
||||
console.error('Error exporting report:', error)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<nav className="bg-gray-800/50 backdrop-blur-sm border-b border-gray-700">
|
||||
<div className="max-w-[1400px] mx-auto px-4 sm:px-6 py-4">
|
||||
@@ -20,11 +37,33 @@ export function Navbar({ lastUpdateTime }) {
|
||||
UTM Solar Panels
|
||||
</h1>
|
||||
</div>
|
||||
{lastUpdateTime && (
|
||||
<div className="flex items-center gap-2 text-gray-400">
|
||||
<LastRefresh timestamp={lastUpdateTime} />
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="flex gap-2">
|
||||
<button
|
||||
onClick={() => handleExport('today')}
|
||||
className="px-3 py-1.5 text-sm font-medium rounded-lg bg-gray-700/50 text-gray-300 hover:bg-gray-600/50 hover:text-white transition-all duration-200 hover:shadow-lg hover:shadow-gray-500/10"
|
||||
>
|
||||
Export Today
|
||||
</button>
|
||||
<button
|
||||
onClick={() => handleExport('week')}
|
||||
className="px-3 py-1.5 text-sm font-medium rounded-lg bg-gray-700/50 text-gray-300 hover:bg-gray-600/50 hover:text-white transition-all duration-200 hover:shadow-lg hover:shadow-gray-500/10"
|
||||
>
|
||||
Export Week
|
||||
</button>
|
||||
<button
|
||||
onClick={() => handleExport('month')}
|
||||
className="px-3 py-1.5 text-sm font-medium rounded-lg bg-gray-700/50 text-gray-300 hover:bg-gray-600/50 hover:text-white transition-all duration-200 hover:shadow-lg hover:shadow-gray-500/10"
|
||||
>
|
||||
Export Month
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{lastUpdateTime && (
|
||||
<div className="flex items-center gap-2 text-gray-400">
|
||||
<LastRefresh timestamp={lastUpdateTime} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
Reference in New Issue
Block a user