Skip to content

Commit

Permalink
Merge pull request #31 from swat-sccs/dcrepublic-dev
Browse files Browse the repository at this point in the history
Fix Courseplan name editing, Lighthouse 100, ReEnable Ratings
  • Loading branch information
DCRepublic authored Dec 3, 2024
2 parents 677eea0 + 82e2001 commit c230e01
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 19 deletions.
1 change: 1 addition & 0 deletions app/admin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default function AdminPage() {
let filtered_ratings: any = [];

if (!isLoading) {
console.log(ratings);
for (let rating of ratings) {
const name = rating.User?.name;
const email = rating.User?.email;
Expand Down
5 changes: 1 addition & 4 deletions app/api/submitReview/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export async function POST(request: NextRequest) {
},
});
if (user?.id && theClass && profs) {
/*
const newReview = await prisma.rating.create({
data: {
userId: user?.id,
Expand All @@ -51,7 +50,6 @@ export async function POST(request: NextRequest) {
profBannerId: profs.bannerId,
profUid: profs.uid,
},
});

if (newReview) {
Expand Down Expand Up @@ -107,9 +105,8 @@ export async function POST(request: NextRequest) {
}
}
}
*/
}

//console.log(plans);
return NextResponse.json("Submission Failed, no user", { status: 500 });
return NextResponse.json("Success", { status: 200 });
}
29 changes: 25 additions & 4 deletions components/CreatePlan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { useDebouncedCallback } from "use-debounce";
import { setPlanName } from "../app/actions/setPlanName";
import {
getCourseIds,
getCoursePlans,
getPlanCourses1,
removeCourseFromDBPlan,
} from "app/actions/getCourses";
Expand All @@ -41,6 +42,8 @@ export default function CreatePlan(props: any) {
const pathname = usePathname();
const { data: session, status } = useSession();
const [coursePlanName, setCoursePlanName]: any = useState("");
const [alert, setAlert]: any = useState(undefined);

const [editable, setEditable]: any = useState("");
const [edit, setEdit]: any = useState(false);
const [courses, setCourses] = useState<Course[]>();
Expand All @@ -49,15 +52,21 @@ export default function CreatePlan(props: any) {
);
const [selectedCoursePlan, setSelectedCoursePlan]: any = useState([]);
const [isScrolled, setIsScrolled] = useState(false);

const fetcher = (url: any) => fetch(url).then((r) => r.json());

async function fetchNewData() {
const coursePlans: CoursePlan[] = await getCoursePlans();
setCoursePlans(coursePlans);
}

const handleNameChange = useDebouncedCallback((newName: any, id: string) => {
setPlanName(newName, id);
fetchNewData();
}, 50);

async function createPlan() {
if (coursePlanName) {
setAlert(undefined);
await axios
.post("/api/createplan", {
planName: coursePlanName,
Expand All @@ -66,12 +75,14 @@ export default function CreatePlan(props: any) {
setCoursePlanName("");
setSelectedCoursePlan([response.data.id]);
setPlanCookie(response.data.id);

fetchNewData();
//console.log(response);
})
.catch(function (error) {
console.log(error);
});
} else {
setAlert("A name is required to create a course plan.");
}
}
async function updateLocalPlan() {
Expand Down Expand Up @@ -134,6 +145,7 @@ export default function CreatePlan(props: any) {
if (courses && courses != undefined) {
return courses.map((course: any) => (
<Card
aria-label={course.courseTitle}
key={course.id}
className={
"bg-light_foreground min-h-16 max-h-16 rounded-sm scroll-none drop-shadow-lg transition-colors"
Expand All @@ -155,6 +167,7 @@ export default function CreatePlan(props: any) {
</div>

<Button
aria-label={"Remove " + course.courseTitle + " from plan"}
isIconOnly
startContent={<HighlightOffIcon />}
size={"sm"}
Expand Down Expand Up @@ -216,11 +229,15 @@ export default function CreatePlan(props: any) {
}}
/>
<Button
aria-label="Create new plan! Name required."
startContent={<AddIcon />}
size="md"
onClick={() => createPlan()}
></Button>
</div>
{alert ? (
<div className="mt-2 text-red-500 text-center">{alert}</div>
) : null}
</div>

<div className="grid grid-cols-3 items-center">
Expand Down Expand Up @@ -263,29 +280,32 @@ export default function CreatePlan(props: any) {
) : null}

<Button
aria-label="Delete the current plan"
isIconOnly
size="md"
startContent={<DeleteIcon />}
onClick={deletePlan}
/>
{edit ? (
<Button
aria-label="Save new plan name"
isIconOnly
size="md"
onClick={() => setEdit(false)}
startContent={<SaveIcon />}
/>
) : (
<Button
aria-label="Edit name of course plan"
isIconOnly
size="md"
onClick={() => {
setEdit(true),
setEditable(
props.coursePlans?.find(
coursePlans?.find(
(plan: any) =>
plan.id === parseInt(selectedCoursePlan)
).name
)?.name
);
}}
startContent={<EditIcon />}
Expand All @@ -299,6 +319,7 @@ export default function CreatePlan(props: any) {
className="flex flex-col h-[45vh] overflow-y-scroll gap-3 scrollbar-thin scrollbar-thumb-accent-500 scrollbar-track-transparent"
id="scrollMe"
ref={scrollRef}
aria-label="List of Courses in plan"
>
<CoursesList />
</div>
Expand Down
2 changes: 0 additions & 2 deletions components/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export default function Search(props: any) {
setSelectedDOTW(searchParams.get("dotw")?.toString().split(","));
setSelectedStartTime(searchParams.get("stime")?.toString().split(","));
//handleSelectionChange({ target: { value: selectedTerm } });

}, [searchParams]);

useEffect(() => {
Expand Down Expand Up @@ -140,7 +139,6 @@ export default function Search(props: any) {

return (
<div className="grid grid-cols-9 gap-3 w-[97%]">
<meta name="viewport" content="width=device-width, user-scalable=no" />
<Input
isClearable
className="col-span-9 lg:col-span-3"
Expand Down
19 changes: 12 additions & 7 deletions components/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,18 @@ export const Navbar = (props: any) => {
</NavbarItem>
</NavbarContent>

{/* Mobile?*/}

<NavbarContent className="flex lg:hidden" justify="end">
<ThemeSwitch />
<NavbarMenuToggle
aria-label={isMenuOpen ? "Close menu" : "Open menu"}
/>
<li>
<ThemeSwitch />
</li>
<li>
<NavbarMenuToggle
aria-label={isMenuOpen ? "Close menu" : "Open menu"}
/>
</li>
</NavbarContent>

{/* Mobile?*/}
<NavbarMenu className=" lg:flex">
<div className="mx-4 mt-2 flex flex-col gap-2">
{siteConfig.navItems.map((item, index) => (
Expand All @@ -193,7 +197,7 @@ export const Navbar = (props: any) => {
{session.user?.name || "Account"}
</Button>
</DropdownTrigger>
<DropdownMenu aria-label="Static Actions">
<DropdownMenu aria-label="Signout dropdown">
{/* Causes an awful error if rendered conditionally */}
{/* <DropdownItem key="admin" href="/admin">
Admin
Expand All @@ -205,6 +209,7 @@ export const Navbar = (props: any) => {
</Dropdown>
) : (
<Button
type="button"
variant="bordered"
onClick={() => signIn("keycloak", { callbackUrl: "/" })}
>
Expand Down
4 changes: 2 additions & 2 deletions lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export const config = {

let theRole;

if ("scheduler" in tokenData.resource_access) {
theRole = tokenData.resource_access.scheduler.roles.find(
if ("planner" in tokenData.resource_access) {
theRole = tokenData.resource_access.planner.roles.find(
(role: string) => role === "admin" || "user"
);
} else {
Expand Down

0 comments on commit c230e01

Please sign in to comment.