Skip to content

Commit

Permalink
Merge pull request #6535 from pmattmann/bugfix/router-xxxFromRoute
Browse files Browse the repository at this point in the history
router.js do not load all entities, when Id is missing
  • Loading branch information
pmattmann authored Dec 25, 2024
2 parents 486eecd + 4b2dc35 commit 14a06d9
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions frontend/src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,9 @@ async function requireChecklist(to, from, next) {
}

export function campFromRoute(route) {
if (!route.params.campId) {
return undefined
}
return apiStore.get().camps({ id: route.params.campId })
}

Expand All @@ -712,24 +715,39 @@ export function invitationFromInviteKey(inviteKey) {
}

export function periodFromRoute(route) {
if (!route.params.periodId) {
return undefined
}
return apiStore.get().periods({ id: route.params.periodId })
}

function scheduleEntryFromRoute(route) {
if (!route.params.scheduleEntryId) {
return undefined
}
return apiStore.get().scheduleEntries({ id: route.params.scheduleEntryId })
}

function categoryFromRoute(route) {
if (!route.params.categoryId) {
return undefined
}
return campFromRoute(route)
.categories()
.allItems.find((c) => c.id === route.params.categoryId)
}

export function materialListFromRoute(route) {
if (!route.params.materialId) {
return undefined
}
return apiStore.get().materialLists({ id: route.params.materialId })
}

export function checklistFromRoute(route) {
if (!route.params.checklistId) {
return undefined
}
return campFromRoute(route)
.checklists()
.allItems.find((c) => c.id === route.params.checklistId)
Expand All @@ -755,6 +773,9 @@ function getContentLayout(route) {
}

function dayFromScheduleEntryInRoute(route) {
if (!route.params.scheduleEntryId) {
return undefined
}
return apiStore.get().scheduleEntries({ id: route.params.scheduleEntryId }).day()
}

Expand Down Expand Up @@ -934,6 +955,9 @@ export function checklistOverviewRoute(camp, checklist, query = {}) {
}

async function firstFuturePeriod(route) {
if (!route.params.campId) {
return undefined
}
const periods = await apiStore.get().camps({ id: route.params.campId }).periods()._meta
.load
// Return the first period that hasn't ended, or if no such period exists, return the first period
Expand Down

0 comments on commit 14a06d9

Please sign in to comment.