Added Calendar store
This commit is contained in:
@@ -23,9 +23,9 @@
|
|||||||
|
|
||||||
function selectDay(event : Event, day : number | null){
|
function selectDay(event : Event, day : number | null){
|
||||||
if(!(event.target instanceof HTMLElement) || day == null) return;
|
if(!(event.target instanceof HTMLElement) || day == null) return;
|
||||||
event.target.classList.toggle("item-selected");
|
|
||||||
calendar.setDay(day);
|
calendar.setDay(day);
|
||||||
datePicker.select(calendar.getDate());
|
datePicker.select(calendar.getDate());
|
||||||
|
event.target.classList.toggle("item-selected");
|
||||||
}
|
}
|
||||||
|
|
||||||
function clickPrev(){
|
function clickPrev(){
|
||||||
|
|||||||
24
src/helpers/ArrayHelper.ts
Normal file
24
src/helpers/ArrayHelper.ts
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,13 +1,23 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
|
import { ArrayHelper} from "@/helpers/ArrayHelper.ts";
|
||||||
|
|
||||||
export const datePickerStore = defineStore('datePicker', {
|
export const datePickerStore = defineStore('datePicker', {
|
||||||
state: () => {
|
state: () => {
|
||||||
return { from: new Date(), to: new Date() }
|
return { dates: [] as number[] }
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
select(date : Date) {
|
select(date : Date) {
|
||||||
this.from = date < this.from ? date : this.from;
|
toggleElement(this.dates, date.getTime());
|
||||||
this.to = date > this.to ? date : this.to;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user