pagination updates; fix subject name in lesson list

This commit is contained in:
Kevin Carter 2026-03-01 20:37:16 +00:00
parent 3754ea4c28
commit 9c9d1e8ae4
12 changed files with 2697 additions and 66 deletions

2697
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -28,6 +28,7 @@
"react-hook-form": "^7.52.2",
"react-toastify": "^10.0.5",
"recharts": "^2.12.7",
"tldraw": "^4.4.0",
"zod": "^3.23.8"
},
"devDependencies": {
@ -43,4 +44,4 @@
"tsx": "^4.21.0",
"typescript": "^5"
}
}
}

View File

@ -6,9 +6,21 @@ import { useRouter } from "next/navigation";
const Pagination = ({ page, count }: { page: number; count: number }) => {
const router = useRouter();
const totalPages = Math.ceil(count / ITEM_PER_PAGE);
const hasPrev = ITEM_PER_PAGE * (page - 1) > 0;
const hasNext = ITEM_PER_PAGE * (page - 1) + ITEM_PER_PAGE < count;
let pages: (number | string)[] = [];
if (totalPages <= 7) {
pages = Array.from({ length: totalPages }, (_, i) => i + 1);
} else if (page <= 3) {
pages = [1, 2, 3, 4, "...", totalPages];
} else if (page >= totalPages - 2) {
pages = [1, "...", totalPages - 3, totalPages - 2, totalPages - 1, totalPages];
} else {
pages = [1, "...", page - 1, page, page + 1, "...", totalPages];
}
const changePage = (newPage: number) => {
const params = new URLSearchParams(window.location.search);
params.set("page", newPage.toString());
@ -26,25 +38,27 @@ const Pagination = ({ page, count }: { page: number; count: number }) => {
Prev
</button>
<div className="flex items-center gap-2 text-sm">
{Array.from(
{ length: Math.ceil(count / ITEM_PER_PAGE) },
(_, index) => {
const pageIndex = index + 1;
{pages.map((p, index) => {
if (typeof p === "string") {
return (
<button
key={pageIndex}
className={`px-2 rounded-sm ${
page === pageIndex ? "bg-lamaSky" : ""
}`}
onClick={() => {
changePage(pageIndex);
}}
>
{pageIndex}
</button>
<span key={`ellipsis-${index}`} className="px-2">
...
</span>
);
}
)}
return (
<button
key={p}
className={`px-2 rounded-sm ${page === p ? "bg-lamaSky" : ""
}`}
onClick={() => {
changePage(p);
}}
>
{p}
</button>
);
})}
</div>
<button
className="py-2 px-4 rounded-md bg-slate-200 text-xs font-semibold disabled:opacity-50 disabled:cursor-not-allowed"

View File

@ -0,0 +1,17 @@
-- Update the auth_user_subjects RLS Helper Function to include subjects of lessons taught by the teacher
CREATE OR REPLACE FUNCTION auth_user_subjects() RETURNS SETOF integer LANGUAGE plpgsql SECURITY DEFINER SET search_path = public STABLE AS $$
BEGIN
RETURN QUERY
SELECT "subjectId" FROM "TeacherSubject" WHERE "teacherId" = requesting_user_id() AND requesting_user_role() = 'teacher'
UNION
SELECT "subjectId" FROM "Lesson" WHERE "teacherId" = requesting_user_id() AND requesting_user_role() = 'teacher'
UNION
SELECT "subjectId" FROM "Lesson" WHERE "classId" IN (
SELECT "classId" FROM "Student" WHERE id = requesting_user_id() AND requesting_user_role() = 'student'
)
UNION
SELECT "subjectId" FROM "Lesson" WHERE "classId" IN (
SELECT "classId" FROM "Student" WHERE "parentId" = requesting_user_id() AND requesting_user_role() = 'parent'
);
END;
$$;