File size: 6,859 Bytes
fbaf2e6
ded8028
 
67bf8e4
6e94481
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ded8028
 
 
6e94481
ded8028
 
 
 
d6a10f8
ded8028
 
6d0aeb9
ded8028
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67bf8e4
 
 
 
 
 
 
 
 
 
c016efc
 
 
 
 
 
 
6e94481
 
 
 
 
 
 
 
 
 
 
 
c016efc
 
39e9c8d
6e94481
 
 
 
 
 
 
 
 
c016efc
6e94481
 
 
 
 
fbaf2e6
6e94481
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c016efc
6e94481
 
 
 
 
 
 
 
 
 
 
c016efc
6e94481
 
39e9c8d
6e94481
 
 
 
 
 
 
ded8028
 
6e94481
 
 
 
 
ded8028
6e94481
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ded8028
6e94481
 
ded8028
6e94481
c016efc
 
 
 
 
ded8028
 
 
 
 
39e9c8d
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import { useState, useEffect, useRef } from 'react';
import './AuthScreen.css';

function AuthScreen({ onAuth, darkMode, setDarkMode }) {
  const [stage, setStage]       = useState('splash');   // 'splash' | 'enter'
  const [username, setUsername]  = useState('');
  const [error, setError]       = useState('');
  const [loading, setLoading]   = useState(false);
  const [transitioning, setTransitioning] = useState(false);
  const inputRef = useRef(null);

  // Focus input when entering name stage
  useEffect(() => {
    if (stage === 'enter' && inputRef.current) {
      setTimeout(() => inputRef.current.focus(), 600);
    }
  }, [stage]);

  const handleEnterClick = () => {
    setTransitioning(true);
    setTimeout(() => {
      setStage('enter');
      setTransitioning(false);
    }, 500);
  };

  const handleSubmit = async (e) => {
    e.preventDefault();
    if (!username.trim()) return;
    setError('');
    setLoading(true);

    try {
      const res = await fetch('/api/v1/auth/enter', {
        method:  'POST',
        headers: { 'Content-Type': 'application/json' },
        body:    JSON.stringify({ username: username.trim() }),
      });
      const data = await res.json();

      if (!res.ok) {
        const msg = Array.isArray(data.detail)
          ? data.detail[0]?.msg ?? 'Invalid input'
          : data.detail ?? 'Something went wrong';
        setError(msg);
        return;
      }

      localStorage.setItem('soma_token',    data.access_token);
      localStorage.setItem('soma_username', data.username);
      onAuth(data.username);
    } catch {
      setError('Could not reach the server. Is it running?');
    } finally {
      setLoading(false);
    }
  };

  return (
    <div className={`landing ${transitioning ? 'transitioning' : ''} ${darkMode ? 'dark' : ''}`}>

      {/* Dark Mode Toggle */}
      <button 
        className="landing-theme-toggle"
        onClick={() => setDarkMode(!darkMode)}
        title={darkMode ? 'Switch to Light Mode' : 'Switch to Dark Mode'}
      >
        <span className="material-icons">{darkMode ? 'light_mode' : 'dark_mode'}</span>
      </button>

      {/* Animated background */}
      <div className="landing-bg">
        <div className="bg-orb orb-1" />
        <div className="bg-orb orb-2" />
        <div className="bg-orb orb-3" />
        <div className="bg-grid" />
        {/* Floating particles */}
        <div className="particles">
          {Array.from({ length: 20 }).map((_, i) => (
            <div key={i} className="particle" style={{
              '--x': `${Math.random() * 100}%`,
              '--y': `${Math.random() * 100}%`,
              '--duration': `${8 + Math.random() * 12}s`,
              '--delay': `${Math.random() * 5}s`,
              '--size': `${2 + Math.random() * 3}px`,
            }} />
          ))}
        </div>
      </div>

      {/* ══════ STAGE 1: Splash ══════ */}
      {stage === 'splash' && (
        <div className={`splash-content ${transitioning ? 'exit' : ''}`}>
          {/* Neural orb */}
          <div className="hero-orb">
            <div className="hero-ring r1" />
            <div className="hero-ring r2" />
            <div className="hero-ring r3" />
            <div className="hero-pulse-ring" />
            <div className="hero-core" />
          </div>

          <h1 className="hero-title">SOMA</h1>
          <p className="hero-tagline">Cognitive Architecture for AI</p>
          <p className="hero-desc">
            A brain-inspired system that builds memory as you talk.
            Every conversation shapes a living neural mesh — unique to you.
          </p>

          {/* Features row */}
          <div className="splash-features">
            <div className="splash-feature">
              <div className="sf-dot" />
              <span>Sensory Memory</span>
            </div>
            <div className="splash-feature">
              <div className="sf-dot" />
              <span>Knowledge Graph</span>
            </div>
            <div className="splash-feature">
              <div className="sf-dot" />
              <span>Neural Dreaming</span>
            </div>
          </div>

          <button className="enter-btn" onClick={handleEnterClick}>
            <span className="enter-btn-text">Enter</span>
            <span className="enter-btn-arrow">
              <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
                <path d="M5 12h14M12 5l7 7-7 7"/>
              </svg>
            </span>
          </button>

          <div className="splash-hint">Press Enter or click to begin</div>
        </div>
      )}

      {/* ══════ STAGE 2: Name Input ══════ */}
      {stage === 'enter' && (
        <div className="name-content">
          {/* Small orb */}
          <div className="name-orb">
            <div className="hero-ring r1" />
            <div className="hero-ring r2" />
            <div className="hero-core" />
          </div>

          <h2 className="name-heading">Who are you?</h2>
          <p className="name-sub">
            Enter your name to initialize your neural space.
            New here? We'll create your brain automatically.
          </p>

          <form className="name-form" onSubmit={handleSubmit}>
            <div className="name-input-wrap">
              <input
                ref={inputRef}
                className="name-input"
                type="text"
                value={username}
                onChange={e => setUsername(e.target.value)}
                placeholder="Type your name..."
                autoComplete="username"
                required
              />
              <div className="name-input-glow" />
            </div>

            {error && <p className="auth-error">{error}</p>}

            <button className="name-submit" type="submit" disabled={loading || !username.trim()}>
              {loading ? (
                <span className="loading-dots">
                  <span />
                  <span />
                  <span />
                </span>
              ) : 'Initialize'}
            </button>
          </form>

          <button className="back-link" onClick={() => setStage('splash')}>
            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
              <path d="M19 12H5M12 19l-7-7 7-7"/>
            </svg>
            Back
          </button>
        </div>
      )}

      {/* Footer */}
      <footer className="landing-footer">
        <span>Soma</span>
        <span className="footer-dot" />
        <span>Brain-Inspired AI</span>
      </footer>
    </div>
  );
}

export default AuthScreen;