diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index b4ef972..54c5d65 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -32,11 +32,15 @@ export default function App() { } function Navbar() { const session = useContext(SessionContext); + const logout = () => { + destroySessionCookie(); + window.location.reload(); + } const links = session ? ( <> Home - Logout + Logout ): ( Login diff --git a/frontend/src/assets/file.svg b/frontend/src/assets/file.svg new file mode 100644 index 0000000..fc1d4a2 --- /dev/null +++ b/frontend/src/assets/file.svg @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/frontend/src/hooks/sessionRedirect.ts b/frontend/src/hooks/sessionRedirect.ts index c90d30a..80ddd7c 100644 --- a/frontend/src/hooks/sessionRedirect.ts +++ b/frontend/src/hooks/sessionRedirect.ts @@ -8,7 +8,7 @@ export const useSessionRedirect = () => { // Redirect to home if session is defined useEffect(() => { if (session !== undefined) { - navigate('/'); + navigate('/search'); } }, [session, navigate]) } \ No newline at end of file diff --git a/frontend/src/screens/Login.tsx b/frontend/src/screens/Login.tsx index 3b5f558..54e5da6 100644 --- a/frontend/src/screens/Login.tsx +++ b/frontend/src/screens/Login.tsx @@ -22,19 +22,15 @@ export default function Login() { body: JSON.stringify({ username, password }), }) .then(response => response.json()) - .then(response => response.json()) .then(data => { console.log("Login response data:", data); if (data.token) { - localStorage.setItem('authToken', data.token); - navigate('/search'); + // localStorage.setItem('authToken', data.token); + navigate('/search'); } else { console.error('No token received:', data); } }) - // .then(() => { - // navigate('/'); - // }) .catch((error) => { console.error('Error:', error); }); diff --git a/frontend/src/screens/MainSearch.tsx b/frontend/src/screens/MainSearch.tsx index f20bfb9..e3d2ae8 100644 --- a/frontend/src/screens/MainSearch.tsx +++ b/frontend/src/screens/MainSearch.tsx @@ -1,6 +1,8 @@ import React, { useState, useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import '../styles/MainScreenWrapper.css'; +import { getSessionCookie } from '../contexts/session'; +import { Professor, Course, Topic } from "../types/types"; interface Filters { professor: string; @@ -14,9 +16,9 @@ const MainSearch: React.FC = () => { course: '', topic: '', }); - const [professors, setProfessors] = useState([]); - const [courses, setCourses] = useState([]); - const [topics, setTopics] = useState([]); + const [professors, setProfessors] = useState([]); + const [courses, setCourses] = useState([]); + const [topics, setTopics] = useState([]); const navigate = useNavigate(); useEffect(() => { @@ -29,7 +31,8 @@ const MainSearch: React.FC = () => { }, []); const getAuthHeaders = () => { - const token = localStorage.getItem('authToken'); + const token = getSessionCookie(); + // const token = localStorage.getItem('authToken'); console.log("Using token for API call:", token); return { 'Authorization': `Token ${token}`, @@ -41,12 +44,13 @@ const MainSearch: React.FC = () => { try { const response = await fetch('http://localhost:8000/api/professors', { method: 'GET', - //credentials: 'include', headers: getAuthHeaders(), }); const data = await response.json(); - //setProfessors(data); + console.log("Professors fetched:", data); + if (Array.isArray(data)) { + console.log("Professors fetched:", data); setProfessors(data); } else { console.error('Data fetched is not an array:', data); @@ -60,11 +64,9 @@ const MainSearch: React.FC = () => { try { const response = await fetch('http://localhost:8000/api/courses', { method: 'GET', - //credentials: 'include', headers: getAuthHeaders(), }); const data = await response.json(); - //setCourses(data); if (Array.isArray(data)) { setCourses(data); } else { @@ -79,7 +81,6 @@ const MainSearch: React.FC = () => { try { const response = await fetch('http://localhost:8000/api/topics', { method: 'GET', - //credentials: 'include', headers: getAuthHeaders(), }); const data = await response.json(); @@ -88,7 +89,6 @@ const MainSearch: React.FC = () => { } else { console.error('Data fetched is not an array:', data); } - //setTopics(data); } catch (error) { console.error('Error fetching topics:', error); } diff --git a/frontend/src/types/types.ts b/frontend/src/types/types.ts new file mode 100644 index 0000000..ff5b577 --- /dev/null +++ b/frontend/src/types/types.ts @@ -0,0 +1,15 @@ +export interface Professor { + id: number; + name: string; +} +export interface Course { + id: number; + name: string; + number: string; +} + +export interface Topic { + id: number; + name: string; + description: string; +} \ No newline at end of file