mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 16:02:26 +00:00
🧹 refactor: use shared truncateMiddle in DeleteModal
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 <[email protected]>
This commit is contained in:
1 parent
c5388fac76
commit
6fc024da8d
1 file changed
+2
-16
@@ -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;
|
||||
|
||||
|
||||
Reference in new issue
Block a user