@@ -13,6 +13,7 @@ export function truncate(s, max) {
1313export function formatTs ( ts ) {
1414 try {
1515 const d = new Date ( ts ) ;
16+ if ( isNaN ( d . getTime ( ) ) ) return ts ;
1617 const mm = String ( d . getUTCMonth ( ) + 1 ) . padStart ( 2 , '0' ) ;
1718 const dd = String ( d . getUTCDate ( ) ) . padStart ( 2 , '0' ) ;
1819 const yyyy = d . getUTCFullYear ( ) ;
@@ -29,6 +30,7 @@ export function formatTs(ts) {
2930export function formatDate ( ts ) {
3031 try {
3132 const d = new Date ( ts ) ;
33+ if ( isNaN ( d . getTime ( ) ) ) return ts ? ts . slice ( 0 , 10 ) : '' ;
3234 const mm = String ( d . getUTCMonth ( ) + 1 ) . padStart ( 2 , '0' ) ;
3335 const dd = String ( d . getUTCDate ( ) ) . padStart ( 2 , '0' ) ;
3436 const yyyy = d . getUTCFullYear ( ) ;
@@ -37,7 +39,7 @@ export function formatDate(ts) {
3739}
3840
3941export function formatSize ( bytes ) {
40- if ( ! bytes ) return '?' ;
42+ if ( bytes == null ) return '?' ;
4143 if ( bytes < 1024 ) return bytes + ' B' ;
4244 if ( bytes < 1048576 ) return ( bytes / 1024 ) . toFixed ( 1 ) + ' KB' ;
4345 return ( bytes / 1048576 ) . toFixed ( 1 ) + ' MB' ;
@@ -59,9 +61,20 @@ export function showToast(message, type = 'info') {
5961 const icons = { success : '\u2713' , error : '\u2717' , info : '\u2139' } ;
6062 const toast = document . createElement ( 'div' ) ;
6163 toast . className = `toast toast-${ type } ` ;
62- toast . innerHTML = `<span class="toast-icon">${ icons [ type ] || icons . info } </span><span class="toast-text">${ message } </span><button class="toast-close">\u00d7</button><div class="toast-progress"></div>` ;
64+ const iconSpan = document . createElement ( 'span' ) ;
65+ iconSpan . className = 'toast-icon' ;
66+ iconSpan . textContent = icons [ type ] || icons . info ;
67+ const textSpan = document . createElement ( 'span' ) ;
68+ textSpan . className = 'toast-text' ;
69+ textSpan . textContent = message ;
70+ const closeBtn = document . createElement ( 'button' ) ;
71+ closeBtn . className = 'toast-close' ;
72+ closeBtn . textContent = '\u00d7' ;
73+ const progress = document . createElement ( 'div' ) ;
74+ progress . className = 'toast-progress' ;
75+ toast . append ( iconSpan , textSpan , closeBtn , progress ) ;
6376 document . body . appendChild ( toast ) ;
64- toast . querySelector ( '.toast-close' ) . addEventListener ( 'click' , ( ) => { toast . classList . remove ( 'show' ) ; setTimeout ( ( ) => toast . remove ( ) , 300 ) ; } ) ;
77+ closeBtn . addEventListener ( 'click' , ( ) => { toast . classList . remove ( 'show' ) ; setTimeout ( ( ) => toast . remove ( ) , 300 ) ; } ) ;
6578 requestAnimationFrame ( ( ) => toast . classList . add ( 'show' ) ) ;
6679 setTimeout ( ( ) => {
6780 toast . classList . remove ( 'show' ) ;
@@ -74,16 +87,16 @@ export function showConfirm(message, onConfirm) {
7487 overlay . className = 'confirm-overlay' ;
7588 const dialog = document . createElement ( 'div' ) ;
7689 dialog . className = 'confirm-dialog' ;
77- dialog . innerHTML = `
78- <div class=" confirm-header">
79- <span class="confirm-icon">?</span>
80- <span class="confirm-title">Confirm Action</span>
81- </div>
82- <p class="confirm- message"> ${ message } </p>
83- < div class="confirm-actions">
84- <button class="confirm-btn confirm-cancel">Cancel</button>
85- < button class="confirm-btn confirm-ok">Confirm</button>
86- </div>` ;
90+ const header = document . createElement ( 'div' ) ;
91+ header . className = ' confirm-header' ;
92+ header . innerHTML = ' <span class="confirm-icon">?</span><span class="confirm-title">Confirm Action</span>' ;
93+ const msgEl = document . createElement ( 'p' ) ;
94+ msgEl . className = 'confirm-message' ;
95+ msgEl . textContent = message ;
96+ const actions = document . createElement ( ' div' ) ;
97+ actions . className = ' confirm-actions' ;
98+ actions . innerHTML = '<button class="confirm-btn confirm-cancel">Cancel</ button><button class="confirm-btn confirm-ok">Confirm</button>' ;
99+ dialog . append ( header , msgEl , actions ) ;
87100 overlay . appendChild ( dialog ) ;
88101 document . body . appendChild ( overlay ) ;
89102 requestAnimationFrame ( ( ) => overlay . classList . add ( 'show' ) ) ;
0 commit comments