feat(views/calendar): add option to hide weekends

This commit is contained in:
Elian Doran
2025-02-21 17:52:11 +02:00
parent 710cf68c06
commit 42d46bdb72
3 changed files with 20 additions and 5 deletions

View File

@@ -117,8 +117,10 @@ export default class NoteListWidget extends NoteContextAwareWidget {
this.checkRenderStatus();
}
if (this.viewMode) {
this.viewMode.entitiesReloadedEvents(e);
// Inform the view mode of changes and refresh if needed.
if (this.viewMode && this.viewMode.onEntitiesReloaded(e)) {
this.refresh();
this.checkRenderStatus();
}
}
}

View File

@@ -102,6 +102,7 @@ export default class CalendarView extends ViewMode {
select: (e) => this.#onCalendarSelection(e),
eventChange: (e) => this.#onEventMoved(e),
firstDay: options.getInt("firstDayOfWeek") ?? 0,
weekends: !this.parentNote.hasAttribute("label", "calendar:hideWeekends"),
locale: await CalendarView.#getLocale(),
height: "100%"
});
@@ -179,12 +180,18 @@ export default class CalendarView extends ViewMode {
CalendarView.#setAttribute(note, "label", "endDate", endDate);
}
entitiesReloadedEvents({ loadResults }: EventData<"entitiesReloaded">): void {
onEntitiesReloaded({ loadResults }: EventData<"entitiesReloaded">) {
// Refresh note IDs if they got changed.
if (loadResults.getBranchRows().some((branch) => branch.parentNoteId == this.parentNote.noteId)) {
if (loadResults.getBranchRows().some((branch) => branch.parentNoteId === this.parentNote.noteId)) {
this.noteIds = this.parentNote.getChildNoteIds();
}
// Refresh calendar on attribute change.
if (loadResults.getAttributeRows().some((attribute) => attribute.noteId === this.parentNote.noteId && attribute.name?.startsWith("calendar:"))) {
return true;
}
// Refresh dataset on subnote change.
if (this.calendar && loadResults.getAttributeRows().some((a) => this.noteIds.includes(a.noteId ?? ""))) {
this.calendar.refetchEvents();
}

View File

@@ -17,7 +17,13 @@ export default abstract class ViewMode {
abstract renderList(): Promise<JQuery<HTMLElement> | undefined>;
entitiesReloadedEvents(e: EventData<"entitiesReloaded">) {
/**
* Called whenever an "entitiesReloaded" event has been received by the parent component.
*
* @param e the event data.
* @return {@code true} if the view should be re-rendered, a falsy value otherwise.
*/
onEntitiesReloaded(e: EventData<"entitiesReloaded">): boolean | void {
// Do nothing by default.
}