obsidian-daily-notes-interface icon indicating copy to clipboard operation
obsidian-daily-notes-interface copied to clipboard

Don‘t return correct periodic notes settings after 1.0.0 ver. of periodic note

Open Quorafind opened this issue 2 years ago • 2 comments

Like the title,

Even if I had set periodic notes settings, the settings didn't show correctly

Quorafind avatar Apr 12 '22 01:04 Quorafind

Seems like this interface hasn't been updated for Periodic Notes v1, which is currently in beta. I believe this is what's affecting users who are using the Upcoming plugin. @liamcain Do you see this as an issue you would address in this interface, or in the Periodic Notes plugin?

charliecm avatar Jun 19 '22 17:06 charliecm

To support Periodic Notes 1.0, file src/settings.ts needs to be updated like this:

import {
  DEFAULT_DAILY_NOTE_FORMAT,
  DEFAULT_MONTHLY_NOTE_FORMAT,
  DEFAULT_WEEKLY_NOTE_FORMAT,
  DEFAULT_QUARTERLY_NOTE_FORMAT,
  DEFAULT_YEARLY_NOTE_FORMAT,
} from "./constants";
import { IPeriodicNoteSettings } from "./types";

export function shouldUsePeriodicNotesSettings(
-  periodicity: "daily" | "weekly" | "monthly" | "quarterly" | "yearly"
+  periodicity: "day" | "week" | "month" | "quarter" | "year"
): boolean {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  const periodicNotes = (<any>window.app).plugins.getPlugin("periodic-notes");
-  return periodicNotes && periodicNotes.settings?.[periodicity]?.enabled;
+  return periodicNotes && periodicNotes.calendarSetManager?.getActiveSet?.()?.[periodicity]?.enabled;
}

/**
 * Read the user settings for the `daily-notes` plugin
 * to keep behavior of creating a new note in-sync.
 */
export function getDailyNoteSettings(): IPeriodicNoteSettings {
  try {
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    const { internalPlugins, plugins } = <any>window.app;

    if (shouldUsePeriodicNotesSettings("day")) {
-      const { format, folder, template } =
-        plugins.getPlugin("periodic-notes")?.settings?.daily || {};
+      const { format, folder, templatePath } =
+        plugins.getPlugin("periodic-notes")?.calendarSetManager?.getActiveSet?.()?.day || {};
      return {
        format: format || DEFAULT_DAILY_NOTE_FORMAT,
        folder: folder?.trim() || "",
-        template: template?.trim() || "",
+        template: templatePath?.trim() || "",
      };
    }

    const { folder, format, template } =
      internalPlugins.getPluginById("daily-notes")?.instance?.options || {};
    return {
      format: format || DEFAULT_DAILY_NOTE_FORMAT,
      folder: folder?.trim() || "",
      template: template?.trim() || "",
    };
  } catch (err) {
    console.info("No custom daily note settings found!", err);
  }
}

// ...

Same changes for weekly and so on.

Note that this isn't a proper diff, I just wrote this manually in the comment editor. Hopefully someone will make a Pull Request.

deltaidea avatar Apr 11 '23 22:04 deltaidea