Skip to content
Snippets Groups Projects
Commit 46bfda46 authored by Konrad Mohrfeldt's avatar Konrad Mohrfeldt :koala:
Browse files

refactor: use API to exclude irrelevant schedules

parent 1201a518
No related branches found
No related tags found
No related merge requests found
...@@ -20,13 +20,9 @@ ...@@ -20,13 +20,9 @@
</thead> </thead>
<tbody> <tbody>
<ScheduleRow <ScheduleRow v-for="schedule in result.items" :key="schedule.id" :schedule="schedule" />
v-for="schedule in relevantSchedules"
:key="schedule.id"
:schedule="schedule"
/>
<tr v-if="relevantSchedules.length === 0"> <tr v-if="result.count === 0">
<td colspan="4"> <td colspan="4">
<p class="tw-text-center tw-py-3 tw-m-0"> <p class="tw-text-center tw-py-3 tw-m-0">
{{ t('showSchedules.noSchedulesAvailable') }} {{ t('showSchedules.noSchedulesAvailable') }}
...@@ -40,14 +36,14 @@ ...@@ -40,14 +36,14 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { parseISO } from 'date-fns'
import { computed } from 'vue'
import { usePaginatedList } from '@rokoli/bnb/drf' import { usePaginatedList } from '@rokoli/bnb/drf'
import { useI18n } from '@/i18n' import { useI18n } from '@/i18n'
import { Schedule, Show } from '@/types'
import ASection from '@/components/generic/ASection.vue'
import { useScheduleStore } from '@/stores/schedules' import { useScheduleStore } from '@/stores/schedules'
import { Show } from '@/types'
import { useQuery } from '@/util'
import ASection from '@/components/generic/ASection.vue'
import ScheduleRow from './ScheduleRow.vue' import ScheduleRow from './ScheduleRow.vue'
defineOptions({ compatConfig: { MODE: 3 } }) defineOptions({ compatConfig: { MODE: 3 } })
...@@ -58,22 +54,10 @@ const props = defineProps<{ ...@@ -58,22 +54,10 @@ const props = defineProps<{
const { t } = useI18n() const { t } = useI18n()
const scheduleStore = useScheduleStore() const scheduleStore = useScheduleStore()
const { result: schedule } = usePaginatedList(scheduleStore.listIsolated, 1, 100, { const { result } = usePaginatedList(scheduleStore.listIsolated, 1, 100, {
query: () => new URLSearchParams({ showIds: props.show.id.toString() }), query: useQuery(() => ({
showIds: props.show.id,
excludeInactive: '1',
})),
}) })
const relevantSchedules = computed(() =>
schedule.value.items.filter((s) => !isPossiblyPastSchedule(s)),
)
function isPossiblyPastSchedule(schedule: Schedule) {
// Recurrence rules get complex very fast, so we only give
// a definitive answer if a lastDate is set for this schedule.
if (!schedule.lastDate) {
return false
}
const lastDate = parseISO(schedule.lastDate)
const [hours, minutes, seconds] = (schedule.endTime ?? '00:00:00').split(':')
lastDate.setHours(parseInt(hours ?? '0'), parseInt(minutes ?? '0'), parseInt(seconds ?? '0'))
return new Date() > lastDate
}
</script> </script>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment