Calendar items can now be selected
This commit is contained in:
@@ -1,2 +1,4 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
docker build -t letsmeet .
|
docker build -t letsmeet .
|
||||||
docker run -d -p 8080:8080 letsmeet
|
docker run -d -p 8080:8080 letsmeet
|
||||||
@@ -3,9 +3,11 @@
|
|||||||
import ArrowLeft from "@/assets/arrow-left.svg";
|
import ArrowLeft from "@/assets/arrow-left.svg";
|
||||||
|
|
||||||
import { ref, onMounted } from "vue";
|
import { ref, onMounted } from "vue";
|
||||||
|
import { datePickerStore } from "@/stores/CalendarStore.ts";
|
||||||
import { Calendar } from "@/models/Calendar.ts";
|
import { Calendar } from "@/models/Calendar.ts";
|
||||||
|
|
||||||
const calendar = new Calendar();
|
const calendar = new Calendar();
|
||||||
|
const datePicker = datePickerStore();
|
||||||
|
|
||||||
const monthYear = ref("");
|
const monthYear = ref("");
|
||||||
const dates = ref([] as (number | null)[]);
|
const dates = ref([] as (number | null)[]);
|
||||||
@@ -14,6 +16,18 @@
|
|||||||
setupCalendar();
|
setupCalendar();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function setupCalendar(){
|
||||||
|
dates.value = calendar.datesOfCurrentMonth();
|
||||||
|
updateMonth();
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
function clickPrev(){
|
function clickPrev(){
|
||||||
dates.value = calendar.datesOfPrevMonth();
|
dates.value = calendar.datesOfPrevMonth();
|
||||||
updateMonth();
|
updateMonth();
|
||||||
@@ -24,13 +38,8 @@
|
|||||||
updateMonth();
|
updateMonth();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupCalendar(){
|
|
||||||
dates.value = calendar.datesOfToday();
|
|
||||||
updateMonth();
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateMonth(){
|
function updateMonth(){
|
||||||
monthYear.value = calendar.getDate();
|
monthYear.value = calendar.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
@@ -56,7 +65,10 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="day-picker">
|
<div class="day-picker">
|
||||||
<div v-for="(day, index) in dates" :key="day ?? `null-${index}`" :class="{'item': day !== null}">
|
<div v-on:click="selectDay($event, day)"
|
||||||
|
v-for ="(day, index) in dates"
|
||||||
|
:id ="day !== null ? `day-${index}` : undefined"
|
||||||
|
:class ="{'item': day !== null}">
|
||||||
{{ day }}
|
{{ day }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -129,10 +141,14 @@
|
|||||||
user-select: none;
|
user-select: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.item:hover
|
.item-selected
|
||||||
{
|
{
|
||||||
transform: scale(1.1);
|
|
||||||
background-color: var(--secondary-color);
|
background-color: var(--secondary-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.item:hover
|
||||||
|
{
|
||||||
|
transform: scale(1.1);
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
export class Calendar {
|
export class Calendar {
|
||||||
|
|
||||||
private year : number;
|
private readonly monthsName : string[] = [
|
||||||
private month : number;
|
|
||||||
private monthsName : string[] = [
|
|
||||||
"January",
|
"January",
|
||||||
"February",
|
"February",
|
||||||
"March",
|
"March",
|
||||||
@@ -16,18 +14,24 @@ export class Calendar {
|
|||||||
"November",
|
"November",
|
||||||
"December"
|
"December"
|
||||||
];
|
];
|
||||||
|
private year : number;
|
||||||
|
private month : number;
|
||||||
|
private day : number;
|
||||||
|
|
||||||
public constructor() {
|
public constructor() {
|
||||||
let date = new Date();
|
let date = new Date();
|
||||||
this.year = date.getFullYear();
|
this.year = date.getFullYear();
|
||||||
this.month = date.getMonth();
|
this.month = date.getMonth();
|
||||||
|
this.day = date.getDay();
|
||||||
}
|
}
|
||||||
|
|
||||||
public getDate(){
|
public getDate(): Date {
|
||||||
return this.monthsName[this.month] + " " + this.year;
|
return new Date(this.year, this.month, this.day);
|
||||||
}
|
}
|
||||||
|
|
||||||
public datesOfToday(){
|
public setDay(day : number) { this.day = day; }
|
||||||
|
|
||||||
|
public datesOfCurrentMonth(){
|
||||||
return this.datesOf();
|
return this.datesOf();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,4 +71,8 @@ export class Calendar {
|
|||||||
}
|
}
|
||||||
return dates;
|
return dates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public toString(){
|
||||||
|
return this.monthsName[this.month] + " " + this.year;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
13
src/stores/CalendarStore.ts
Normal file
13
src/stores/CalendarStore.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { defineStore } from 'pinia'
|
||||||
|
|
||||||
|
export const datePickerStore = defineStore('datePicker', {
|
||||||
|
state: () => {
|
||||||
|
return { from: new Date(), to: new Date() }
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
select(date : Date) {
|
||||||
|
this.from = date < this.from ? date : this.from;
|
||||||
|
this.to = date > this.to ? date : this.to;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user