Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add time in note title #317

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/calendars/FullNoteCalendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@ import { TFile, TFolder, parseYaml } from "obsidian";
import { rrulestr } from "rrule";
import { EventPathLocation } from "../core/EventStore";
import { ObsidianInterface } from "../ObsidianAdapter";
import { OFCEvent, EventLocation, validateEvent } from "../types";
import {
OFCEvent,
EventLocation,
validateEvent,
isRangeTimeData,
} from "../types";
import { EditableCalendar, EditableEventResponse } from "./EditableCalendar";

const basenameFromEvent = (event: OFCEvent): string => {
switch (event.type) {
case undefined:
case "single":
if (isRangeTimeData(event)) {
Copy link
Author

@jartigag jartigag Mar 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use something like

if (this.plugin.settings.timeInNoteTitle && isRangeTimeData(event)) {

But this.plugin.settings is not valid from here and I don't know how to access to that value in this place.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davish I need help with this part. How would you check that setting from the FullNoteCalendar class?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can pass the boolean timeInNoteTitle as an argument to the FullNoteCalendar constructor. When the calendar is registered in main.ts. I don't think there's a way right now to get access to "global" settings, but you could make it a per-calendar setting that lives as part of the CalendarInfo type for local calendars.

return `${event.date} ${event.startTime.replace(":", "")} ${
event.title
}`;
}
return `${event.date} ${event.title}`;
case "recurring":
return `(Every ${event.daysOfWeek.join(",")}) ${event.title}`;
Expand Down
6 changes: 6 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export type CommonEventData = {
id?: string; // Only set for remote calendars.
} & (RangeTimeData | AllDayData);

export function isRangeTimeData(
event: RangeTimeData | AllDayData
): event is RangeTimeData {
return (event as RangeTimeData).startTime !== undefined;
}

export type SingleEventData = {
type?: "single";
date: string;
Expand Down