chore(client): review from Gemini

This commit is contained in:
Elian Doran
2025-11-09 15:10:40 +02:00
parent 40a7f286a3
commit 1257e46852
12 changed files with 37 additions and 62 deletions

View File

@@ -668,7 +668,7 @@ export class AppContext extends Component {
} }
removeBeforeUnloadListener(listener: (() => boolean)) { removeBeforeUnloadListener(listener: (() => boolean)) {
this.beforeUnloadListeners = this.beforeUnloadListeners.filter(l => l === listener); this.beforeUnloadListeners = this.beforeUnloadListeners.filter(l => l !== listener);
} }
} }

View File

@@ -175,7 +175,6 @@ export default class Entrypoints extends Component {
return; return;
} }
const { ntxId, note } = noteContext; const { ntxId, note } = noteContext;
console.log("Run active note");
// ctrl+enter is also used elsewhere, so make sure we're running only when appropriate // ctrl+enter is also used elsewhere, so make sure we're running only when appropriate
if (!note || note.type !== "code") { if (!note || note.type !== "code") {

View File

@@ -873,29 +873,6 @@ export function getErrorMessage(e: unknown) {
} }
} }
// TODO: Deduplicate with server
export interface DeferredPromise<T> extends Promise<T> {
resolve: (value: T | PromiseLike<T>) => void;
reject: (reason?: any) => void;
}
// TODO: Deduplicate with server
export function deferred<T>(): DeferredPromise<T> {
return (() => {
let resolve!: (value: T | PromiseLike<T>) => void;
let reject!: (reason?: any) => void;
let promise = new Promise<T>((res, rej) => {
resolve = res;
reject = rej;
}) as DeferredPromise<T>;
promise.resolve = resolve;
promise.reject = reject;
return promise as DeferredPromise<T>;
})();
}
/** /**
* Handles left or right placement of e.g. tooltips in case of right-to-left languages. If the current language is a RTL one, then left and right are swapped. Other directions are unaffected. * Handles left or right placement of e.g. tooltips in case of right-to-left languages. If the current language is a RTL one, then left and right are swapped. Other directions are unaffected.
* @param placement a string optionally containing a "left" or "right" value. * @param placement a string optionally containing a "left" or "right" value.

View File

@@ -40,7 +40,6 @@ export default function AiChat({ note, noteContext }: TypeWidgetProps) {
useEffect(() => { useEffect(() => {
llmChatPanel.setNoteId(note.noteId); llmChatPanel.setNoteId(note.noteId);
llmChatPanel.setCurrentNoteId(note.noteId); llmChatPanel.setCurrentNoteId(note.noteId);
console.log("Refresh!");
}, [ note ]); }, [ note ]);
return ChatWidget; return ChatWidget;

View File

@@ -20,7 +20,6 @@ export default function Doc({ note, viewScope, ntxId }: TypeWidgetProps) {
}, [ note ]); }, [ note ]);
useTriliumEvent("executeWithContentElement", async ({ resolve, ntxId: eventNtxId}) => { useTriliumEvent("executeWithContentElement", async ({ resolve, ntxId: eventNtxId}) => {
console.log("Got request for content ", ntxId, eventNtxId);
if (eventNtxId !== ntxId) return; if (eventNtxId !== ntxId) return;
await initialized.current; await initialized.current;
resolve(refToJQuerySelector(containerRef)); resolve(refToJQuerySelector(containerRef));

View File

@@ -1,7 +1,7 @@
import { useEffect, useRef, useState } from "preact/hooks"; import { useEffect, useRef, useState } from "preact/hooks";
import dialog from "../../../services/dialog"; import dialog from "../../../services/dialog";
import toast from "../../../services/toast"; import toast from "../../../services/toast";
import utils, { deferred, hasTouchBar, isMobile } from "../../../services/utils"; import utils, { hasTouchBar, isMobile } from "../../../services/utils";
import { useEditorSpacedUpdate, useKeyboardShortcuts, useLegacyImperativeHandlers, useNoteLabel, useTriliumEvent, useTriliumOption, useTriliumOptionBool } from "../../react/hooks"; import { useEditorSpacedUpdate, useKeyboardShortcuts, useLegacyImperativeHandlers, useNoteLabel, useTriliumEvent, useTriliumOption, useTriliumOptionBool } from "../../react/hooks";
import { TypeWidgetProps } from "../type_widget"; import { TypeWidgetProps } from "../type_widget";
import CKEditorWithWatchdog, { CKEditorApi } from "./CKEditorWithWatchdog"; import CKEditorWithWatchdog, { CKEditorApi } from "./CKEditorWithWatchdog";
@@ -17,6 +17,7 @@ import note_create from "../../../services/note_create";
import TouchBar, { TouchBarButton, TouchBarGroup, TouchBarSegmentedControl } from "../../react/TouchBar"; import TouchBar, { TouchBarButton, TouchBarGroup, TouchBarSegmentedControl } from "../../react/TouchBar";
import { RefObject } from "preact"; import { RefObject } from "preact";
import { buildSelectedBackgroundColor } from "../../../components/touch_bar"; import { buildSelectedBackgroundColor } from "../../../components/touch_bar";
import { deferred } from "@triliumnext/commons";
/** /**
* The editor can operate into two distinct modes: * The editor can operate into two distinct modes:
@@ -202,6 +203,7 @@ export default function EditableText({ note, parentComponent, ntxId, noteContext
const customDateTimeFormat = options.get("customDateTimeFormat"); const customDateTimeFormat = options.get("customDateTimeFormat");
const dateString = utils.formatDateTime(date, customDateTimeFormat); const dateString = utils.formatDateTime(date, customDateTimeFormat);
console.log("Insert text ", ntxId, eventNtxId, dateString);
addTextToEditor(dateString); addTextToEditor(dateString);
}); });
useTriliumEvent("addTextToActiveEditor", ({ text }) => { useTriliumEvent("addTextToActiveEditor", ({ text }) => {

View File

@@ -4,9 +4,8 @@ import hiddenSubtreeService from "./hidden_subtree.js";
import sql_init from "./sql_init.js"; import sql_init from "./sql_init.js";
import branches from "./branches.js"; import branches from "./branches.js";
import becca from "../becca/becca.js"; import becca from "../becca/becca.js";
import { LOCALES } from "@triliumnext/commons"; import { deferred, LOCALES } from "@triliumnext/commons";
import { changeLanguage } from "./i18n.js"; import { changeLanguage } from "./i18n.js";
import { deferred } from "./utils.js";
describe("Hidden Subtree", () => { describe("Hidden Subtree", () => {
beforeAll(async () => { beforeAll(async () => {

View File

@@ -2,7 +2,7 @@ import log from "./log.js";
import fs from "fs"; import fs from "fs";
import resourceDir from "./resource_dir.js"; import resourceDir from "./resource_dir.js";
import sql from "./sql.js"; import sql from "./sql.js";
import { isElectron, deferred } from "./utils.js"; import { isElectron } from "./utils.js";
import optionService from "./options.js"; import optionService from "./options.js";
import port from "./port.js"; import port from "./port.js";
import BOption from "../becca/entities/boption.js"; import BOption from "../becca/entities/boption.js";
@@ -10,7 +10,7 @@ import TaskContext from "./task_context.js";
import migrationService from "./migration.js"; import migrationService from "./migration.js";
import cls from "./cls.js"; import cls from "./cls.js";
import config from "./config.js"; import config from "./config.js";
import type { OptionRow } from "@triliumnext/commons"; import { deferred, type OptionRow } from "@triliumnext/commons";
import BNote from "../becca/entities/bnote.js"; import BNote from "../becca/entities/bnote.js";
import BBranch from "../becca/entities/bbranch.js"; import BBranch from "../becca/entities/bbranch.js";
import zipImportService from "./import/zip.js"; import zipImportService from "./import/zip.js";

View File

@@ -379,14 +379,6 @@ describe("#timeLimit", () => {
}); });
}); });
describe("#deferred", () => {
it("should return a promise", () => {
const result = utils.deferred();
expect(result).toBeInstanceOf(Promise);
});
// TriliumNextTODO: Add further tests!
});
describe("#removeDiacritic", () => { describe("#removeDiacritic", () => {
const testCases: TestCase<typeof utils.removeDiacritic>[] = [ const testCases: TestCase<typeof utils.removeDiacritic>[] = [
[ "w/ 'Äpfel' it should replace the 'Ä'", [ "Äpfel" ], "Apfel" ], [ "w/ 'Äpfel' it should replace the 'Ä'", [ "Äpfel" ], "Apfel" ],

View File

@@ -229,27 +229,6 @@ export function timeLimit<T>(promise: Promise<T>, limitMs: number, errorMessage?
}); });
} }
export interface DeferredPromise<T> extends Promise<T> {
resolve: (value: T | PromiseLike<T>) => void;
reject: (reason?: any) => void;
}
export function deferred<T>(): DeferredPromise<T> {
return (() => {
let resolve!: (value: T | PromiseLike<T>) => void;
let reject!: (reason?: any) => void;
let promise = new Promise<T>((res, rej) => {
resolve = res;
reject = rej;
}) as DeferredPromise<T>;
promise.resolve = resolve;
promise.reject = reject;
return promise as DeferredPromise<T>;
})();
}
export function removeDiacritic(str: string) { export function removeDiacritic(str: string) {
if (!str) { if (!str) {
return ""; return "";
@@ -508,7 +487,6 @@ function slugify(text: string) {
export default { export default {
compareVersions, compareVersions,
crash, crash,
deferred,
envToBoolean, envToBoolean,
escapeHtml, escapeHtml,
escapeRegExp, escapeRegExp,

View File

@@ -0,0 +1,9 @@
import { deferred } from "./utils.js";
describe("#deferred", () => {
it("should return a promise", () => {
const result = deferred();
expect(result).toBeInstanceOf(Promise);
});
// TriliumNextTODO: Add further tests!
});

View File

@@ -9,3 +9,24 @@ export function formatLogMessage(message: string | object) {
return message; return message;
} }
export interface DeferredPromise<T> extends Promise<T> {
resolve: (value: T | PromiseLike<T>) => void;
reject: (reason?: any) => void;
}
export function deferred<T>(): DeferredPromise<T> {
return (() => {
let resolve!: (value: T | PromiseLike<T>) => void;
let reject!: (reason?: any) => void;
let promise = new Promise<T>((res, rej) => {
resolve = res;
reject = rej;
}) as DeferredPromise<T>;
promise.resolve = resolve;
promise.reject = reject;
return promise as DeferredPromise<T>;
})();
}