Skip to content

Commit f51d500

Browse files
committed
Fix tags and Fix the bug where the window reloads after timetable creation
1 parent f6f4cfd commit f51d500

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

course-matrix/frontend/src/api/baseApiSlice.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ const baseQuery = fetchBaseQuery({ baseUrl: BASE_URL });
55

66
export const apiSlice = createApi({
77
baseQuery,
8-
tagTypes: ["Auth", "Course", "Department", "Offering", "Timetable", "Event"],
8+
tagTypes: ["Auth", "Course", "Department", "Offering", "Timetable", "Event", "Restrictions"],
99
endpoints: () => ({}),
1010
});

course-matrix/frontend/src/api/eventsApiSlice.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ export const eventsApiSlice = apiSlice.injectEndpoints({
1313
"Content-Type": "application/json",
1414
Accept: "application/json, text/plain, */*",
1515
},
16-
providesTags: ["Event"],
1716
body: data,
1817
credentials: "include",
1918
}),
19+
invalidatesTags: ["Event"],
2020
}),
2121
getEvents: builder.query<unknown, number>({
2222
query: (id) => ({
@@ -38,10 +38,10 @@ export const eventsApiSlice = apiSlice.injectEndpoints({
3838
"Content-Type": "application/json",
3939
Accept: "application/json, text/plain, */*",
4040
},
41-
providesTags: ["Event"],
4241
body: data,
4342
credentials: "include",
4443
}),
44+
invalidatesTags: ["Event"],
4545
}),
4646
deleteEvent: builder.mutation({
4747
query: (id) => ({
@@ -51,9 +51,9 @@ export const eventsApiSlice = apiSlice.injectEndpoints({
5151
"Content-Type": "application/json",
5252
Accept: "application/json, text/plain, */*",
5353
},
54-
providesTags: ["Event"],
5554
credentials: "include",
5655
}),
56+
invalidatesTags: ["Event"],
5757
}),
5858
}),
5959
});

course-matrix/frontend/src/api/restrictionsApiSlice.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ export const restrictionsApiSlice = apiSlice.injectEndpoints({
2424
"Content-Type": "application/json",
2525
Accept: "application/json, text/plain, */*",
2626
},
27-
providesTags: ["Restrictions"],
2827
body: data,
2928
credentials: "include",
3029
}),
30+
invalidatesTags: ["Restrictions"],
3131
}),
3232
deleteRestriction: builder.mutation({
3333
query: (id) => ({
@@ -37,9 +37,9 @@ export const restrictionsApiSlice = apiSlice.injectEndpoints({
3737
"Content-Type": "application/json",
3838
Accept: "application/json, text/plain, */*",
3939
},
40-
providesTags: ["Restrictions"],
4140
credentials: "include",
4241
}),
42+
invalidatesTags: ["Restrictions"],
4343
}),
4444
}),
4545
});

course-matrix/frontend/src/api/timetableApiSlice.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ export const timetableApiSlice = apiSlice.injectEndpoints({
1212
"Content-Type": "application/json",
1313
Accept: "application/json, text/plain, */*",
1414
},
15-
providesTags: ["Timetable"],
1615
body: data,
1716
credentials: "include",
1817
}),
18+
invalidatesTags: ["Timetable"],
1919
}),
2020
getTimetables: builder.query<unknown, void>({
2121
query: () => ({
@@ -28,6 +28,7 @@ export const timetableApiSlice = apiSlice.injectEndpoints({
2828
providesTags: ["Timetable"],
2929
credentials: "include",
3030
}),
31+
keepUnusedDataFor: 0,
3132
}),
3233
updateTimetable: builder.mutation({
3334
query: (data) => ({
@@ -37,10 +38,10 @@ export const timetableApiSlice = apiSlice.injectEndpoints({
3738
"Content-Type": "application/json",
3839
Accept: "application/json, text/plain, */*",
3940
},
40-
providesTags: ["Timetable"],
4141
body: data,
4242
credentials: "include",
4343
}),
44+
invalidatesTags: ["Timetable"],
4445
}),
4546
deleteTimetable: builder.mutation({
4647
query: (id) => ({
@@ -50,9 +51,9 @@ export const timetableApiSlice = apiSlice.injectEndpoints({
5051
"Content-Type": "application/json",
5152
Accept: "application/json, text/plain, */*",
5253
},
53-
providesTags: ["Timetable"],
5454
credentials: "include",
5555
}),
56+
invalidatesTags: ["Timetable"],
5657
}),
5758
}),
5859
});

course-matrix/frontend/src/pages/TimetableBuilder/Calendar.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ import { TimetableFormSchema } from "@/models/timetable-form";
2828
import {
2929
useCreateTimetableMutation,
3030
useDeleteTimetableMutation,
31+
useGetTimetablesQuery,
3132
} from "@/api/timetableApiSlice";
3233
import { useCreateRestrictionMutation } from "@/api/restrictionsApiSlice";
3334
import { z } from "zod";
3435
import { useEffect, useState } from "react";
3536
import { useGetNumberOfCourseSectionsQuery } from "@/api/coursesApiSlice";
3637
import { useCreateEventMutation } from "@/api/eventsApiSlice";
37-
import { useSearchParams } from "react-router-dom";
38+
import { useNavigate, useSearchParams } from "react-router-dom";
3839
import { Event, Timetable } from "@/utils/type-utils";
3940

4041
interface CalendarProps {
@@ -74,6 +75,7 @@ function Calendar({
7475
userEvents,
7576
form,
7677
}: CalendarProps) {
78+
const navigate = useNavigate();
7779
const [queryParams] = useSearchParams();
7880
const isEditingTimetable = queryParams.has("edit");
7981
const timetableId = parseInt(queryParams.get("edit") ?? "0");
@@ -163,6 +165,7 @@ function Calendar({
163165
});
164166
if (error) {
165167
console.error(error);
168+
return;
166169
}
167170

168171
// Create course events for the newly created timetable
@@ -200,9 +203,8 @@ function Calendar({
200203
});
201204
await Promise.all(restrictionPromises);
202205

203-
// Refresh the page and redirect to the home page to see the newly created timetable
204-
window.location.reload();
205-
window.location.href = "/home";
206+
// Redirect to the home page to see the newly created timetable
207+
navigate("/home");
206208
};
207209

208210
const handleUpdate = async () => {
@@ -284,4 +286,4 @@ function Calendar({
284286
);
285287
}
286288

287-
export default Calendar;
289+
export default Calendar;

0 commit comments

Comments
 (0)