mirror of
https://github.com/AmanTahiliani/PeerNotes.git
synced 2026-08-07 11:55:12 -04:00
get basic results page working
This commit is contained in:
@@ -37,7 +37,7 @@ function Navbar() {
|
|||||||
background: '#B1D4E0',
|
background: '#B1D4E0',
|
||||||
padding: '8px 16px',
|
padding: '8px 16px',
|
||||||
borderRadius: '5px',
|
borderRadius: '5px',
|
||||||
margin: '0 5px'
|
// margin: '0 5px'
|
||||||
};
|
};
|
||||||
const session = useContext(SessionContext);
|
const session = useContext(SessionContext);
|
||||||
const logout = () => {
|
const logout = () => {
|
||||||
@@ -47,10 +47,14 @@ function Navbar() {
|
|||||||
|
|
||||||
const links = session ? (
|
const links = session ? (
|
||||||
<>
|
<>
|
||||||
<img src="/PeerNotes.png" alt="PeerNotes Logo" style={{ height: '60px', marginRight: '10px' }} />
|
<div>
|
||||||
<Link to="/" style={linkStyle}>Home</Link>
|
<img src="/PeerNotes.png" alt="PeerNotes Logo" style={{ height: '60px' }} />
|
||||||
<Link to="/search" style={linkStyle}>Search</Link>
|
<Link to="/" style={linkStyle}>Home</Link>
|
||||||
<a onClick={logout} style={linkStyle}>Logout</a>
|
<Link to="/search" style={linkStyle}>Search</Link>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<a onClick={logout} style={linkStyle}>Logout</a>
|
||||||
|
</div>
|
||||||
</>
|
</>
|
||||||
): (
|
): (
|
||||||
<Link to="/login">Login</Link>
|
<Link to="/login">Login</Link>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import '../styles/MainScreenWrapper.css';
|
import '../styles/MainScreenWrapper.css';
|
||||||
import { getSessionCookie } from '../contexts/session';
|
import { getAuthHeaders } from '../utils/getAuthHeaders';
|
||||||
import { Professor, Course, Topic } from "../types/types";
|
import { Professor, Course, Topic } from "../types/types";
|
||||||
|
|
||||||
interface Filters extends Record<string, string> {
|
interface Filters extends Record<string, string> {
|
||||||
@@ -30,15 +30,6 @@ const MainSearch: React.FC = () => {
|
|||||||
fetchTopics();
|
fetchTopics();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const getAuthHeaders = () => {
|
|
||||||
const token = getSessionCookie();
|
|
||||||
// const token = localStorage.getItem('authToken');
|
|
||||||
console.log("Using token for API call:", token);
|
|
||||||
return {
|
|
||||||
'Authorization': `Token ${token}`,
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const fetchProfessors = async () => {
|
const fetchProfessors = async () => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,15 +1,8 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { useLocation, useNavigate } from 'react-router-dom';
|
import { useLocation, useNavigate } from 'react-router-dom';
|
||||||
import styles from '../styles/Results.module.css'; // Make sure this path is correct
|
import styles from '../styles/Results.module.css'; // Make sure this path is correct
|
||||||
|
import { getAuthHeaders } from '../utils/getAuthHeaders';
|
||||||
interface File {
|
import { File } from '../types/types';
|
||||||
id: string;
|
|
||||||
name: string; // do we even use id and name?
|
|
||||||
professor: string;
|
|
||||||
course: string;
|
|
||||||
type?: string; // Assumed type is optional
|
|
||||||
// what other properties to add?semester?
|
|
||||||
}
|
|
||||||
|
|
||||||
const Results: React.FC = () => {
|
const Results: React.FC = () => {
|
||||||
const [files, setFiles] = useState<File[]>([]);
|
const [files, setFiles] = useState<File[]>([]);
|
||||||
@@ -23,7 +16,8 @@ const Results: React.FC = () => {
|
|||||||
try {
|
try {
|
||||||
// Need to double check this
|
// Need to double check this
|
||||||
const queryString = location.search; // Includes the '?' prefix
|
const queryString = location.search; // Includes the '?' prefix
|
||||||
const response = await fetch(`/api/path-to-filefilterview${queryString}`);
|
console.log(queryString)
|
||||||
|
const response = await fetch(`http://localhost:8000/api/files/filter${queryString}`, {headers: getAuthHeaders()});
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`HTTP error! status: ${response.status}`);
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
}
|
}
|
||||||
@@ -55,9 +49,26 @@ const Results: React.FC = () => {
|
|||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
<p>Loading...</p>
|
<p>Loading...</p>
|
||||||
) : files.length ? (
|
) : files.length ? (
|
||||||
<table className={styles.resultsTable}>
|
files.map((file) => (
|
||||||
{/* Table structure here */}
|
<>
|
||||||
</table>
|
<div key={file.id} className={styles.fileCard}>
|
||||||
|
<h3>{file.filename}</h3>
|
||||||
|
<p>Course: {file.course.name} {file.course.number}</p>
|
||||||
|
<p>Professor: {file.professor.name}</p>
|
||||||
|
<p>Semester: {file.semester.name}</p>
|
||||||
|
<p>Upvotes: {file.upvotes.length}</p>
|
||||||
|
<p>Downvotes: {file.downvotes.length}</p>
|
||||||
|
</div>
|
||||||
|
<div key={file.id} className={styles.fileCard}>
|
||||||
|
<h3>{file.filename}</h3>
|
||||||
|
<p>Course: {file.course.name} {file.course.number}</p>
|
||||||
|
<p>Professor: {file.professor.name}</p>
|
||||||
|
<p>Semester: {file.semester.name}</p>
|
||||||
|
<p>Upvotes: {file.upvotes.length}</p>
|
||||||
|
<p>Downvotes: {file.downvotes.length}</p>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
))
|
||||||
) : (
|
) : (
|
||||||
<p>No results found.</p>
|
<p>No results found.</p>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -14,6 +14,11 @@ nav {
|
|||||||
z-index: 1000;
|
z-index: 1000;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
nav div {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
.App {
|
.App {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|||||||
@@ -27,17 +27,33 @@
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
padding-top: 100px; /* Adjust based on header height to ensure content doesn't overlap */
|
|
||||||
margin: auto;
|
margin: auto;
|
||||||
width: 90%;
|
width: 100vh;
|
||||||
max-width: 600px;
|
gap: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.resultsTable {
|
.resultsTable {
|
||||||
/* to be filled out */
|
/* to be filled out */
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
.fileCard p {
|
||||||
|
background-color: #1f4f7c;
|
||||||
|
padding: 1rem;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
.fileCard {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 20px;
|
||||||
|
gap: 1rem;
|
||||||
|
background-color: #145DA0;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||||
|
min-width: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
.searchAgainButton {
|
.searchAgainButton {
|
||||||
height: 50px;
|
height: 50px;
|
||||||
|
|||||||
@@ -12,4 +12,28 @@ export interface Topic {
|
|||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Semester {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface User {
|
||||||
|
id: string;
|
||||||
|
username: string;
|
||||||
|
email: string;
|
||||||
|
ip_address: string;
|
||||||
|
points: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface File {
|
||||||
|
id: string;
|
||||||
|
filename: string;
|
||||||
|
original_author: User;
|
||||||
|
professor: Professor;
|
||||||
|
course: Course;
|
||||||
|
semester: Semester;
|
||||||
|
upvotes: number[];
|
||||||
|
downvotes: number[];
|
||||||
}
|
}
|
||||||
10
frontend/src/utils/getAuthHeaders.ts
Normal file
10
frontend/src/utils/getAuthHeaders.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { getSessionCookie } from "../contexts/session";
|
||||||
|
export const getAuthHeaders = () => {
|
||||||
|
const token = getSessionCookie();
|
||||||
|
// const token = localStorage.getItem('authToken');
|
||||||
|
console.log("Using token for API call:", token);
|
||||||
|
return {
|
||||||
|
'Authorization': `Token ${token}`,
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user