Girish Jeswani commited on
Commit
a3ae13f
·
1 Parent(s): 01db13e

update routes + new auth

Browse files
phd-advisor-frontend/src/App.js CHANGED
@@ -2,37 +2,49 @@ import React, { useState } from 'react';
2
  import { ThemeProvider } from './contexts/ThemeContext';
3
  import HomePage from './pages/HomePage';
4
  import ChatPage from './pages/ChatPage';
 
5
  import './styles/components.css';
6
 
7
  function App() {
8
  const [currentView, setCurrentView] = useState('home');
 
9
 
10
- const navigateToChat = () => {
11
- setCurrentView('chat');
12
- };
13
 
14
- const navigateToHome = () => {
15
- setCurrentView('home');
16
- // Reset session when going home
17
- fetch('http://localhost:8000/reset-session', {
18
- method: 'POST',
19
- headers: {
20
- 'Content-Type': 'application/json',
21
- }
22
- }).catch(console.error);
23
- };
 
 
 
 
 
 
24
 
25
  return (
26
- <ThemeProvider>
27
- <div className="App">
28
- {currentView === 'home' ? (
29
- <HomePage onNavigateToChat={navigateToChat} />
30
- ) : (
31
- <ChatPage onNavigateToHome={navigateToHome} />
32
- )}
33
- </div>
34
- </ThemeProvider>
35
- );
 
 
 
 
36
  }
37
 
38
  export default App;
 
2
  import { ThemeProvider } from './contexts/ThemeContext';
3
  import HomePage from './pages/HomePage';
4
  import ChatPage from './pages/ChatPage';
5
+ import AuthPage from './pages/AuthPage';
6
  import './styles/components.css';
7
 
8
  function App() {
9
  const [currentView, setCurrentView] = useState('home');
10
+ const [isAuthenticated, setIsAuthenticated] = useState(false);
11
 
12
+ const navigateToAuth = () => {
13
+ setCurrentView('auth');
14
+ };
15
 
16
+ const navigateToHome = () => {
17
+ setCurrentView('home');
18
+ setIsAuthenticated(false); // Reset auth when going home
19
+ // Reset session when going home
20
+ fetch('http://localhost:8000/reset-session', {
21
+ method: 'POST',
22
+ headers: {
23
+ 'Content-Type': 'application/json',
24
+ }
25
+ }).catch(console.error);
26
+ };
27
+
28
+ const handleAuthSuccess = () => {
29
+ setIsAuthenticated(true);
30
+ setCurrentView('chat');
31
+ };
32
 
33
  return (
34
+ <ThemeProvider>
35
+ <div className="App">
36
+ {currentView === 'home' && (
37
+ <HomePage onNavigateToChat={navigateToAuth} />
38
+ )}
39
+ {currentView === 'auth' && (
40
+ <AuthPage onAuthSuccess={handleAuthSuccess} />
41
+ )}
42
+ {currentView === 'chat' && (
43
+ <ChatPage onNavigateToHome={navigateToHome} />
44
+ )}
45
+ </div>
46
+ </ThemeProvider>
47
+ );
48
  }
49
 
50
  export default App;
phd-advisor-frontend/src/pages/AuthPage.js ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React, { useState } from 'react';
2
+ import Login from '../components/Login';
3
+ import Signup from '../components/Signup';
4
+
5
+ const AuthPage = ({ onAuthSuccess }) => {
6
+ const [isLogin, setIsLogin] = useState(true);
7
+
8
+ const handleNavigateToLogin = () => setIsLogin(true);
9
+ const handleNavigateToSignup = () => setIsLogin(false);
10
+
11
+ return (
12
+ <>
13
+ {isLogin ? (
14
+ <Login
15
+ onNavigateToSignup={handleNavigateToSignup}
16
+ onNavigateToHome={onAuthSuccess}
17
+ />
18
+ ) : (
19
+ <Signup
20
+ onNavigateToLogin={handleNavigateToLogin}
21
+ onNavigateToHome={onAuthSuccess}
22
+ />
23
+ )}
24
+ </>
25
+ );
26
+ };
27
+
28
+ export default AuthPage;