Skip to content

Commit

Permalink
feat: add today button mode setting
Browse files Browse the repository at this point in the history
  • Loading branch information
srg-kostyrko committed Oct 28, 2024
1 parent 6419337 commit 5cb3313
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
21 changes: 18 additions & 3 deletions src/calendar-view/CalendarView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ 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 { pluginSettings$, journalsList$ } from "../stores/settings.store";
import { pluginSettings$, journalsList$, calendarViewSettings$ } 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 { app$, plugin$ } from "@/stores/obsidian.store";
import { useShelfProvider } from "@/composables/use-shelf";
const refDateMoment = ref(today());
Expand Down Expand Up @@ -51,8 +51,23 @@ function selectShelf() {
function navigate(amount: number, step: "month" | "year" = "month") {
refDateMoment.value = refDateMoment.value.clone().add(amount, step);
}
function goToday() {
function goToday(event: MouseEvent) {
refDateMoment.value = today();
if (calendarViewSettings$.value.todayMode === "create") {
openDay(refDate.value, event);
} else if (calendarViewSettings$.value.todayMode === "navigate") {
const journals: string[] = [];
for (const journalSetttings of journalsList$.value) {
const journal = plugin$.value.getJournal(journalSetttings.name);
if (!journal) continue;
const anchorDate = journal.resolveAnchorDate(refDate.value);
if (!anchorDate) continue;
const index = plugin$.value.index.getJournalIndex(journal.name);
if (!index) continue;
if (index.get(anchorDate)) journals.push(journal.name);
}
openDate(refDate.value, journals, event).catch(console.error);
}
}
function pickDate() {
new VueModal(
Expand Down
7 changes: 7 additions & 0 deletions src/settings/JournalSettingsDashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,11 @@ function changeFirstWeekOfYear(value: number): void {
<option value="right">After weekdays</option>
</ObsidianDropdown>
</ObsidianSetting>
<ObsidianSetting name="Today button">
<ObsidianDropdown v-model="calendarViewSettings$.todayMode">
<option value="create">Creates today's note if doesn't exist</option>
<option value="navigate">Opens today's note if it exists</option>
<option value="switch_date">Just switch calendar view to current month</option>
</ObsidianDropdown>
</ObsidianSetting>
</template>
2 changes: 1 addition & 1 deletion src/types/settings.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface PluginSettings {
leaf: "left" | "right";
weeks: "none" | "left" | "right";

todayMode: "navigate" | "create";
todayMode: "navigate" | "create" | "switch_date";
};
}

Expand Down

0 comments on commit 5cb3313

Please sign in to comment.