mirror of
https://github.com/formax68/memoChron.git
synced 2026-07-22 05:45:44 +00:00
refactor(08-02): replace (window as any).moment with typed obsidian import (A1)
Per Amendment A1, the 5 (window as any).moment casts get replaced with the
typed import { moment } from "obsidian" (obsidian.d.ts exports moment as
typeof Moment). Removes 5 dead null-check branches that existed only because
the cast was treated as nullable: 4 negative-shape (if (!moment) return) and
1 positive-shape (if (moment) { weekNum = ... } flattened to unconditional).
- CalendarView.ts: 3 sites (checkDailyNoteForDate, renderWeekNumber,
handleDailyNoteClick) — adds moment to existing obsidian import
- EmbeddedCalendarView.ts: 1 site — adds moment to existing obsidian import
- EmbeddedAgendaView.ts: 1 site — adds moment to existing obsidian import
This commit is contained in:
parent
413b6f3bfc
commit
e69c2fa194
3 changed files with 4 additions and 32 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { ItemView, WorkspaceLeaf, Notice, TFile, setIcon, MarkdownView, Menu, MenuItem } from "obsidian";
|
||||
import { ItemView, WorkspaceLeaf, Notice, TFile, setIcon, MarkdownView, Menu, MenuItem, moment } from "obsidian";
|
||||
import { CalendarEvent } from "../services/CalendarService";
|
||||
import MemoChron from "../main";
|
||||
import { MEMOCHRON_VIEW_TYPE } from "../utils/constants";
|
||||
|
|
@ -156,11 +156,6 @@ export class CalendarView extends ItemView {
|
|||
}
|
||||
|
||||
try {
|
||||
const moment = (window as any).moment;
|
||||
if (!moment) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const momentDate = moment(date);
|
||||
const allDailyNotes = getAllDailyNotes();
|
||||
const dailyNote = getDailyNote(momentDate, allDailyNotes);
|
||||
|
|
@ -551,12 +546,7 @@ export class CalendarView extends ItemView {
|
|||
}
|
||||
|
||||
private renderWeekNumber(grid: HTMLElement, date: Date) {
|
||||
const moment = (window as any).moment;
|
||||
let weekNum = "?";
|
||||
|
||||
if (moment) {
|
||||
weekNum = String(moment(date).week());
|
||||
}
|
||||
const weekNum = String(moment(date).week());
|
||||
|
||||
grid.createEl("div", {
|
||||
cls: "memochron-week-number",
|
||||
|
|
@ -801,12 +791,6 @@ export class CalendarView extends ItemView {
|
|||
}
|
||||
|
||||
// Use moment for date handling (same as Obsidian's daily notes)
|
||||
const moment = (window as any).moment;
|
||||
if (!moment) {
|
||||
new Notice("Moment.js is not available");
|
||||
return;
|
||||
}
|
||||
|
||||
const momentDate = moment(date);
|
||||
|
||||
// Get all daily notes
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { MarkdownRenderChild, MarkdownView, Notice, setIcon, TFile } from "obsidian";
|
||||
import { MarkdownRenderChild, MarkdownView, Notice, setIcon, TFile, moment } from "obsidian";
|
||||
import MemoChron from "../main";
|
||||
import {
|
||||
parseDate,
|
||||
|
|
@ -376,12 +376,6 @@ export class EmbeddedAgendaView extends MarkdownRenderChild {
|
|||
return;
|
||||
}
|
||||
|
||||
const moment = (window as any).moment;
|
||||
if (!moment) {
|
||||
new Notice("Moment.js is not available");
|
||||
return;
|
||||
}
|
||||
|
||||
const momentDate = moment(date);
|
||||
const allDailyNotes = getAllDailyNotes();
|
||||
let dailyNote = getDailyNote(momentDate, allDailyNotes);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { MarkdownRenderChild, Notice, TFile } from "obsidian";
|
||||
import { MarkdownRenderChild, Notice, TFile, moment } from "obsidian";
|
||||
import MemoChron from "../main";
|
||||
import {
|
||||
renderCalendarGrid,
|
||||
|
|
@ -220,12 +220,6 @@ export class EmbeddedCalendarView extends MarkdownRenderChild {
|
|||
}
|
||||
|
||||
// Use moment for date handling (same as Obsidian's daily notes)
|
||||
const moment = (window as any).moment;
|
||||
if (!moment) {
|
||||
new Notice("Moment.js is not available");
|
||||
return;
|
||||
}
|
||||
|
||||
const momentDate = moment(date);
|
||||
|
||||
// Get all daily notes
|
||||
|
|
|
|||
Loading…
Reference in a new issue