Skip to content

Commit

Permalink
Better error handling for missing folder (#120)
Browse files Browse the repository at this point in the history
* Better error handling for missing folder

* Bump version
  • Loading branch information
liamcain authored Jan 22, 2021
1 parent 207aba4 commit fbb0159
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 18 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.16",
"version": "1.4.17",
"author": "Liam Cain",
"authorUrl": "https://github.com/liamcain/",
"isDesktopOnly": false,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "calendar",
"version": "1.4.16",
"version": "1.4.17",
"description": "Calendar view of your daily notes",
"author": "liamcain",
"main": "main.js",
Expand Down
20 changes: 10 additions & 10 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ export class CalendarSettingsTab extends PluginSettingTab {
display(): void {
this.containerEl.empty();

if (!appHasDailyNotesPluginLoaded()) {
this.containerEl.createEl("h3", {
text: "⚠️ Daily Notes plugin not enabled",
});
this.containerEl.createEl("p", {
text:
"The calendar is best used in conjunction with the Daily Notes plugin. Enable it in your plugin settings for a more optimal experience.",
});
}

this.containerEl.createEl("h3", {
text: "General Settings",
});
Expand All @@ -85,16 +95,6 @@ export class CalendarSettingsTab extends PluginSettingTab {
this.addWeeklyNoteFolderSetting();
}

if (!appHasDailyNotesPluginLoaded()) {
this.containerEl.createEl("h3", {
text: "⚠️ Daily Notes plugin not enabled",
});
this.containerEl.createEl("p", {
text:
"The calendar is best used in conjunction with the Daily Notes plugin. Enable it in your plugin settings for a more optimal experience.",
});
}

this.containerEl.createEl("h3", {
text: "Advanced Settings",
});
Expand Down
21 changes: 18 additions & 3 deletions src/ui/stores.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
import type { TFile } from "obsidian";
import { get, writable } from "svelte/store";
import { Notice, TFile } from "obsidian";
import { getAllDailyNotes } from "obsidian-daily-notes-interface";
import { get, writable } from "svelte/store";

import { defaultSettings, ISettings } from "src/settings";

import { getDateUIDFromFile } from "./utils";

function createDailyNotesStore() {
let hasError = false;
const store = writable<Record<string, TFile>>(null);
return {
reindex: () => store.set(getAllDailyNotes()),
reindex: () => {
try {
const dailyNotes = getAllDailyNotes();
store.set(dailyNotes);
hasError = false;
} catch (err) {
if (!hasError) {
// Avoid error being shown multiple times
new Notice("Failed to find your Daily Note folder");
console.log("[Calendar] Failed to find daily notes folder", err);
}
store.set({});
hasError = true;
}
},
...store,
};
}
Expand Down
9 changes: 6 additions & 3 deletions src/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,15 @@ export default class CalendarView extends ItemView {

private async onFileModified(file: TFile): Promise<void> {
const date = getDateFromFile(file);
if (date) {
if (date && this.calendar) {
this.calendar.tick();
}
}

private onFileCreated(file: TFile): void {
if (this.app.workspace.layoutReady) {
const date = getDateFromFile(file);
if (date) {
if (date && this.calendar) {
dailyNotes.reindex();
this.calendar.tick();
}
Expand All @@ -207,7 +207,10 @@ export default class CalendarView extends ItemView {
file = view.file;
}
activeFile.setFile(file);
this.calendar.tick();

if (this.calendar) {
this.calendar.tick();
}
}

public revealActiveNote(): void {
Expand Down

0 comments on commit fbb0159

Please sign in to comment.