feat(in_app_help): contextual help for book types

This commit is contained in:
Elian Doran
2025-02-16 18:09:01 +02:00
parent c17d10114f
commit e73ea36161
3 changed files with 27 additions and 7 deletions

View File

@@ -1,7 +1,8 @@
import appContext from "../../components/app_context.js";
import appContext, { type EventData } from "../../components/app_context.js";
import type { NoteType } from "../../entities/fnote.js";
import { t } from "../../services/i18n.js";
import type { ViewScope } from "../../services/link.js";
import type { ViewTypeOptions } from "../../services/note_list_renderer.js";
import NoteContextAwareWidget from "../note_context_aware_widget.js";
const TPL = `
@@ -10,8 +11,7 @@ const TPL = `
</button>
`;
const byNoteType: Record<NoteType, string | null> = {
book: null,
const byNoteType: Record<Exclude<NoteType, "book">, string | null> = {
canvas: null,
code: null,
contentWidget: null,
@@ -30,6 +30,12 @@ const byNoteType: Record<NoteType, string | null> = {
webView: null
};
const byBookType: Record<ViewTypeOptions, string | null> = {
list: null,
grid: null,
calendar: "fDGg7QcJg3Xm"
};
export default class ContextualHelpButton extends NoteContextAwareWidget {
private helpNoteIdToOpen?: string | null;
@@ -41,8 +47,10 @@ export default class ContextualHelpButton extends NoteContextAwareWidget {
return false;
}
if (this.note && byNoteType[this.note.type]) {
if (this.note && this.note.type !== "book" && byNoteType[this.note.type]) {
this.helpNoteIdToOpen = byNoteType[this.note.type];
} else if (this.note && this.note.type === "book") {
this.helpNoteIdToOpen = byBookType[this.note.getAttributeValue("label", "viewType") as ViewTypeOptions ?? ""]
}
return !!this.helpNoteIdToOpen;
@@ -73,4 +81,10 @@ export default class ContextualHelpButton extends NoteContextAwareWidget {
});
}
entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
if (this.note?.type === "book" && loadResults.getAttributeRows().find((attr) => attr.noteId === this.noteId && attr.name === "viewType")) {
this.refresh();
}
}
}