Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 8 additions & 29 deletions client/src/pages/NotesPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,13 @@ const NotesPage = () => {
throw new Error(errorData.error || "Failed to fetch notes");
}

const data = await res.json();
let data = await res.json();

// extract isLastPage and assign notes to data
const isLastPage = data?.isLastPage;
if (isLastPage) setHasMore(!isLastPage);
data = data?.notes;

if (!Array.isArray(data)) {
throw new Error("Invalid response format");
}
Expand Down Expand Up @@ -160,20 +166,13 @@ const NotesPage = () => {
};
const renderNotesContent = () => {
if (loading) {
return (


<Spinner />

);
return <Spinner />;
}

if (error) {
return (

<div className="bg-red-50 dark:bg-red-900 border-l-4 border-red-400 dark:border-red-500 p-4 mb-6 rounded">
<p className="text-sm text-red-700 dark:text-red-100">{error}</p>

</div>
);
}
Expand All @@ -182,7 +181,6 @@ const NotesPage = () => {
return (
<>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">

{notes.map((note) => (
<NotesCard
notes={notes}
Expand All @@ -193,26 +191,22 @@ const NotesPage = () => {
handleViewPDF={handleViewPDF}
/>
))}

</div>

{/* Pagination Controls */}
<div className="flex justify-between items-center mt-8">
<button
onClick={handlePrevPage}
disabled={page === 0}

className={`px-4 py-2 rounded-md transition-colors ${
page === 0
? "bg-gray-300 dark:bg-gray-600 text-gray-500 cursor-not-allowed"

: "bg-blue-600 hover:bg-blue-700 text-white"
}`}
>
Previous
</button>


<span className="text-gray-700 dark:text-gray-200">
Page {page + 1}
</span>
Expand All @@ -223,7 +217,6 @@ const NotesPage = () => {
className={`px-4 py-2 rounded-md transition-colors ${
!hasMore
? "bg-gray-300 dark:bg-gray-600 text-gray-500 cursor-not-allowed"

: "bg-blue-600 hover:bg-blue-700 text-white"
}`}
>
Expand All @@ -235,7 +228,6 @@ const NotesPage = () => {
}

return (

<div className="min-h-screen bg-gray-50 dark:bg-gray-900 py-8 px-4 sm:px-6 lg:px-8 mt-12">
<div className="text-center py-16 bg-white dark:bg-gray-800 rounded-xl shadow-sm">
<h3 className="text-lg font-medium text-gray-900 dark:text-white">
Expand Down Expand Up @@ -296,13 +288,11 @@ const NotesPage = () => {
return (
<div className="min-h-screen bg-gray-50 dark:bg-gray-900 py-8 px-4 sm:px-6 lg:px-8 mt-12">
<div className="max-w-7xl mx-auto">

<div className="text-center py-16 bg-white dark:bg-gray-800 rounded-xl shadow-sm">
<h3 className="text-lg font-medium text-gray-900 dark:text-white">
Please login to view notes
</h3>
<p className="mt-1 text-sm text-gray-500 dark:text-gray-400">

You need to be logged in to access academic notes and study
materials.
</p>
Expand Down Expand Up @@ -336,15 +326,12 @@ const NotesPage = () => {
<div>
<label
className="block text-sm font-medium text-gray-700 dark:text-gray-200 mb-1"

htmlFor="year"
>
Academic Year
</label>
<select

className="block w-full pl-3 pr-10 py-2 text-base bg-white dark:bg-gray-700 dark:text-white border-gray-300 dark:border-gray-600 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 sm:text-sm rounded-md border"

id="year"
name="year"
value={filters.year}
Expand All @@ -362,17 +349,13 @@ const NotesPage = () => {
{/* Branch Filter */}
<div>
<label

className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1"

htmlFor="branch"
>
Branch
</label>
<select

className="block w-full pl-3 pr-10 py-2 text-base bg-white dark:bg-gray-700 dark:text-white border-gray-300 dark:border-gray-600 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 sm:text-sm rounded-md border"

id="branch"
name="branch"
value={filters.branch}
Expand All @@ -391,17 +374,13 @@ const NotesPage = () => {
{/* Subject Filter */}
<div>
<label

className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1"

htmlFor="subject"
>
Subject
</label>
<select

className="block w-full pl-3 pr-10 py-2 text-base bg-white dark:bg-gray-700 dark:text-white border-gray-300 dark:border-gray-600 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 sm:text-sm rounded-md border"

id="subject"
name="subject"
value={filters.subject}
Expand Down
8 changes: 5 additions & 3 deletions client/src/pages/PyqsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { Link } from "react-router-dom";
import toast, { Toaster } from "react-hot-toast";
import Spinner from "../components/Spinner";


const PyqsPage = () => {
const [pyqs, setPyqs] = useState([]);
const [loading, setLoading] = useState(true);
Expand Down Expand Up @@ -101,8 +100,11 @@ const PyqsPage = () => {
);
if (!response.ok) throw new Error("Failed to fetch PYQs");

const data = await response.json();

let data = await response.json();
// extract isLastPage and assign notes to data
const isLastPage = data?.isLastPage;
if (isLastPage) setHasMore(!isLastPage);
data = data?.pyqs;
const processedData = data.map((pyq) => ({
...pyq,
uploadedBy: pyq.user || { name: "Unknown" },
Expand Down
Loading
Loading