diff --git a/components/CacheUpdateManager.tsx b/components/CacheUpdateManager.tsx index f4b484d..4517f42 100644 --- a/components/CacheUpdateManager.tsx +++ b/components/CacheUpdateManager.tsx @@ -1,4 +1,5 @@ import { useState } from 'react' +import { useRouter } from 'next/router' import { nostrAuthService } from '@/lib/nostrAuth' import { objectCache } from '@/lib/objectCache' import { syncUserContentToCache } from '@/lib/userContentSync' @@ -49,7 +50,8 @@ function NotConnectedMessage(): React.ReactElement { function createUpdateHandler( setUpdating: (value: boolean) => void, setError: (value: string | null) => void, - setSuccess: (value: boolean) => void + setSuccess: (value: boolean) => void, + router: ReturnType ): () => Promise { return async (): Promise => { try { @@ -58,24 +60,31 @@ function createUpdateHandler( setSuccess(false) await updateCache() setSuccess(true) + // Wait a bit to show success message, then reload page setTimeout(() => { - setSuccess(false) - }, 3000) + router.reload() + }, 1000) } catch (e) { const errorMessage = e instanceof Error ? e.message : 'Erreur lors de la mise à jour du cache' setError(errorMessage) console.error('Error updating cache:', e) - } finally { setUpdating(false) } } } +function Spinner(): React.ReactElement { + return ( +
+ ) +} + export function CacheUpdateManager(): React.ReactElement { + const router = useRouter() const [updating, setUpdating] = useState(false) const [success, setSuccess] = useState(false) const [error, setError] = useState(null) - const handleUpdateCache = createUpdateHandler(setUpdating, setError, setSuccess) + const handleUpdateCache = createUpdateHandler(setUpdating, setError, setSuccess, router) const state = nostrAuthService.getState() const isConnected = state.connected && state.pubkey @@ -97,8 +106,9 @@ export function CacheUpdateManager(): React.ReactElement { void handleUpdateCache() }} disabled={updating || !isConnected} - className="w-full py-3 px-6 bg-neon-cyan/20 hover:bg-neon-cyan/30 text-neon-cyan rounded-lg font-medium transition-all border border-neon-cyan/50 hover:shadow-glow-cyan disabled:opacity-50 disabled:cursor-not-allowed" + className="w-full py-3 px-6 bg-neon-cyan/20 hover:bg-neon-cyan/30 text-neon-cyan rounded-lg font-medium transition-all border border-neon-cyan/50 hover:shadow-glow-cyan disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center" > + {updating && } {updating ? 'Mise à jour en cours...' : 'Mettre à jour le cache'}