diff --git a/src/popup/popup.ts b/src/popup/popup.ts index 4d1bad3..6a8a34a 100644 --- a/src/popup/popup.ts +++ b/src/popup/popup.ts @@ -316,13 +316,10 @@ async function loadPDFQueue() { */ async function syncWithServer() { if (!currentCredentials) { - console.log('[Popup] No credentials, skipping server sync'); return; } try { - console.log('[Popup] Syncing with Binect server...'); - // Get list of documents from server const result = await chrome.runtime.sendMessage({ action: 'listServerDocuments', @@ -330,8 +327,6 @@ async function syncWithServer() { password: currentCredentials.password }); - console.log('[Popup] listServerDocuments result:', result); - if (!result.success || !result.documents) { console.warn('[Popup] Failed to list server documents:', result.error); return; @@ -347,15 +342,11 @@ async function syncWithServer() { errorDetails?: string; }>; - console.log('[Popup] Found', serverDocs.length, 'documents on server'); - for (const doc of serverDocs) { - console.log('[Popup] Server doc:', doc.id, doc.filename, 'status:', doc.status, doc.statusText); - } + console.log('[Popup] Syncing', serverDocs.length, 'server documents'); // Sync each server document to local proxy for (const doc of serverDocs) { - console.log('[Popup] Syncing doc', doc.id, 'to local proxy...'); - const syncResult = await chrome.runtime.sendMessage({ + await chrome.runtime.sendMessage({ action: 'syncFromServer', binectDocumentId: doc.id, filename: doc.filename, @@ -365,10 +356,7 @@ async function syncWithServer() { recipientAddress: doc.recipientAddress, errorDetails: doc.errorDetails }); - console.log('[Popup] Sync result for doc', doc.id, ':', syncResult); } - - console.log('[Popup] Server sync complete'); } catch (error) { console.error('[Popup] Server sync error:', error); } @@ -444,13 +432,20 @@ function renderPDFList() { `; } else { // Live view - group by Binect status - const pendingUpload = pdfQueue.filter(p => p.binectStatus === 'pending' || p.binectStatus === 'uploading' || p.binectStatus === 'failed'); + // Separate truly local pending uploads from server documents with errors + const pendingUpload = pdfQueue.filter(p => + (p.binectStatus === 'pending' || p.binectStatus === 'uploading') || + (p.binectStatus === 'failed' && !p.binectDocumentId) // Local failed uploads + ); + const erroneous = pdfQueue.filter(p => + p.binectStatus === 'failed' && p.binectDocumentId // Server documents with errors + ); const inBasket = pdfQueue.filter(p => p.binectStatus === 'in_basket' || p.binectStatus === 'ordering'); const inProduction = pdfQueue.filter(p => p.binectStatus === 'in_production'); const completed = pdfQueue.filter(p => p.binectStatus === 'sent' || p.binectStatus === 'canceled'); // Count actionable items - const actionableCount = pendingUpload.length + inBasket.length; + const actionableCount = pendingUpload.length + erroneous.length + inBasket.length; // Update count if (actionableCount > 0) { @@ -470,6 +465,13 @@ function renderPDFList() { `; } + if (erroneous.length > 0) { + html += `
+
Has Errors
+ ${erroneous.map(pdf => renderPDFItem(pdf, 'erroneous')).join('')} +
`; + } + if (inBasket.length > 0) { html += `
In Basket
@@ -504,7 +506,7 @@ function renderPDFList() { /** * Render a single PDF item */ -function renderPDFItem(pdf: DocumentProxy, section: 'pending' | 'basket' | 'production' | 'completed' | 'archived'): string { +function renderPDFItem(pdf: DocumentProxy, section: 'pending' | 'erroneous' | 'basket' | 'production' | 'completed' | 'archived'): string { const statusClass = getStatusClass(pdf.binectStatus); const statusText = getStatusText(pdf); const priceText = pdf.price ? `${(pdf.price / 100).toFixed(2)} €` : ''; @@ -522,10 +524,13 @@ function renderPDFItem(pdf: DocumentProxy, section: 'pending' | 'basket' | 'prod - ${canDeleteFromServer - ? `` - : `` - } + + `; + break; + case 'erroneous': + // Server documents with errors - can only delete from server + actionsHtml = ` + `; break; case 'basket': @@ -563,6 +568,20 @@ function renderPDFItem(pdf: DocumentProxy, section: 'pending' | 'basket' | 'prod // Show detailed error info for erroneous documents const hasErrorDetails = pdf.binectStatus === 'failed' && pdf.errorMessage && pdf.binectStatusCode === 7; + // Build metadata parts - only include what we have + const metaParts: string[] = []; + if (pdf.size > 0) { + metaParts.push(formatFileSize(pdf.size)); + } + if (pdf.sourceDomain && pdf.sourceDomain !== 'binect.de') { + metaParts.push(escapeHtml(pdf.sourceDomain)); + } else if (pdf.binectDocumentId && pdf.sourceDomain === 'binect.de') { + metaParts.push(`ID: ${pdf.binectDocumentId}`); + } + if (priceText) { + metaParts.push(`${priceText}`); + } + return `
${getStatusIcon(pdf.binectStatus)}
@@ -571,10 +590,7 @@ function renderPDFItem(pdf: DocumentProxy, section: 'pending' | 'basket' | 'prod ${escapeHtml(displayFilename)} ${isLocalOnly ? 'local' : ''}
-
- ${formatFileSize(pdf.size)} · ${escapeHtml(pdf.sourceDomain)} - ${priceText ? ` · ${priceText}` : ''} -
+ ${metaParts.length > 0 ? `
${metaParts.join(' · ')}
` : ''} ${pdf.recipientAddress ? `
${escapeHtml(pdf.recipientAddress.split('\n')[0])}
` : ''}
${statusText}
${hasErrorDetails ? `
${escapeHtml(pdf.errorMessage!)}
` : ''} diff --git a/src/utils/binect-api.ts b/src/utils/binect-api.ts index 567b98b..a9fd526 100644 --- a/src/utils/binect-api.ts +++ b/src/utils/binect-api.ts @@ -500,23 +500,17 @@ export async function listServerDocuments( }); // Get shippable documents (status 2) - console.log('[Binect API] Fetching shippable documents...'); const shippableResponse = await client.documents.list(); - console.log('[Binect API] Shippable response:', JSON.stringify(shippableResponse)); const shippable = shippableResponse.items || []; - console.log('[Binect API] Found', shippable.length, 'shippable documents'); // Get erroneous documents (status 7) - console.log('[Binect API] Fetching erroneous documents...'); const errorsResponse = await client.documents.listErrors(); - console.log('[Binect API] Errors response:', JSON.stringify(errorsResponse)); const erroneous = errorsResponse.items || []; - console.log('[Binect API] Found', erroneous.length, 'erroneous documents'); // Combine and map to our format const allDocs = [...shippable, ...erroneous]; - console.log('[Binect API] Total documents on server:', allDocs.length); + console.log('[Binect API] Found', allDocs.length, 'documents on server (', shippable.length, 'shippable,', erroneous.length, 'erroneous)'); return allDocs.map(doc => { let errorDetails: string | undefined;