Added Calendar store

This commit is contained in:
Laurent
2025-03-09 21:44:26 +01:00
parent 0827bf512c
commit 495f83e56c
3 changed files with 38 additions and 4 deletions

View File

@@ -23,9 +23,9 @@
function selectDay(event : Event, day : number | null){
if(!(event.target instanceof HTMLElement) || day == null) return;
event.target.classList.toggle("item-selected");
calendar.setDay(day);
datePicker.select(calendar.getDate());
event.target.classList.toggle("item-selected");
}
function clickPrev(){

View File

@@ -0,0 +1,24 @@
export abstract class ArrayHelper {
public static contains(array : any[], element : any) : boolean {
return array.indexOf(element) > -1;
}
public static indexOf(array : any[], element : any) : number {
return array.indexOf(element);
}
public static toggleElement(array : any[], element : any) : void {
let index = ArrayHelper.indexOf(array, element);
console.log(index);
if(index < 0) {
console.log("Not in array")
array.push(element);
} else {
console.log("Already in array")
array.splice(index, 1);
}
}
}

View File

@@ -1,13 +1,23 @@
import { defineStore } from 'pinia'
import { ArrayHelper} from "@/helpers/ArrayHelper.ts";
export const datePickerStore = defineStore('datePicker', {
state: () => {
return { from: new Date(), to: new Date() }
return { dates: [] as number[] }
},
actions: {
select(date : Date) {
this.from = date < this.from ? date : this.from;
this.to = date > this.to ? date : this.to;
toggleElement(this.dates, date.getTime());
console.log(this.dates);
},
},
})
function toggleElement(arr : any[], element:any) : void {
let index = ArrayHelper.indexOf(arr, element);
if (index < 0) {
arr.push(element);
} else {
arr.splice(index, 1);
}
}