From d1f8e651f46c6a06f8f3cdf7c38b634176cc6296 Mon Sep 17 00:00:00 2001 From: iamvann Date: Tue, 20 May 2025 19:46:50 +0800 Subject: [PATCH] fix: address the review feedback --- apps/client/src/services/utils.ts | 20 ++++++------------- .../src/translations/en/translation.json | 11 ++++++++++ .../src/widgets/type_widgets/editable_text.ts | 10 +--------- .../options/text_notes/date_time_format.ts | 18 ++++++++--------- 4 files changed, 27 insertions(+), 32 deletions(-) diff --git a/apps/client/src/services/utils.ts b/apps/client/src/services/utils.ts index 92ca2bc70..c31faf98d 100644 --- a/apps/client/src/services/utils.ts +++ b/apps/client/src/services/utils.ts @@ -125,22 +125,14 @@ function formatDateISO(date: Date) { } -// old version -// function formatDateTime(date: Date) { -// return `${formatDate(date)} ${formatTime(date)}`; -// } - -// new version -export function formatDateTime(date: Date, userSuppliedFormat?: string): string { - const DEFAULT_FORMAT = 'YYYY-MM-DD HH:mm'; - let formatToUse = DEFAULT_FORMAT; - - if (userSuppliedFormat && typeof userSuppliedFormat === 'string' && userSuppliedFormat.trim() !== "") { - formatToUse = userSuppliedFormat.trim(); - } +export function formatDateTime(date: Date, userSuppliedFormat?: string): string { + const DEFAULT_FORMAT = 'YYYY-MM-DD HH:mm'; + const formatToUse = (typeof userSuppliedFormat === 'string' && userSuppliedFormat.trim() !== "") + ? userSuppliedFormat.trim() + : DEFAULT_FORMAT; if (!date) { - date = new Date(); + date = new Date(); } try { diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json index 24f104441..efa2e5a83 100644 --- a/apps/client/src/translations/en/translation.json +++ b/apps/client/src/translations/en/translation.json @@ -1956,5 +1956,16 @@ "title": "Appearance", "word_wrapping": "Word wrapping", "color-scheme": "Color scheme" + }, + "custom_date_time_format": { + "title": "Custom Date/Time Format (Alt+T)", + "desc1": "Define a custom format for the date and time inserted using the Alt+T shortcut.", + "desc2": "Uses Day.js format tokens. Refer to the Day.js documentation for valid tokens.", + "important_label": "Important:", + "desc3": "If you provide a format string that Day.js does not recognize (e.g., mostly plain text without valid Day.js tokens), the text you typed might be inserted literally. If the format string is left empty, or if Day.js encounters a critical internal error with your format, a default format (e.g., YYYY-MM-DD HH:mm) will be used.", + "format_string_label": "Format String:", + "placeholder": "e.g., DD/MM/YYYY HH:mm:ss or dddd, MMMM D", + "examples_label": "Examples of valid Day.js formats:", + "example_default": "Default-like" } } diff --git a/apps/client/src/widgets/type_widgets/editable_text.ts b/apps/client/src/widgets/type_widgets/editable_text.ts index 4e530f990..1670a0ce1 100644 --- a/apps/client/src/widgets/type_widgets/editable_text.ts +++ b/apps/client/src/widgets/type_widgets/editable_text.ts @@ -287,7 +287,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget { // Touch bar integration if (hasTouchBar) { - for (const event of ["bold", "italic", "underline", "paragraph", "heading"]) { + for (const event of [ "bold", "italic", "underline", "paragraph", "heading" ]) { editor.commands.get(event)?.on("change", () => this.triggerCommand("refreshTouchBar")); } } @@ -373,15 +373,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget { }); } } - // old version - // insertDateTimeToTextCommand() { - // const date = new Date(); - // const dateString = utils.formatDateTime(date); - // this.addTextToEditor(dateString); - // } - - // new version async insertDateTimeToTextCommand() { const date = new Date(); let userPreferredFormat = ""; diff --git a/apps/client/src/widgets/type_widgets/options/text_notes/date_time_format.ts b/apps/client/src/widgets/type_widgets/options/text_notes/date_time_format.ts index 7ddf05565..0690e77a9 100644 --- a/apps/client/src/widgets/type_widgets/options/text_notes/date_time_format.ts +++ b/apps/client/src/widgets/type_widgets/options/text_notes/date_time_format.ts @@ -5,28 +5,28 @@ import type { OptionMap } from "@triliumnext/commons"; const TPL = /*html*/`
-

${t("options.customDateTimeFormatTitle", "Custom Date/Time Format (Alt+T)")}

+

${t("custom_date_time_format.title")}

- ${t("options.customDateTimeFormatDesc1", "Define a custom format for the date and time inserted using the Alt+T shortcut.")} - ${t("options.customDateTimeFormatDesc2", "Uses Day.js format tokens. Refer to the Day.js documentation for valid tokens.")} + ${t("custom_date_time_format.desc1")} + ${t("custom_date_time_format.desc2")}

- ${t("options.customDateTimeFormatImportant", "Important:")} - ${t("options.customDateTimeFormatDesc3", "If you provide a format string that Day.js does not recognize (e.g., mostly plain text without valid Day.js tokens), the text you typed might be inserted literally. If the format string is left empty, or if Day.js encounters a critical internal error with your format, a default format (e.g., YYYY-MM-DD HH:mm) will be used.")} + ${t("custom_date_time_format.important_label")} + ${t("custom_date_time_format.desc3")}

- ${t("options.customDateTimeFormatExamplesLabel", "Examples of valid Day.js formats:")} - YYYY-MM-DD HH:mm (${t("options.customDateTimeFormatExampleDefault", "Default-like")}), + ${t("custom_date_time_format.examples_label")} + YYYY-MM-DD HH:mm (${t("custom_date_time_format.example_default")}), DD.MM.YYYY, MMMM D, YYYY h:mm A, [Today is] dddd