Skip to content

Commit

Permalink
[Fix] Keep the view locale and the daily notes locale in sync (#123)
Browse files Browse the repository at this point in the history
* Call localization function before generating daily notes

* Bump version
  • Loading branch information
liamcain authored Jan 25, 2021
1 parent 1e2ba68 commit 9acf17a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
Expand Down
19 changes: 13 additions & 6 deletions src/ui/Calendar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -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
Expand All @@ -45,8 +53,6 @@
</script>

<CalendarBase
localeOverride={$settings.localeOverride}
weekStart={$settings.weekStart}
{sources}
{today}
{onHoverDay}
Expand All @@ -56,6 +62,7 @@
{onClickDay}
{onClickWeek}
bind:displayedMonth
localeData={today.localeData()}
selectedId={$activeFile}
showWeekNums={$settings.showWeeklyNote}
/>
2 changes: 0 additions & 2 deletions src/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 9acf17a

Please sign in to comment.