From 6fc024da8ddd7d7179e33db323f2fb474ffced44 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 26 Feb 2026 18:03:17 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20refactor:=20use=20shared=20trunc?= =?UTF-8?q?ateMiddle=20in=20DeleteModal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed the duplicated string truncation logic in `js/ui/components/DeleteModal.js` and replaced it with the shared `truncateMiddle` utility from `js/utils/formatters.js`. This improves maintainability and ensures consistent string truncation behavior across the application. Co-authored-by: PR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> --- js/ui/components/DeleteModal.js | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/js/ui/components/DeleteModal.js b/js/ui/components/DeleteModal.js index d3ef17ac..853f9dfe 100644 --- a/js/ui/components/DeleteModal.js +++ b/js/ui/components/DeleteModal.js @@ -1,3 +1,4 @@ +import { truncateMiddle as defaultTruncateMiddle } from "../../utils/formatters.js"; import { createModalAccessibility } from "./modalAccessibility.js"; function extractDTagValue(tags) { @@ -28,22 +29,7 @@ export class DeleteModal { this.setGlobalModalState = typeof setGlobalModalState === "function" ? setGlobalModalState : () => {}; this.truncateMiddle = - typeof truncateMiddle === "function" ? truncateMiddle : (value, maxLength = 48) => { - if (typeof value !== "string") { - return ""; - } - if (value.length <= maxLength) { - return value; - } - if (maxLength <= 1) { - return value.slice(0, maxLength); - } - const ellipsis = "…"; - const charsToShow = maxLength - ellipsis.length; - const front = Math.ceil(charsToShow / 2); - const back = Math.floor(charsToShow / 2); - return `${value.slice(0, front)}${ellipsis}${value.slice(value.length - back)}`; - }; + typeof truncateMiddle === "function" ? truncateMiddle : defaultTruncateMiddle; this.eventTarget = eventTarget instanceof EventTarget ? eventTarget : new EventTarget(); this.container = container || document.getElementById("modalContainer") || null;