Spaces:
Sleeping
Sleeping
fixe login issue
Browse files- web/src/Login.tsx +16 -4
web/src/Login.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
|
| 2 |
|
| 3 |
const LOGIC_SAYINGS = [
|
| 4 |
"Logic is disciplined honesty",
|
|
@@ -115,10 +115,15 @@ const Login: React.FC<LoginProps> = ({ onLogin }) => {
|
|
| 115 |
const [username, setUsername] = useState('');
|
| 116 |
const [password, setPassword] = useState('');
|
| 117 |
const [assistantMode, setAssistantMode] = useState<'generalist' | 'legal-support'>('generalist');
|
|
|
|
| 118 |
|
| 119 |
const [error, setError] = useState('');
|
| 120 |
const [loading, setLoading] = useState(false);
|
| 121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
const randomSaying = useMemo(
|
| 123 |
() => LOGIC_SAYINGS[Math.floor(Math.random() * LOGIC_SAYINGS.length)],
|
| 124 |
[]
|
|
@@ -156,7 +161,7 @@ const Login: React.FC<LoginProps> = ({ onLogin }) => {
|
|
| 156 |
}
|
| 157 |
|
| 158 |
const sessionId = data.token || '';
|
| 159 |
-
onLogin(sessionId, data.user,
|
| 160 |
} catch (err: any) {
|
| 161 |
setError(err.message || 'An error occurred');
|
| 162 |
} finally {
|
|
@@ -206,7 +211,10 @@ const Login: React.FC<LoginProps> = ({ onLogin }) => {
|
|
| 206 |
<button
|
| 207 |
type="button"
|
| 208 |
className={`login-mode-btn${assistantMode === 'legal-support' ? ' login-mode-btn--active' : ''}`}
|
| 209 |
-
onClick={() =>
|
|
|
|
|
|
|
|
|
|
| 210 |
title="Legal support mode"
|
| 211 |
>
|
| 212 |
Legal Support
|
|
@@ -214,7 +222,10 @@ const Login: React.FC<LoginProps> = ({ onLogin }) => {
|
|
| 214 |
<button
|
| 215 |
type="button"
|
| 216 |
className={`login-mode-btn${assistantMode === 'generalist' ? ' login-mode-btn--active' : ''}`}
|
| 217 |
-
onClick={() =>
|
|
|
|
|
|
|
|
|
|
| 218 |
title="General-purpose mode"
|
| 219 |
>
|
| 220 |
Generalist
|
|
@@ -252,3 +263,4 @@ const Login: React.FC<LoginProps> = ({ onLogin }) => {
|
|
| 252 |
};
|
| 253 |
|
| 254 |
export default Login;
|
|
|
|
|
|
| 1 |
+
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
| 2 |
|
| 3 |
const LOGIC_SAYINGS = [
|
| 4 |
"Logic is disciplined honesty",
|
|
|
|
| 115 |
const [username, setUsername] = useState('');
|
| 116 |
const [password, setPassword] = useState('');
|
| 117 |
const [assistantMode, setAssistantMode] = useState<'generalist' | 'legal-support'>('generalist');
|
| 118 |
+
const assistantModeRef = useRef<'generalist' | 'legal-support'>('generalist');
|
| 119 |
|
| 120 |
const [error, setError] = useState('');
|
| 121 |
const [loading, setLoading] = useState(false);
|
| 122 |
|
| 123 |
+
useEffect(() => {
|
| 124 |
+
assistantModeRef.current = assistantMode;
|
| 125 |
+
}, [assistantMode]);
|
| 126 |
+
|
| 127 |
const randomSaying = useMemo(
|
| 128 |
() => LOGIC_SAYINGS[Math.floor(Math.random() * LOGIC_SAYINGS.length)],
|
| 129 |
[]
|
|
|
|
| 161 |
}
|
| 162 |
|
| 163 |
const sessionId = data.token || '';
|
| 164 |
+
onLogin(sessionId, data.user, assistantModeRef.current);
|
| 165 |
} catch (err: any) {
|
| 166 |
setError(err.message || 'An error occurred');
|
| 167 |
} finally {
|
|
|
|
| 211 |
<button
|
| 212 |
type="button"
|
| 213 |
className={`login-mode-btn${assistantMode === 'legal-support' ? ' login-mode-btn--active' : ''}`}
|
| 214 |
+
onClick={() => {
|
| 215 |
+
assistantModeRef.current = 'legal-support';
|
| 216 |
+
setAssistantMode('legal-support');
|
| 217 |
+
}}
|
| 218 |
title="Legal support mode"
|
| 219 |
>
|
| 220 |
Legal Support
|
|
|
|
| 222 |
<button
|
| 223 |
type="button"
|
| 224 |
className={`login-mode-btn${assistantMode === 'generalist' ? ' login-mode-btn--active' : ''}`}
|
| 225 |
+
onClick={() => {
|
| 226 |
+
assistantModeRef.current = 'generalist';
|
| 227 |
+
setAssistantMode('generalist');
|
| 228 |
+
}}
|
| 229 |
title="General-purpose mode"
|
| 230 |
>
|
| 231 |
Generalist
|
|
|
|
| 263 |
};
|
| 264 |
|
| 265 |
export default Login;
|
| 266 |
+
|