Browse Source

fix update banner

imwald
Silberengel 2 weeks ago
parent
commit
4d2a5fa902
  1. 4
      package-lock.json
  2. 2
      package.json
  3. 45
      src/components/VersionUpdateBanner/index.tsx

4
package-lock.json generated

@ -1,12 +1,12 @@
{ {
"name": "imwald", "name": "imwald",
"version": "22.5.7", "version": "23.0.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "imwald", "name": "imwald",
"version": "22.5.7", "version": "23.0.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@asciidoctor/core": "^3.0.4", "@asciidoctor/core": "^3.0.4",

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "imwald", "name": "imwald",
"version": "22.5.7", "version": "23.0.0",
"description": "Imwald — a user-friendly Nostr client focused on relay feed browsing, publications, and relay discovery", "description": "Imwald — a user-friendly Nostr client focused on relay feed browsing, publications, and relay discovery",
"private": true, "private": true,
"type": "module", "type": "module",

45
src/components/VersionUpdateBanner/index.tsx

@ -5,10 +5,19 @@ import { useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import logger from '@/lib/logger' import logger from '@/lib/logger'
function readVersionUpdateDismissed(): boolean {
if (typeof window === 'undefined') return false
try {
return sessionStorage.getItem('versionUpdateDismissed') === 'true'
} catch {
return false
}
}
export default function VersionUpdateBanner() { export default function VersionUpdateBanner() {
const { t } = useTranslation() const { t } = useTranslation()
const [updateAvailable, setUpdateAvailable] = useState(false) const [updateAvailable, setUpdateAvailable] = useState(false)
const [isDismissed, setIsDismissed] = useState(false) const [isDismissed, setIsDismissed] = useState(readVersionUpdateDismissed)
const [isUpdating, setIsUpdating] = useState(false) const [isUpdating, setIsUpdating] = useState(false)
useEffect(() => { useEffect(() => {
@ -107,24 +116,40 @@ export default function VersionUpdateBanner() {
}, []) }, [])
const handleUpdate = () => { const handleUpdate = () => {
try {
sessionStorage.setItem('versionUpdateDismissed', 'true')
} catch {
// ignore quota or private browsing
}
setIsDismissed(true)
setIsUpdating(true) setIsUpdating(true)
// Reload the page to activate the new service worker
const reload = () => {
window.location.reload() window.location.reload()
} }
if (typeof navigator === 'undefined' || !('serviceWorker' in navigator)) {
reload()
return
}
void navigator.serviceWorker
.getRegistration()
.then((registration) => {
registration?.waiting?.postMessage({ type: 'SKIP_WAITING' })
reload()
})
.catch(reload)
}
const handleDismiss = () => { const handleDismiss = () => {
setIsDismissed(true) setIsDismissed(true)
// Store dismissal in sessionStorage to avoid showing it again this session try {
sessionStorage.setItem('versionUpdateDismissed', 'true') sessionStorage.setItem('versionUpdateDismissed', 'true')
} catch {
// ignore quota or private browsing
} }
// Check if user already dismissed this session
useEffect(() => {
const dismissed = sessionStorage.getItem('versionUpdateDismissed')
if (dismissed === 'true') {
setIsDismissed(true)
} }
}, [])
if (!updateAvailable || isDismissed) { if (!updateAvailable || isDismissed) {
return null return null

Loading…
Cancel
Save