File size: 1,734 Bytes
3568151
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React from 'react'

export class ErrorBoundary extends React.Component<{
  children: React.ReactNode
},{
  hasError: boolean
  error?: Error
} > {
  constructor(props: {
    children: React.ReactNode
  }) {
    super(props)
    this.state = { hasError: false }
  }

  static getDerivedStateFromError(error: Error): {
    hasError: boolean
    error?: Error
  } {
    return { hasError: true, error }
  }

  componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
    console.error('Error caught by boundary:', error, errorInfo)
  }

  render() {
    if (this.state.hasError) {
      return (
        <div style={{ 
          padding: '20px', 
          backgroundColor: '#323232', 
          color: 'white', 
          minHeight: '100vh' 
        }}>
          <h1>🎵♟️ Musical Chess Arena</h1>
          <div style={{ 
            backgroundColor: '#ff4444', 
            padding: '20px', 
            borderRadius: '8px',
            marginTop: '20px'
          }}>
            <h2>Something went wrong!</h2>
            <p>Error: {this.state.error?.message}</p>
            <pre style={{ marginTop: '10px', fontSize: '12px' }}>
              {this.state.error?.stack}
            </pre>
            <button 
              onClick={() => window.location.reload()}
              style={{ 
                marginTop: '20px',
                padding: '10px 20px',
                backgroundColor: '#323232',
                color: 'white',
                border: '2px solid white',
                borderRadius: '4px',
                cursor: 'pointer'
              }}
            >
              Reload Page
            </button>
          </div>
        </div>
      )
    }

    return this.props.children
  }
}