Spaces:
Sleeping
Sleeping
File size: 2,481 Bytes
f871fed |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
'use client'
import { useEffect } from 'react'
import { toast } from 'sonner'
import { getConfig } from '@/lib/config'
/**
* Hook to check for version updates and display notification.
* Should be called once per session in the dashboard layout.
*/
export function useVersionCheck() {
useEffect(() => {
const checkVersion = async () => {
try {
const config = await getConfig()
// Only show notification if update is available
if (config.hasUpdate && config.latestVersion) {
// Check if user has dismissed this version in this session
const dismissKey = `version_notification_dismissed_${config.latestVersion}`
const isDismissed = sessionStorage.getItem(dismissKey)
if (!isDismissed) {
// Show persistent toast notification
toast.info(`Version ${config.latestVersion} available`, {
description: 'A new version of Open Notebook is available.',
duration: Infinity, // No auto-dismiss - user must manually dismiss
closeButton: true, // Show close button for dismissing
action: {
label: 'View on GitHub',
onClick: () => {
window.open(
'https://github.com/lfnovo/open-notebook',
'_blank',
'noopener,noreferrer'
)
},
},
onDismiss: () => {
// Store dismissal in session storage
sessionStorage.setItem(dismissKey, 'true')
},
})
console.log(
`π [Version Check] Update available: ${config.version} β ${config.latestVersion}`
)
} else {
console.log(
`π [Version Check] Notification dismissed for version ${config.latestVersion}`
)
}
} else if (config.latestVersion) {
console.log(
`β
[Version Check] Running latest version: ${config.version}`
)
} else {
console.log(
`β οΈ [Version Check] Could not check for updates (offline or GitHub unavailable)`
)
}
} catch (error) {
console.error('β [Version Check] Failed to check version:', error)
// Silently fail - don't disrupt user experience
}
}
// Run version check
checkVersion()
}, []) // Run once on mount
}
|