diff --git a/src/calendar-view/CalendarView.vue b/src/calendar-view/CalendarView.vue index f0dd8f6..0ab5718 100644 --- a/src/calendar-view/CalendarView.vue +++ b/src/calendar-view/CalendarView.vue @@ -12,8 +12,12 @@ 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$, plugin$ } from "@/stores/obsidian.store"; import { useShelfProvider } from "@/composables/use-shelf"; +import { useApp } from "@/composables/use-app"; +import { usePlugin } from "@/composables/use-plugin"; + +const app = useApp(); +const plugin = usePlugin(); const refDateMoment = ref(today()); const refDate = computed(() => refDateMoment.value.format("YYYY-MM-DD")); @@ -43,7 +47,7 @@ const weeksClickable = computed(() => { }); function selectShelf() { - new ShelfSuggestModal(app$.value, Object.keys(pluginSettings$.value.shelves), (shelf: string | null) => { + new ShelfSuggestModal(app, Object.keys(pluginSettings$.value.shelves), (shelf: string | null) => { selectedShelf.value = shelf; }).open(); } @@ -58,19 +62,21 @@ function goToday(event: MouseEvent) { } else if (calendarViewSettings$.value.todayMode === "navigate") { const journals: string[] = []; for (const journalSetttings of journalsList$.value) { - const journal = plugin$.value.getJournal(journalSetttings.name); + const journal = plugin.getJournal(journalSetttings.name); if (!journal) continue; const anchorDate = journal.resolveAnchorDate(refDate.value); if (!anchorDate) continue; - const index = plugin$.value.index.getJournalIndex(journal.name); + const index = plugin.index.getJournalIndex(journal.name); if (!index) continue; if (index.get(anchorDate)) journals.push(journal.name); } - openDate(refDate.value, journals, event).catch(console.error); + openDate(app, plugin, refDate.value, journals, event).catch(console.error); } } function pickDate() { new VueModal( + app, + plugin, "Pick a date", DatePickerModal, { @@ -85,6 +91,8 @@ function pickDate() { function openDay(date: string, event: MouseEvent) { openDate( + app, + plugin, date, journals.day.value.map((journal) => journal.name), event, @@ -92,6 +100,8 @@ function openDay(date: string, event: MouseEvent) { } function openWeek(date: string, event: MouseEvent) { openDate( + app, + plugin, date, journals.week.value.map((journal) => journal.name), event, @@ -99,6 +109,8 @@ function openWeek(date: string, event: MouseEvent) { } function openMonth(event: MouseEvent) { openDate( + app, + plugin, refDate.value, journals.month.value.map((journal) => journal.name), event, @@ -106,6 +118,8 @@ function openMonth(event: MouseEvent) { } function openQuarter(event: MouseEvent) { openDate( + app, + plugin, refDate.value, journals.quarter.value.map((journal) => journal.name), event, @@ -113,6 +127,8 @@ function openQuarter(event: MouseEvent) { } function openYear(event: MouseEvent) { openDate( + app, + plugin, refDate.value, journals.year.value.map((journal) => journal.name), event, diff --git a/src/calendar-view/calendar-view.ts b/src/calendar-view/calendar-view.ts index 1bc356b..e0729b8 100644 --- a/src/calendar-view/calendar-view.ts +++ b/src/calendar-view/calendar-view.ts @@ -1,12 +1,20 @@ -import { ItemView } from "obsidian"; +import { ItemView, type WorkspaceLeaf } from "obsidian"; import { createApp, type App as VueApp } from "vue"; -import { CALENDAR_VIEW_TYPE } from "../constants"; +import { APP_KEY, CALENDAR_VIEW_TYPE, PLUGIN_KEY } from "../constants"; import CalendarViewComponent from "./CalendarView.vue"; +import type { JournalPlugin } from "@/types/plugin.types"; export class CalendarView extends ItemView { navigation = false; #vueApp: VueApp | null = null; + constructor( + leaf: WorkspaceLeaf, + private plugin: JournalPlugin, + ) { + super(leaf); + } + getViewType(): string { return CALENDAR_VIEW_TYPE; } @@ -20,6 +28,8 @@ export class CalendarView extends ItemView { protected onOpen(): Promise { this.#vueApp = createApp(CalendarViewComponent); + this.#vueApp.provide(APP_KEY, this.app); + this.#vueApp.provide(PLUGIN_KEY, this.plugin); this.#vueApp.mount(this.contentEl); return Promise.resolve(); } diff --git a/src/code-blocks/navigation/NavigationBlock.vue b/src/code-blocks/navigation/NavigationBlock.vue index a061aee..54fa87e 100644 --- a/src/code-blocks/navigation/NavigationBlock.vue +++ b/src/code-blocks/navigation/NavigationBlock.vue @@ -2,10 +2,11 @@ import { computed } from "vue"; import { journals$ } from "@/stores/settings.store"; import NavigationBlockRow from "./NavigationBlockRow.vue"; -import { plugin$ } from "@/stores/obsidian.store"; import { openDate, openDateInJournal } from "@/journals/open-date"; import { useShelfProvider } from "@/composables/use-shelf"; -import { NavBlockRow } from "@/types/settings.types"; +import type { NavBlockRow } from "@/types/settings.types"; +import { useApp } from "@/composables/use-app"; +import { usePlugin } from "@/composables/use-plugin"; const props = defineProps<{ refDate: string; @@ -14,8 +15,11 @@ const props = defineProps<{ defineEmits<(event: "move-up" | "move-down" | "edit" | "remove", index: number) => void>(); +const app = useApp(); +const plugin = usePlugin(); + const journalSettings = computed(() => journals$.value[props.journalName]); -const journal = computed(() => plugin$.value.getJournal(props.journalName)); +const journal = computed(() => plugin.getJournal(props.journalName)); const shelfName = computed(() => journalSettings.value?.shelves[0] ?? null); const { journals } = useShelfProvider(shelfName); @@ -27,10 +31,10 @@ async function navigate(type: NavBlockRow["link"], date: string, journalName?: s if (metadata) await journal.value?.open(metadata); } else if (type === "journal") { if (!journalName) return; - await openDateInJournal(date, journalName); + await openDateInJournal(plugin, date, journalName); } else { const journalsToUse = journals[type].value.map((journal) => journal.name); - await openDate(date, journalsToUse); + await openDate(app, plugin, date, journalsToUse); } } diff --git a/src/code-blocks/navigation/NavigationBlockEditPreview.vue b/src/code-blocks/navigation/NavigationBlockEditPreview.vue index f88e071..fad4e1b 100644 --- a/src/code-blocks/navigation/NavigationBlockEditPreview.vue +++ b/src/code-blocks/navigation/NavigationBlockEditPreview.vue @@ -3,7 +3,8 @@ import { computed } from "vue"; import { journals$ } from "@/stores/settings.store"; import NavigationBlockRow from "./NavigationBlockRow.vue"; import ObsidianIconButton from "@/components/obsidian/ObsidianIconButton.vue"; -import { plugin$ } from "@/stores/obsidian.store"; +import { usePlugin } from "@/composables/use-plugin"; +import { useShelfProvider } from "@/composables/use-shelf"; const props = defineProps<{ refDate: string; @@ -12,8 +13,12 @@ const props = defineProps<{ defineEmits<(event: "move-up" | "move-down" | "edit" | "remove", index: number) => void>(); +const plugin = usePlugin(); + const journalSettings = computed(() => journals$.value[props.journalName]); -const journal = computed(() => plugin$.value.getJournal(props.journalName)); +const journal = computed(() => plugin.getJournal(props.journalName)); + +useShelfProvider(journalSettings.value?.shelves[0]);