Real-Time Brainstorming Assistant
Create a new session or join an existing one to start collaborating.
OR
Brainstorming Session
Session ID:
No ideas yet. Be the first to add one!
${idea.text}
`; elements.ideaBoard.appendChild(card); }); } async function handleAddIdea(e) { e.preventDefault(); const ideaText = elements.ideaInput.value.trim(); if (!ideaText || !currentSessionId) return; try { const ideasCol = collection(db, 'artifacts', appId, 'public', 'data', 'brainstorm-sessions', currentSessionId, 'ideas'); await addDoc(ideasCol, { text: ideaText, authorId: userId, createdAt: serverTimestamp(), }); elements.ideaInput.value = ''; } catch (error) { console.error("Error adding idea:", error); showMessage("Failed to add idea.", "error"); } } function copySessionId() { navigator.clipboard.writeText(currentSessionId).then(() => { showMessage("Session ID copied to clipboard!", "success"); }).catch(err => { showMessage("Failed to copy ID.", "error"); }); } function downloadPdf() { if (allIdeas.length === 0) { showMessage("There are no ideas to export.", "error"); return; } const { jsPDF } = window.jspdf; const doc = new jsPDF(); doc.setFont('helvetica', 'bold'); doc.setFontSize(18); doc.text(`Brainstorming Session: ${currentSessionId}`, doc.internal.pageSize.getWidth() / 2, 20, { align: 'center' }); const tableBody = allIdeas.map((idea, index) => [index + 1, idea.text]); doc.autoTable({ startY: 30, head: [['#', 'Idea']], body: tableBody, theme: 'grid', headStyles: { fillColor: [79, 70, 229] } }); doc.save(`brainstorm-session-${currentSessionId}.pdf`); } // --- Firebase Initialization and Auth --- async function initializeFirebase() { try { const app = initializeApp(firebaseConfig); db = getFirestore(app); auth = getAuth(app); onAuthStateChanged(auth, (user) => { if (user) { userId = user.uid; } else { userId = null; } }); if (typeof __initial_auth_token !== 'undefined' && __initial_auth_token) { await signInWithCustomToken(auth, __initial_auth_token); } else { await signInAnonymously(auth); } } catch (error) { console.error("Firebase initialization failed:", error); showMessage("Could not connect to the service.", "error"); } } // --- Event Listeners --- elements.btnCreateSession.addEventListener('click', () => { const newSessionId = generateSessionId(); joinSession(newSessionId); }); elements.btnJoinSession.addEventListener('click', () => { const sessionIdToJoin = elements.joinSessionIdInput.value.trim().toUpperCase(); if (sessionIdToJoin) { joinSession(sessionIdToJoin); } else { showMessage("Please enter a Session ID.", "error"); } }); elements.ideaForm.addEventListener('submit', handleAddIdea); elements.btnCopyId.addEventListener('click', copySessionId); elements.btnDownloadPdf.addEventListener('click', downloadPdf); // --- Start the app --- initializeFirebase();