Skip to content

Commit

Permalink
User feedback on click, handle faster plan updates
Browse files Browse the repository at this point in the history
  • Loading branch information
DCRepublic committed Nov 30, 2024
1 parent 09f3772 commit 4fb82b9
Show file tree
Hide file tree
Showing 10 changed files with 631 additions and 279 deletions.
14 changes: 14 additions & 0 deletions app/actions/actions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use server";

import prisma from "@/lib/prisma";
import { cookies } from "next/headers";

export async function setPlanCookie(plan: string) {
Expand All @@ -14,3 +15,16 @@ export async function getPlanCookie() {

return out;
}

export async function setSelectedCookie(selected: any) {
(await cookies()).set("selectedCourses", selected);
}

export async function getSelectedCoursesCookie() {
const cookieStore = await cookies();
const plan = cookieStore.get("selectedCourses");

const out = plan ? plan.value : undefined;

return out;
}
106 changes: 91 additions & 15 deletions app/actions/getCourses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { cookies } from "next/headers";
import prisma from "../../lib/prisma";
import { Prisma } from "@prisma/client";
import { auth } from "@/lib/auth";
import { getPlanCookie } from "./actions";
import { getPlanCookie, setSelectedCookie } from "./actions";

export async function getUniqueCodes() {
const codes = await prisma.sectionAttribute.findMany();
Expand Down Expand Up @@ -66,34 +66,84 @@ export async function getPlanCourses1() {
const planCookie: any = await getPlanCookie();
const session = await auth();

return await prisma.coursePlan.findMany({
where: {
AND: {
if (planCookie) {
return await prisma.coursePlan.findUnique({
where: {
User: {
uuid: session?.user.id,
},
//id: parseInt(planCookie),
id: parseInt(planCookie),
},
include: {
courses: true,
},
});
}
return {};
}

export async function removeCourseFromDBPlan(course: any) {
const id: any = await getPlanCookie();
//let DOTW: Array<String> = dotw.split(",");
const updatedCourse = await prisma.coursePlan.update({
where: {
id: parseInt(id),
},
include: {
courses: true,
data: {
courses: {
disconnect: {
id: course.id,
},
},
},
});
getCourseIds();
}

export async function getPlanCourses(planID: any) {
export async function getCourseIds() {
const id: any = await getPlanCookie();
//let DOTW: Array<String> = dotw.split(",");
const output = [];

return await prisma.course.findMany({
where: {
CoursePlan: {
some: {
id: parseInt(planID),
if (id) {
const ids = await prisma.coursePlan.findUnique({
where: {
id: parseInt(id),
},
select: {
courses: {
select: {
id: true,
},
},
},
});

if (ids) {
for (let theid of ids.courses) {
output.push(theid.id);
}
}
}

//setSelectedCookie(output);

return output;
}

export async function updateDBPlan(course: any) {
const id: any = await getPlanCookie();
//let DOTW: Array<String> = dotw.split(",");
const updatedCourse = await prisma.coursePlan.update({
where: {
id: parseInt(id),
},
include: {
CoursePlan: true,
data: {
courses: {
connect: {
id: course.id,
},
},
},
});
}
Expand Down Expand Up @@ -138,6 +188,32 @@ export async function getInitialCourses(
});
}

export async function getCoursePlans() {
const session = await auth();
const user = await prisma.user.findUnique({
where: {
uuid: session?.user?.id,
},
});
let courses: any;

if (user) {
courses = await prisma.coursePlan.findMany({
where: {
User: {
id: user.id,
},
},
include: {
courses: true,
},
});
} else {
courses = null;
}
return courses;
}

export async function getCourses(
take: any,
query: any,
Expand Down
14 changes: 14 additions & 0 deletions app/actions/setPlanName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use server";

import prisma from "@/lib/prisma";

export async function setPlanName(planName: string, id: string) {
const newPlan = await prisma.coursePlan.update({
where: {
id: parseInt(id),
},
data: {
name: planName,
},
});
}
7 changes: 4 additions & 3 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getTerms,
getUniqueStartEndTimes,
getUniqueCodes,
getCoursePlans,
} from "../app/actions/getCourses";
import { redirect } from "next/navigation";
import { CoursePlan } from "@prisma/client";
Expand All @@ -31,7 +32,6 @@ export default async function Page(props: {

if (pagePref && pagePref.value != "/") {
redirect(pagePref.value);

}

const searchParams = await props.searchParams;
Expand All @@ -41,7 +41,8 @@ export default async function Page(props: {
const stime = searchParams?.stime || [];
const homePageProps: any = {};
const initalCourses = await getInitialCourses(query, term, dotw, stime);
const planCourses: CoursePlan[] = await getPlanCourses1();
const planCourses: any = await getPlanCourses1();
const coursePlans: any = await getCoursePlans();

homePageProps["fullCourseList"] = (
<Suspense
Expand Down Expand Up @@ -69,7 +70,7 @@ export default async function Page(props: {
<Skeleton className="rounded-lg w-8/12 h-fit align-top justify-start" />
}
>
<CreatePlan initialPlan={planCourses} />
<CreatePlan initialPlan={planCourses} coursePlans={coursePlans} />
</Suspense>
);

Expand Down
3 changes: 3 additions & 0 deletions app/sw.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { defaultCache } from "@serwist/next/worker";
import type { PrecacheEntry, SerwistGlobalConfig } from "serwist";
import { Serwist } from "serwist";
import { disableDevLogs } from "serwist";

disableDevLogs();

declare global {
interface WorkerGlobalScope extends SerwistGlobalConfig {
Expand Down
Loading

0 comments on commit 4fb82b9

Please sign in to comment.