From 59901c5533adfc502c3f97652f1c7a5e8c63db87 Mon Sep 17 00:00:00 2001 From: Thomas Hallock Date: Thu, 20 Nov 2025 07:32:12 -0600 Subject: [PATCH] refactor: use existing Radix toast system for errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace custom ErrorToast with the existing Radix-based toast system. **Changes:** - Remove custom ErrorToast component (redundant) - Update ArcadeErrorContext to use useToast() from ToastContext - Simpler, more consistent with existing codebase - Better accessibility (Radix UI primitives) **Benefits:** - No duplicate toast infrastructure - Consistent styling with rest of app - Already set up and working - Radix UI accessibility built-in 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- apps/web/src/components/ErrorToast.tsx | 187 ------------------- apps/web/src/contexts/ArcadeErrorContext.tsx | 64 ++----- 2 files changed, 11 insertions(+), 240 deletions(-) delete mode 100644 apps/web/src/components/ErrorToast.tsx diff --git a/apps/web/src/components/ErrorToast.tsx b/apps/web/src/components/ErrorToast.tsx deleted file mode 100644 index de7c0468..00000000 --- a/apps/web/src/components/ErrorToast.tsx +++ /dev/null @@ -1,187 +0,0 @@ -'use client' - -import { useEffect, useState } from 'react' -import { css } from '../../styled-system/css' - -export interface ErrorToastProps { - message: string - details?: string - onDismiss: () => void - autoHideDuration?: number // milliseconds, default 10000 (10s) -} - -/** - * Error toast notification component - * Shows prominent error messages to users with optional details - */ -export function ErrorToast({ - message, - details, - onDismiss, - autoHideDuration = 10000, -}: ErrorToastProps) { - const [isVisible, setIsVisible] = useState(true) - const [showDetails, setShowDetails] = useState(false) - - useEffect(() => { - if (autoHideDuration > 0) { - const timer = setTimeout(() => { - setIsVisible(false) - setTimeout(onDismiss, 300) // Wait for fade-out animation - }, autoHideDuration) - - return () => clearTimeout(timer) - } - }, [autoHideDuration, onDismiss]) - - if (!isVisible) return null - - return ( -
- {/* Header with dismiss button */} -
-
- - ⚠️ - - Error -
- - -
- - {/* Error message */} -
- {message} -
- - {/* Optional details */} - {details && ( -
- - - {showDetails && ( -
-              {details}
-            
- )} -
- )} -
- ) -} - -/** - * Error toast container that manages multiple toasts - */ -export function ErrorToastContainer({ errors }: { errors: Array<{ id: string; message: string; details?: string }> }) { - const [visibleErrors, setVisibleErrors] = useState(errors) - - useEffect(() => { - setVisibleErrors(errors) - }, [errors]) - - return ( - <> - {visibleErrors.map((error, index) => ( - { - setVisibleErrors((prev) => prev.filter((e) => e.id !== error.id)) - }} - /> - ))} - - ) -} diff --git a/apps/web/src/contexts/ArcadeErrorContext.tsx b/apps/web/src/contexts/ArcadeErrorContext.tsx index c4b7e66b..28d004be 100644 --- a/apps/web/src/contexts/ArcadeErrorContext.tsx +++ b/apps/web/src/contexts/ArcadeErrorContext.tsx @@ -1,72 +1,30 @@ 'use client' -import React, { createContext, useContext, useState, useCallback, type ReactNode } from 'react' -import { ErrorToast } from '@/components/ErrorToast' - -interface ArcadeError { - id: string - message: string - details?: string - timestamp: number -} +import React, { createContext, useContext, useCallback, type ReactNode } from 'react' +import { useToast } from '@/components/common/ToastContext' interface ArcadeErrorContextValue { - errors: ArcadeError[] addError: (message: string, details?: string) => void - clearError: (id: string) => void - clearAllErrors: () => void } const ArcadeErrorContext = createContext(null) /** * Provider for arcade error management - * Manages error toast notifications across arcade games + * Uses the existing Radix-based toast system for error notifications */ export function ArcadeErrorProvider({ children }: { children: ReactNode }) { - const [errors, setErrors] = useState([]) + const { showError } = useToast() - const addError = useCallback((message: string, details?: string) => { - const error: ArcadeError = { - id: `error-${Date.now()}-${Math.random()}`, - message, - details, - timestamp: Date.now(), - } - - setErrors((prev) => [...prev, error]) - - // Auto-remove after 15 seconds as fallback - setTimeout(() => { - setErrors((prev) => prev.filter((e) => e.id !== error.id)) - }, 15000) - }, []) - - const clearError = useCallback((id: string) => { - setErrors((prev) => prev.filter((e) => e.id !== id)) - }, []) - - const clearAllErrors = useCallback(() => { - setErrors([]) - }, []) + const addError = useCallback( + (message: string, details?: string) => { + showError(message, details) + }, + [showError] + ) return ( - - {children} - - {/* Render error toasts */} -
- {errors.map((error) => ( - clearError(error.id)} - autoHideDuration={10000} - /> - ))} -
-
+ {children} ) }