From 641933716c238e0bc757bacee8516f15a86217b0 Mon Sep 17 00:00:00 2001 From: Sergii Kostyrko Date: Sun, 27 Oct 2024 16:51:40 +0200 Subject: [PATCH] feat: add journal shelves --- src/calendar-view/CalendarView.vue | 61 +++++++++++------ .../navigation/NavigationBlock.vue | 14 ++-- .../navigation/NavigationBlockRow.vue | 14 +++- src/components/calendar/CalendarDay.vue | 7 +- .../calendar/CalendarMonthButton.vue | 11 +-- .../calendar/CalendarQuarterButton.vue | 11 +-- .../calendar/CalendarWeekNumber.vue | 7 +- .../calendar/CalendarYearButton.vue | 13 ++-- src/composables/use-shelf.ts | 67 +++++++++++++++++++ src/defaults.ts | 3 + src/main.ts | 15 +++++ src/stores/settings.store.ts | 39 ----------- src/types/provided-data.types.ts | 12 ++++ src/types/settings.types.ts | 6 +- tsconfig.app.json | 1 + 15 files changed, 192 insertions(+), 89 deletions(-) create mode 100644 src/composables/use-shelf.ts create mode 100644 src/types/provided-data.types.ts diff --git a/src/calendar-view/CalendarView.vue b/src/calendar-view/CalendarView.vue index 29b8038..ee0d783 100644 --- a/src/calendar-view/CalendarView.vue +++ b/src/calendar-view/CalendarView.vue @@ -6,26 +6,26 @@ import CalendarMonth from "../components/calendar/CalendarMonth.vue"; import DatePickerModal from "../components/modals/DatePicker.modal.vue"; import { VueModal } from "../components/modals/vue-modal"; import { today, date_from_string } from "../calendar"; -import { - journalsWithDays$, - journalsWithWeeks$, - journalsWithMonths$, - journalsWithQuarters$, - journalsWithYears$, - pluginSettings$, - journalsList$, -} from "../stores/settings.store"; +import { pluginSettings$, journalsList$ } from "../stores/settings.store"; import { openDate } from "@/journals/open-date"; import CalendarMonthButton from "@/components/calendar/CalendarMonthButton.vue"; import CalendarYearButton from "@/components/calendar/CalendarYearButton.vue"; import CalendarQuarterButton from "@/components/calendar/CalendarQuarterButton.vue"; import { ShelfSuggestModal } from "@/components/suggests/shelf-suggest"; import { app$ } from "@/stores/obsidian.store"; +import { useShelfProvider } from "@/composables/use-shelf"; const refDateMoment = ref(today()); const refDate = computed(() => refDateMoment.value.format("YYYY-MM-DD")); -const selectedShelf = ref(null); +const selectedShelf = computed({ + get() { + return pluginSettings$.value.ui.calendarShelf; + }, + set(value) { + pluginSettings$.value.ui.calendarShelf = value; + }, +}); const shouldShowShelf = computed(() => { return ( (pluginSettings$.value.useShelves && Object.values(pluginSettings$.value.shelves).length > 0) || @@ -33,14 +33,13 @@ const shouldShowShelf = computed(() => { ); }); +const { journals } = useShelfProvider(selectedShelf); + const daysClickable = computed(() => { - return journalsWithDays$.value.length > 0; + return journals.day.value.length > 0; }); const weeksClickable = computed(() => { - return journalsWithWeeks$.value.length > 0; -}); -const quartersClickable = computed(() => { - return journalsWithQuarters$.value.length > 0; + return journals.week.value.length > 0; }); function selectShelf() { @@ -70,19 +69,39 @@ function pickDate() { } function openDay(date: string, event: MouseEvent) { - openDate(date, journalsWithDays$.value, event).catch(console.error); + openDate( + date, + journals.day.value.map((journal) => journal.name), + event, + ).catch(console.error); } function openWeek(date: string, event: MouseEvent) { - openDate(date, journalsWithWeeks$.value, event).catch(console.error); + openDate( + date, + journals.week.value.map((journal) => journal.name), + event, + ).catch(console.error); } function openMonth(event: MouseEvent) { - openDate(refDate.value, journalsWithMonths$.value, event).catch(console.error); + openDate( + refDate.value, + journals.month.value.map((journal) => journal.name), + event, + ).catch(console.error); } function openQuarter(event: MouseEvent) { - openDate(refDate.value, journalsWithQuarters$.value, event).catch(console.error); + openDate( + refDate.value, + journals.quarter.value.map((journal) => journal.name), + event, + ).catch(console.error); } function openYear(event: MouseEvent) { - openDate(refDate.value, journalsWithYears$.value, event).catch(console.error); + openDate( + refDate.value, + journals.year.value.map((journal) => journal.name), + event, + ).catch(console.error); } // TODO slim header to avoid scroll @@ -108,7 +127,7 @@ function openYear(event: MouseEvent) {
- +
diff --git a/src/code-blocks/navigation/NavigationBlock.vue b/src/code-blocks/navigation/NavigationBlock.vue index 7935668..a061aee 100644 --- a/src/code-blocks/navigation/NavigationBlock.vue +++ b/src/code-blocks/navigation/NavigationBlock.vue @@ -1,9 +1,11 @@ diff --git a/src/code-blocks/navigation/NavigationBlockRow.vue b/src/code-blocks/navigation/NavigationBlockRow.vue index 26a8477..6fd23e2 100644 --- a/src/code-blocks/navigation/NavigationBlockRow.vue +++ b/src/code-blocks/navigation/NavigationBlockRow.vue @@ -1,8 +1,9 @@