refactor(client): remove string from viewtype

This commit is contained in:
Elian Doran 2025-10-01 19:44:55 +03:00
parent efcd54be50
commit 873c4c6636
No known key found for this signature in database
2 changed files with 4 additions and 5 deletions

View File

@ -35,8 +35,7 @@ async function getLinkIcon(noteId: string, viewMode: ViewMode | undefined) {
return icon; return icon;
} }
// TODO: Remove `string` once all the view modes have been mapped. export type ViewMode = "default" | "source" | "attachments" | "contextual-help";
export type ViewMode = "default" | "source" | "attachments" | "contextual-help" | string;
export interface ViewScope { export interface ViewScope {
/** /**

View File

@ -1,7 +1,7 @@
import TypeWidget from "./type_widget.js"; import TypeWidget from "./type_widget.js";
import appContext, { type EventData } from "../../components/app_context.js"; import appContext, { type EventData } from "../../components/app_context.js";
import froca from "../../services/froca.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 contentRenderer from "../../services/content_renderer.js";
import utils from "../../services/utils.js"; import utils from "../../services/utils.js";
import options from "../../services/options.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) { async openImageInNewTab($img: JQuery<HTMLElement>, activate: boolean = false) {
const parsedImage = await this.parseFromImage($img); const parsedImage = await this.parseFromImage($img);
if (parsedImage) { if (parsedImage?.noteId) {
appContext.tabManager.openTabWithNoteWithHoisting(parsedImage.noteId, { activate, viewScope: parsedImage.viewScope }); appContext.tabManager.openTabWithNoteWithHoisting(parsedImage.noteId, { activate, viewScope: parsedImage.viewScope });
} else { } else {
window.open($img.prop("src"), "_blank"); 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 imgSrc = $img.prop("src");
const imageNoteMatch = imgSrc.match(/\/api\/images\/([A-Za-z0-9_]+)\//); const imageNoteMatch = imgSrc.match(/\/api\/images\/([A-Za-z0-9_]+)\//);