Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kan 79/save mods #51

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat(display ganttchart): Sidebar now display which campus it is on
  • Loading branch information
NguyenDonLam committed Oct 14, 2024
commit 14bfa82f9da25af7900d1a6421e4e08dd68d8c03
6 changes: 1 addition & 5 deletions frontend/src/components/GanttChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export default function GanttChart() {
const groups = useRef(new DataSet<GanttGroup>());
const moddedUnits = useRef<Unit[]>([]);
const [open, setOpen] = useState(false);
// console.log("modded is", moddedUnits);
let campusSolutions: TimetableSolution[];
let check: string | null = sessionStorage.getItem("campusSolutions");
if (check !== null) {
Expand Down Expand Up @@ -70,6 +69,7 @@ export default function GanttChart() {
remove: false, // delete an item by tapping the delete button top right
overrideItems: false, // allow these options to override item.editable
},
showCurrentTime: false,
};

// Initialize the timeline
Expand Down Expand Up @@ -161,7 +161,6 @@ export default function GanttChart() {
}
moddedUnits.current.push(modded);
}
console.log(moddedUnits.current);
}
}

Expand Down Expand Up @@ -226,7 +225,6 @@ export default function GanttChart() {
const saveData = async () => {
try {
setOpen(true);
console.log("fetching: ", JSON.stringify(moddedUnits.current));
const response = await fetch(REMOTE_API_URL + "/timetabling/update", {
method: "PUT",
headers: {
Expand All @@ -240,7 +238,6 @@ export default function GanttChart() {
}
// Clear moddedUnits if the first fetch was successful
moddedUnits.current = [];
console.log("Clearing modded", moddedUnits.current.length);

// Second fetch request (GET) only runs after the first one completes
const viewResponse = await fetch(REMOTE_API_URL + "/timetabling/view", {
Expand All @@ -259,7 +256,6 @@ export default function GanttChart() {
"campusSolutions",
JSON.stringify(timetableSolutions)
);
console.log("DONE");
setOpen(false);
} catch (error) {
console.error("Error saving data:", error);
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/components/ModSiderbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Routes, Route, Link } from "react-router-dom";

import GanttChart from "./GanttChart";
import { TimetableSolution } from "../scripts/api";
import { useState } from "react";

interface SidebarProps {
marginTop: number;
Expand All @@ -17,6 +18,12 @@ interface SidebarProps {
const drawerWidth = 240;

export default function ModSidebar({ marginTop, width }: SidebarProps) {
const [selectedCampus, setSelectedCampus] = useState(null);

const handleItemClick = (campusName) => {
setSelectedCampus(campusName); // Update the selected campus
};

let campusSolutions: TimetableSolution[];
let campusSolutionsStr: string|null = sessionStorage.getItem("campusSolutions");
if (campusSolutionsStr !== null) {
Expand Down Expand Up @@ -48,6 +55,13 @@ export default function ModSidebar({ marginTop, width }: SidebarProps) {
<ListItemButton
component={Link}
to={`/timetablemod/${campusName.toLowerCase()}`}
onClick={() => handleItemClick(campusName)}
sx={{
backgroundColor:
selectedCampus === campusName
? "lightgrey"
: "transparent",
}}
>
<ListItemIcon>
<InboxIcon />
Expand Down