From 1d81ce288825c6fac21833d1b2332e6490e1bf0e Mon Sep 17 00:00:00 2001 From: Prannaya Date: Sun, 16 Apr 2023 13:29:19 +0800 Subject: [PATCH] custom calendar widget --- frontend/src/components/calendar/Calendar.vue | 398 ++++++++++++++++++ .../src/components/calendar/EventsModal.vue | 222 ++++++++++ frontend/src/components/calendar/Top.vue | 105 +++++ frontend/src/store/calendar.ts | 71 ++++ 4 files changed, 796 insertions(+) create mode 100644 frontend/src/components/calendar/Calendar.vue create mode 100644 frontend/src/components/calendar/EventsModal.vue create mode 100644 frontend/src/components/calendar/Top.vue create mode 100644 frontend/src/store/calendar.ts diff --git a/frontend/src/components/calendar/Calendar.vue b/frontend/src/components/calendar/Calendar.vue new file mode 100644 index 0000000..65c777c --- /dev/null +++ b/frontend/src/components/calendar/Calendar.vue @@ -0,0 +1,398 @@ + + + + + diff --git a/frontend/src/components/calendar/EventsModal.vue b/frontend/src/components/calendar/EventsModal.vue new file mode 100644 index 0000000..021897f --- /dev/null +++ b/frontend/src/components/calendar/EventsModal.vue @@ -0,0 +1,222 @@ + + + diff --git a/frontend/src/components/calendar/Top.vue b/frontend/src/components/calendar/Top.vue new file mode 100644 index 0000000..c918ac7 --- /dev/null +++ b/frontend/src/components/calendar/Top.vue @@ -0,0 +1,105 @@ + + + diff --git a/frontend/src/store/calendar.ts b/frontend/src/store/calendar.ts new file mode 100644 index 0000000..756cf43 --- /dev/null +++ b/frontend/src/store/calendar.ts @@ -0,0 +1,71 @@ +import { defineStore } from "pinia"; +import { computed, ref } from "vue"; + +export const useCalendarStore = defineStore("calendar", () => { + const year = ref(new Date().getFullYear()); + const month = ref(new Date().getMonth()); + const day = ref(new Date().getDate()); + + const getYear = computed(() => year.value); + const getMonth = computed(() => month.value); + const getDay = computed(() => day.value); + + const monthStr = computed(() => new Intl.DateTimeFormat("en-US", { month: "long" }).format( + new Date(year.value, month.value, day.value) + )) + + function incrementYear(val: number) { + year.value = year.value + val; + } + function decrementYear(val: number) { + year.value = year.value - val; + } + function incrementMonth(val: number) { + if (month.value == 11) { + incrementYear(1); + month.value = 0; + return; + } + + month.value = month.value + val; + } + function decrementMonth(val: number) { + if (month.value == 0) { + decrementYear(1); + month.value = 11; + return; + } + + month.value = month.value - val; + } + + function setMonth(val: number) { + month.value = val; + } + + function setYear(val: number) { + year.value = val; + } + + function resetDate() { + year.value = new Date().getFullYear(); + month.value = new Date().getMonth(); + day.value = new Date().getDate(); + } + + return { + year, + month, + day, + getYear, + getMonth, + getDay, + monthStr, + incrementYear, + incrementMonth, + decrementMonth, + setMonth, + setYear, + resetDate, + }; +});