Add consistency check just in case

This commit is contained in:
Laurent
2025-03-10 20:22:07 +01:00
parent f7b52334bd
commit d97b306c32
3 changed files with 22 additions and 2 deletions

View File

@@ -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 {

View File

@@ -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 }
]
})

View File

@@ -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[];
},
},
})