Skip to content

Commit

Permalink
Set time boundary in api calls for events calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelmdLow committed Nov 14, 2024
1 parent eac6f2a commit b82f43d
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions ubyssey/static_src/src/js/components/Events/calendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ export function QueryEventsCalendar() {
const month = parseInt(urlParams.get("month"));
const year = parseInt(urlParams.get("year"));
return getDate(month, year);
}

else{
} else{
console.log("No month and year");
const today = new Date();
today.setHours(0, 0, 0, 0);
Expand All @@ -115,8 +113,8 @@ export function QueryEventsCalendar() {
start = new Date(start.getTime() + d);
}
return start;
}
}
}
const calculateNewStart = (direction, start) => {
// Set the start date to the first day of the current month
let newStart = new Date(start);
Expand Down Expand Up @@ -201,17 +199,15 @@ export function QueryEventsCalendar() {
const h = m * 60;
const d = h * 24;

const today = new Date();
today.setHours(0, 0, 0, 0);
var start = new Date(today.getTime() - (10*d));
while(start.getDay() != 1) {
start = new Date(start.getTime() + d);
}
let end = new Date(start.getTime() + (4*7+1)*d)
var apiStart = new Date(start.getTime() - d*25);
apiStart.setDate(1);

var apiEnd = new Date(apiStart.getTime() + d*120);
apiEnd.setDate(1);
console.log(String(apiStart) + " " + String(apiEnd));
axios
.get(
'/api/events/?limit=300' //If needed you can increase or decrease the limit to include more or lesser events or add more query parmaters
'/api/events/?limit=300&start_time__gte=' + apiStart.toISOString() + "&end_time__lte=" + apiEnd.toISOString() //2024-10-15T11:00:00-07:00 If needed you can increase or decrease the limit to include more or lesser events or add more query parmaters
)
.then((response) => {
const res = response.data.results;
Expand All @@ -229,7 +225,7 @@ export function QueryEventsCalendar() {
getEvents();
const theme = document.documentElement.getAttribute('color-css-theme');
setIsDarkMode(theme === 'dark');
},[]);
},[start]);

const toggleDarkMode = () => {
setIsDarkMode(prevMode => !prevMode); // Toggle dark mode state
Expand Down

0 comments on commit b82f43d

Please sign in to comment.