Skip to content

Build your personal knowledge base with Trilium Notes

refactor(client): remove string from viewtype

Elian Doran873c4c6636cf
diff --git a/apps/client/src/services/link.ts b/apps/client/src/services/link.ts
index 7a7b8b924a..f31400fc16 100644
--- a/apps/client/src/services/link.ts
+++ b/apps/client/src/services/link.ts
@@ -35,8 +35,7 @@ async function getLinkIcon(noteId: string, viewMode: ViewMode | undefined) {
return icon;
}
-// TODO: Remove `string` once all the view modes have been mapped.
-export type ViewMode = "default" | "source" | "attachments" | "contextual-help" | string;
+export type ViewMode = "default" | "source" | "attachments" | "contextual-help";
export interface ViewScope {
/**
diff --git a/apps/client/src/widgets/type_widgets/abstract_text_type_widget.ts b/apps/client/src/widgets/type_widgets/abstract_text_type_widget.ts
index 5061d3b57b..dca5ec5cc9 100644
--- a/apps/client/src/widgets/type_widgets/abstract_text_type_widget.ts
+++ b/apps/client/src/widgets/type_widgets/abstract_text_type_widget.ts
@@ -1,7 +1,7 @@
import TypeWidget from "./type_widget.js";
import appContext, { type EventData } from "../../components/app_context.js";
import froca from "../../services/froca.js";
-import linkService from "../../services/link.js";
+import linkService, { type ViewScope } from "../../services/link.js";
import contentRenderer from "../../services/content_renderer.js";
import utils from "../../services/utils.js";
import options from "../../services/options.js";
@@ -44,14 +44,14 @@ export default class AbstractTextTypeWidget extends TypeWidget {
async openImageInNewTab($img: JQuery<HTMLElement>, activate: boolean = false) {
const parsedImage = await this.parseFromImage($img);
- if (parsedImage) {
+ if (parsedImage?.noteId) {
appContext.tabManager.openTabWithNoteWithHoisting(parsedImage.noteId, { activate, viewScope: parsedImage.viewScope });
} else {
window.open($img.prop("src"), "_blank");
}
}
- async parseFromImage($img: JQuery<HTMLElement>) {
+ async parseFromImage($img: JQuery<HTMLElement>): Promise<{ noteId?: string, viewScope: ViewScope } | null> {
const imgSrc = $img.prop("src");
const imageNoteMatch = imgSrc.match(/\/api\/images\/([A-Za-z0-9_]+)\//);