diff --git a/src/components/Calendar.vue b/src/components/Calendar.vue index 24a8009..9e73fa3 100644 --- a/src/components/Calendar.vue +++ b/src/components/Calendar.vue @@ -4,6 +4,7 @@ import {ref, onMounted, watch} from "vue"; import { datePickerStore } from "@/stores/CalendarStore.ts"; import { Calendar } from "@/models/Calendar.ts"; + import router from "@/router"; const calendar = new Calendar(); const datePicker = datePickerStore(); @@ -25,6 +26,19 @@ calendar.setDay(day); toggleSelectedDay(event.target.id, calendar.getDate()); highlightSelectedDay(event.target); + checkConsistency(); + } + + function checkConsistency(){ + + let selected = selectedDays.value; + let stored = datePicker.value; + + if(selected.size != stored.length){ + datePicker.clear(); + selected.clear(); + router.push('/error') + } } function toggleSelectedDay(id : string, date : Date) : void { diff --git a/src/router/index.ts b/src/router/index.ts index 61e4dca..22319a3 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -12,6 +12,7 @@ const router = createRouter({ { path: '/about', name: 'about', component: AboutView}, { path: '/create', name: 'create', component: CreateView}, { path: '/join', name: 'join', component: JoinView}, + { path: '/error', name: 'error', component: ErrorView}, { path: '/:pathMatch(.*)*', component: ErrorView } ] }) diff --git a/src/stores/CalendarStore.ts b/src/stores/CalendarStore.ts index f49b3f5..64a42f6 100644 --- a/src/stores/CalendarStore.ts +++ b/src/stores/CalendarStore.ts @@ -5,10 +5,15 @@ export const datePickerStore = defineStore('datePicker', { state: () => { return { dates: [] as TimeStamp[] } }, + getters: { + value: (state) : TimeStamp[] => state.dates as TimeStamp[], + }, actions: { - update(dates : Date[]) { + update(dates : Date[]) : void { this.dates = dates.map(date => new TimeStamp(date)); - console.log(this.dates); + }, + clear() : void { + this.dates = [] as TimeStamp[]; }, }, })