Legal Document Collaboration Platform

Initializing Collaboration Platform...

No comments yet.

'; return; } pdfListEl.innerHTML = '

Comments

'; comments.sort((a,b) => (a.createdAt?.seconds || 0) - (b.createdAt?.seconds || 0)).forEach(comment => { const date = comment.createdAt ? new Date(comment.createdAt.seconds * 1000).toLocaleString() : 'Just now'; const isCurrentUser = comment.authorId === userId; // Main UI Comment Bubble const commentEl = document.createElement('div'); commentEl.className = `p-3 rounded-lg mb-3 ${isCurrentUser ? 'bg-amber-800/50 ml-auto' : 'bg-slate-700'} max-w-xs`; commentEl.innerHTML = `

${comment.text}

${isCurrentUser ? 'You' : 'User ' + comment.authorId.substring(0,6)} • ${date}

`; listEl.appendChild(commentEl); // PDF Comment Item const pdfCommentEl = document.createElement('div'); pdfCommentEl.className = 'mb-4 pb-2 border-b border-slate-700'; pdfCommentEl.innerHTML = `

${comment.text}

By: ${comment.authorId} on ${date}

`; pdfListEl.appendChild(pdfCommentEl); }); listEl.scrollTop = listEl.scrollHeight; }; const handleAddComment = async (e) => { e.preventDefault(); const input = document.getElementById('comment-input'); const text = input.value.trim(); if (!text || !currentDocId) return; const newComment = { text, authorId: userId, createdAt: serverTimestamp() }; try { const docRef = doc(db, DOCS_COLLECTION_PATH, currentDocId); await updateDoc(docRef, { comments: arrayUnion(newComment) }); input.value = ''; } catch (error) { console.error("Error adding comment:", error); alert("Failed to add comment."); } }; const handleBackToLobby = () => { if(unsubscribeDoc) unsubscribeDoc(); unsubscribeDoc = null; currentDocId = null; showView(lobbyView); }; const handleDownloadPDF = () => { const content = document.getElementById('pdf-content'); if (!content) return; html2canvas(content, { scale: 2, backgroundColor: '#0f172a', // slate-900 useCORS: true }).then(canvas => { const imgData = canvas.toDataURL('image/png'); const { jsPDF } = window.jspdf; const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const canvasWidth = canvas.width; const canvasHeight = canvas.height; const ratio = canvasWidth / canvasHeight; const imgWidth = pdfWidth - 20; const imgHeight = imgWidth / ratio; pdf.addImage(imgData, 'PNG', 10, 10, imgWidth, imgHeight); const title = document.getElementById('doc-title-display').textContent; pdf.save(`${title.replace(/ /g, '_')}_Collaboration.pdf`); }); }; // --- EVENT LISTENERS --- createDocForm.addEventListener('submit', handleCreateDocument); joinDocForm.addEventListener('submit', handleJoinDocument); backToLobbyBtn.addEventListener('click', handleBackToLobby); commentForm.addEventListener('submit', handleAddComment); downloadPdfBtn.addEventListener('click', handleDownloadPDF); });
Scroll to Top