From 9acf17a9427f35f7a61d4378721229cbc92ecfc7 Mon Sep 17 00:00:00 2001 From: Liam Cain Date: Mon, 25 Jan 2021 18:16:59 -0500 Subject: [PATCH] [Fix] Keep the view locale and the daily notes locale in sync (#123) * Call localization function before generating daily notes * Bump version --- manifest.json | 2 +- package.json | 4 ++-- src/ui/Calendar.svelte | 19 +++++++++++++------ src/view.ts | 2 -- yarn.lock | 8 ++++---- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/manifest.json b/manifest.json index 6ec667b..6fa6d58 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "id": "calendar", "name": "Calendar", "description": "Calendar view of your daily notes", - "version": "1.4.18", + "version": "1.4.19", "author": "Liam Cain", "authorUrl": "https://github.com/liamcain/", "isDesktopOnly": false, diff --git a/package.json b/package.json index fd4a055..dfe43c6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "calendar", - "version": "1.4.18", + "version": "1.4.19", "description": "Calendar view of your daily notes", "author": "liamcain", "main": "main.js", @@ -13,7 +13,7 @@ }, "dependencies": { "obsidian": "obsidianmd/obsidian-api#master", - "obsidian-calendar-ui": "0.2.4", + "obsidian-calendar-ui": "0.3.0", "obsidian-daily-notes-interface": "0.5.1", "svelte": "3.31.0", "tslib": "2.0.3" diff --git a/src/ui/Calendar.svelte b/src/ui/Calendar.svelte index 6a0a4c4..42778ef 100644 --- a/src/ui/Calendar.svelte +++ b/src/ui/Calendar.svelte @@ -5,14 +5,16 @@ import { Calendar as CalendarBase, ICalendarSource, + configureGlobalMomentLocale, } from "obsidian-calendar-ui"; import { onDestroy } from "svelte"; - import { activeFile, settings } from "./stores"; + import type { ISettings } from "src/settings"; + import { activeFile, dailyNotes, settings } from "./stores"; - const moment = window.moment; + let today: Moment; - let today: Moment = moment(); + $: today = getToday($settings); export let displayedMonth: Moment = today; export let sources: ICalendarSource[]; @@ -24,7 +26,13 @@ export let onContextMenuWeek: (date: Moment, event: MouseEvent) => boolean; export function tick() { - today = moment(); + today = window.moment(); + } + + function getToday(settings: ISettings) { + configureGlobalMomentLocale(settings.localeOverride, settings.weekStart); + dailyNotes.reindex(); + return window.moment(); } // 1 minute heartbeat to keep `today` reflecting the current day @@ -45,8 +53,6 @@ diff --git a/src/view.ts b/src/view.ts index fd53141..d3e8b82 100644 --- a/src/view.ts +++ b/src/view.ts @@ -89,8 +89,6 @@ export default class CalendarView extends ItemView { ]; this.app.workspace.trigger(TRIGGER_ON_OPEN, sources); - dailyNotes.reindex(); - this.calendar = new Calendar({ // eslint-disable-next-line @typescript-eslint/no-explicit-any target: (this as any).contentEl, diff --git a/yarn.lock b/yarn.lock index 32f8ae2..8157947 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3314,10 +3314,10 @@ object.pick@^1.3.0: dependencies: isobject "^3.0.1" -obsidian-calendar-ui@0.2.4: - version "0.2.4" - resolved "https://registry.yarnpkg.com/obsidian-calendar-ui/-/obsidian-calendar-ui-0.2.4.tgz#8e6f3bcfca51c8f97345ddab426b2abefbbe5249" - integrity sha512-VSpgqmUKhy3wG/x6XRHbK3H57DzddRcsvS17/M+XnryAzT4unQa10th5ikWMfDHWdkbwqYxyvf90NWkcIr4NdQ== +obsidian-calendar-ui@0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/obsidian-calendar-ui/-/obsidian-calendar-ui-0.3.0.tgz#3c3af76a6995d2b17e7185d19b1fdf180e9106ce" + integrity sha512-C07BIq04m+jKF0foZOB6dzxRXHRDFJs2vDYEH97qV2iKC00TOYHwwFg8PgRNQARs+TZGRGI3Tn05xIzy9c7Jdg== dependencies: obsidian-daily-notes-interface "0.5.1" svelte "3.31.0"