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

Fix schedule event previews #441

Merged
merged 2 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 8 additions & 6 deletions frontend/src/components/ScheduleCreation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -479,13 +479,15 @@ const scheduledRangeMinutes = computed(() => {
return end.diff(start, 'minutes');
});

// generate time slots from current schedule configuration
const getSlots = () => {
// generate time slots from current schedule configuration for the displayed month
const getSlotPreviews = () => {
const slots = [];
// Add 1 week to the end of month here to display slots in displayed next month days too
const end = scheduleInput.value.end_date
? dj.min(dj(scheduleInput.value.end_date), dj(props.activeDate).endOf('month'))
: dj(props.activeDate).endOf('month');
let pointerDate = dj.max(dj(scheduleInput.value.start_date), dj(props.activeDate).startOf('month'));
? dj.min(dj(scheduleInput.value.end_date), dj(props.activeDate).endOf('month').add(1, 'week'))
: dj(props.activeDate).endOf('month').add(1, 'week');
// Substract one week from the start to display slots in displayed previous month days too
let pointerDate = dj.max(dj(scheduleInput.value.start_date), dj(props.activeDate).startOf('month').subtract(1, 'week'));
while (pointerDate <= end) {
if (scheduleInput.value.weekdays?.includes(pointerDate.isoWeekday())) {
slots.push({
Expand All @@ -508,7 +510,7 @@ const getScheduleAppointment = () => ({
location_url: scheduleInput.value.location_url,
details: scheduleInput.value.details,
status: 2,
slots: getSlots(),
slots: getSlotPreviews(),
type: 'schedule',
});

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/views/ScheduleView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ const schedules = ref([]);
const firstSchedule = computed(() => (schedules.value?.length > 0 ? schedules.value[0] : null));
const schedulesReady = ref(false);
const getFirstSchedule = async () => {
calendarEvents.value = [];
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find any reason to keep this here. This was the cause for calendar events to disappear on schedule save.

// trailing slash to prevent fast api redirect which doesn't work great on our container setup
const { data } = await call('schedule/').get().json();
schedules.value = data.value;
Expand All @@ -107,6 +106,8 @@ const onDateChange = (dateObj) => {
const start = dj(dateObj.start);
const end = dj(dateObj.end);

activeDate.value = start.add(end.diff(start, 'minutes')/2, 'minutes');
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're now updating the selected date on navigation too, to keep the event generation in sync with the view


// remote data is retrieved per month, so a data request happens as soon as the user navigates to a different month
if (
dj(activeDateRange.value.end).format('YYYYMM') !== dj(end).format('YYYYMM')
Expand Down