Skip to content

Commit

Permalink
Do not render opening state when data is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
Siilwyn committed Sep 15, 2023
1 parent 2c67520 commit 82b5ea1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/components/CardStatus/CardStatus.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<ClientOnly>
<p
v-if="openingHours"
class="card-status"
:class="{ 'card-status--open': isOpen }"
v-bind="$attrs"
Expand Down Expand Up @@ -32,13 +33,13 @@ export default {
<script setup lang="ts">
import type { OpeningHours } from "~/types/OpeningHours";
const props = defineProps<{ openingHours: OpeningHours[] }>();
const props = defineProps<{ openingHours?: OpeningHours[] }>();
const isOpen = computed(() => {
const now = new Date();
const dayNames = ["su", "mo", "tu", "we", "th", "fr", "sa"];
const indexToday = dayNames[now.getDay()];
const openingHoursToday = props.openingHours?.find(({ day }) => day === indexToday).time;
const openingHoursToday = props.openingHours?.find(({ day }) => day === indexToday)?.time;
return openingHoursToday?.some(([startTime, endTime]) => {
return now >= new Date(startTime) && now <= new Date(endTime);
Expand Down
5 changes: 3 additions & 2 deletions src/types/Building.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ export interface BuildingI18n {
totalSeats: number;
totalSpaces: number;
totalRooms: number;
openingHours: OpeningHours[];

activeDevices?: number;

// Client-side loading
occupancy?: Occupancy | undefined;
openingHours?: OpeningHours[];
}

export type CsvAndCmsBuildingData = Omit<
Expand Down

0 comments on commit 82b5ea1

Please sign in to comment.