pagination updates; fix subject name in lesson list
This commit is contained in:
parent
3754ea4c28
commit
9c9d1e8ae4
2697
package-lock.json
generated
2697
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -28,6 +28,7 @@
|
|||||||
"react-hook-form": "^7.52.2",
|
"react-hook-form": "^7.52.2",
|
||||||
"react-toastify": "^10.0.5",
|
"react-toastify": "^10.0.5",
|
||||||
"recharts": "^2.12.7",
|
"recharts": "^2.12.7",
|
||||||
|
"tldraw": "^4.4.0",
|
||||||
"zod": "^3.23.8"
|
"zod": "^3.23.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@ -6,9 +6,21 @@ import { useRouter } from "next/navigation";
|
|||||||
const Pagination = ({ page, count }: { page: number; count: number }) => {
|
const Pagination = ({ page, count }: { page: number; count: number }) => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
const totalPages = Math.ceil(count / ITEM_PER_PAGE);
|
||||||
const hasPrev = ITEM_PER_PAGE * (page - 1) > 0;
|
const hasPrev = ITEM_PER_PAGE * (page - 1) > 0;
|
||||||
const hasNext = ITEM_PER_PAGE * (page - 1) + ITEM_PER_PAGE < count;
|
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 changePage = (newPage: number) => {
|
||||||
const params = new URLSearchParams(window.location.search);
|
const params = new URLSearchParams(window.location.search);
|
||||||
params.set("page", newPage.toString());
|
params.set("page", newPage.toString());
|
||||||
@ -26,25 +38,27 @@ const Pagination = ({ page, count }: { page: number; count: number }) => {
|
|||||||
Prev
|
Prev
|
||||||
</button>
|
</button>
|
||||||
<div className="flex items-center gap-2 text-sm">
|
<div className="flex items-center gap-2 text-sm">
|
||||||
{Array.from(
|
{pages.map((p, index) => {
|
||||||
{ length: Math.ceil(count / ITEM_PER_PAGE) },
|
if (typeof p === "string") {
|
||||||
(_, index) => {
|
|
||||||
const pageIndex = index + 1;
|
|
||||||
return (
|
return (
|
||||||
<button
|
<span key={`ellipsis-${index}`} className="px-2">
|
||||||
key={pageIndex}
|
...
|
||||||
className={`px-2 rounded-sm ${
|
</span>
|
||||||
page === pageIndex ? "bg-lamaSky" : ""
|
|
||||||
}`}
|
|
||||||
onClick={() => {
|
|
||||||
changePage(pageIndex);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{pageIndex}
|
|
||||||
</button>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
)}
|
return (
|
||||||
|
<button
|
||||||
|
key={p}
|
||||||
|
className={`px-2 rounded-sm ${page === p ? "bg-lamaSky" : ""
|
||||||
|
}`}
|
||||||
|
onClick={() => {
|
||||||
|
changePage(p);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{p}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
className="py-2 px-4 rounded-md bg-slate-200 text-xs font-semibold disabled:opacity-50 disabled:cursor-not-allowed"
|
className="py-2 px-4 rounded-md bg-slate-200 text-xs font-semibold disabled:opacity-50 disabled:cursor-not-allowed"
|
||||||
|
|||||||
@ -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;
|
||||||
|
$$;
|
||||||
Loading…
x
Reference in New Issue
Block a user