Selecte courseSession from route query for dueDates

This commit is contained in:
Daniel Egger 2024-04-19 11:38:28 +02:00
parent 4925c1a178
commit e7ea2f8922
2 changed files with 25 additions and 12 deletions

View File

@ -7,7 +7,6 @@ import dayjs from "dayjs";
const props = defineProps<{
dueDate: DashboardDueDate;
singleLine?: boolean;
showCourseSession?: boolean;
}>();
const { t } = useTranslation();

View File

@ -6,11 +6,12 @@ import ItDropdownSelect from "@/components/ui/ItDropdownSelect.vue";
import { computed, ref, watch } from "vue";
import { useTranslation } from "i18next-vue";
import _ from "lodash";
import DueDatesList from "@/components/dueDates/DueDatesList.vue";
import { useRouteQuery } from "@vueuse/router";
import DueDateSingle from "@/components/dueDates/DueDateSingle.vue";
log.debug("DashboardPersonsPage created");
const UNFILTERED = Number.MAX_SAFE_INTEGER.toString();
const UNFILTERED = "0";
type DropboxItem = {
id: string;
@ -74,8 +75,27 @@ const courseSessions = computed(() => {
];
});
const selectedSessionRouteQuery = useRouteQuery("session");
const selectedSession = ref<DropboxItem>(courseSessions.value[0]);
watch(selectedSession, () => {
selectedSessionRouteQuery.value = selectedSession.value.id;
});
watch(courseSessions, () => {
if (courseSessions.value.length > 0 && selectedSessionRouteQuery.value) {
// preselect session from route query
const selectedSessionFromRoute = courseSessions.value.find(
(cs) => cs.id === selectedSessionRouteQuery.value
);
if (selectedSessionFromRoute) {
selectedSession.value = selectedSessionFromRoute;
return;
}
}
selectedSession.value = courseSessions.value[0];
});
const filteredDueDates = computed(() => {
return _.orderBy(
dashboardDueDates.value
@ -247,15 +267,9 @@ watch(selectedCourse, async () => {
</section>
<section>
<DueDatesList
:show-top-border="false"
:show-bottom-border="false"
:due-dates="filteredDueDates"
:show-all-due-dates-link="false"
:max-count="100"
data-cy="due-date-list"
:show-course-session="true"
/>
<div v-for="dueDate in filteredDueDates" :key="dueDate.id" class="border-b">
<DueDateSingle :single-line="true" :due-date="dueDate"></DueDateSingle>
</div>
</section>
</div>
</div>