Skip to content

Commit

Permalink
Merge branch '331-staging' of github.com:devsoc-unsw/circles into 331…
Browse files Browse the repository at this point in the history
…-staging
  • Loading branch information
ChinoGoblino committed Nov 17, 2024
2 parents d30ef21 + b819165 commit aa7aa00
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 28 deletions.
1 change: 1 addition & 0 deletions backend/server/routers/utility/oidc/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ def validate_id_token(token: str, access_token: str) -> DecodedIDToken:
audience=CLIENT_ID,
issuer=config["issuer"],
options={ "verify_signature": True },
leeway=5,
)
except jwt.exceptions.InvalidTokenError as e:
raise OIDCValidationError(
Expand Down
68 changes: 40 additions & 28 deletions frontend/src/pages/TermPlanner/TermPlanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import openNotification from 'utils/openNotification';
import PageTemplate from 'components/PageTemplate';
import Spinner from 'components/Spinner';
import { LIVE_YEAR } from 'config/constants';
import useIdentity from 'hooks/useIdentity';
import useSettings from 'hooks/useSettings';
import { GridItem } from './common/styles';
import HideYearTooltip from './HideYearTooltip';
Expand Down Expand Up @@ -70,6 +71,8 @@ const TermPlanner = () => {
const [draggingCourse, setDraggingCourse] = useState('');
const { hiddenYears } = useSettings();

const { userId } = useIdentity();

const queryClient = useQueryClient();
const plannerPicRef = useRef<HTMLDivElement>(null);

Expand Down Expand Up @@ -120,17 +123,20 @@ const TermPlanner = () => {
const setPlannedCourseToTermMutation = useSetPlannedCourseToTermMutation({
mutationOptions: {
onMutate: (data) => {
// TODO-olli
queryClient.setQueryData(['planner'], (prev: PlannerResponse | undefined) => {
if (!prev) return badPlanner;
const curr: PlannerResponse = structuredClone(prev);
curr.years[data.srcRow][data.srcTerm].splice(
curr.years[data.srcRow][data.srcTerm].indexOf(data.courseCode),
1
);
curr.years[data.destRow][data.destTerm].splice(data.destIndex, 0, data.courseCode);
return curr;
});
// TODO: match these keys with queries.ts
queryClient.setQueryData(
['user', userId, 'planner'],
(prev: PlannerResponse | undefined) => {
if (!prev) return badPlanner;
const curr: PlannerResponse = structuredClone(prev);
curr.years[data.srcRow][data.srcTerm].splice(
curr.years[data.srcRow][data.srcTerm].indexOf(data.courseCode),
1
);
curr.years[data.destRow][data.destTerm].splice(data.destIndex, 0, data.courseCode);
return curr;
}
);
}
}
});
Expand All @@ -143,13 +149,16 @@ const TermPlanner = () => {
mutationOptions: {
onMutate: (data) => {
// TODO-olli
queryClient.setQueryData(['planner'], (prev: PlannerResponse | undefined) => {
if (!prev) return badPlanner;
const curr: PlannerResponse = structuredClone(prev);
curr.unplanned.splice(curr.unplanned.indexOf(data.courseCode), 1);
curr.years[data.destRow][data.destTerm].splice(data.destIndex, 0, data.courseCode);
return curr;
});
queryClient.setQueryData(
['user', userId, 'planner'],
(prev: PlannerResponse | undefined) => {
if (!prev) return badPlanner;
const curr: PlannerResponse = structuredClone(prev);
curr.unplanned.splice(curr.unplanned.indexOf(data.courseCode), 1);
curr.years[data.destRow][data.destTerm].splice(data.destIndex, 0, data.courseCode);
return curr;
}
);
}
}
});
Expand All @@ -162,16 +171,19 @@ const TermPlanner = () => {
mutationOptions: {
onMutate: (data) => {
// TODO-olli: remove from here...
queryClient.setQueryData(['planner'], (prev: PlannerResponse | undefined) => {
if (!prev) return badPlanner;
const curr: PlannerResponse = structuredClone(prev);
curr.years[data.srcRow as number][data.srcTerm as string].splice(
curr.years[data.srcRow as number][data.srcTerm as string].indexOf(data.courseCode),
1
);
curr.unplanned.push(data.courseCode);
return curr;
});
queryClient.setQueryData(
['user', userId, 'planner'],
(prev: PlannerResponse | undefined) => {
if (!prev) return badPlanner;
const curr: PlannerResponse = structuredClone(prev);
curr.years[data.srcRow as number][data.srcTerm as string].splice(
curr.years[data.srcRow as number][data.srcTerm as string].indexOf(data.courseCode),
1
);
curr.unplanned.push(data.courseCode);
return curr;
}
);
}
}
});
Expand Down

0 comments on commit aa7aa00

Please sign in to comment.