diff --git a/src/components/Gemini.js b/src/components/Gemini.js index 625be92..a9fee55 100644 --- a/src/components/Gemini.js +++ b/src/components/Gemini.js @@ -1,5 +1,5 @@ import React, { useState, useEffect, useRef } from 'react'; -import { query, collection, onSnapshot, addDoc, where, getDocs, orderBy } from 'firebase/firestore'; +import { query, collection, onSnapshot, addDoc, where, getDocs, orderBy, getCountFromServer } from 'firebase/firestore'; import Markdown from 'react-markdown'; import MathJax from 'react-mathjax'; import RemarkMathPlugin from 'remark-math'; @@ -20,6 +20,7 @@ function Gemini(props) { const [isTyping, setIsTyping] = useState(false); const [discussionId, setDiscussionId] = useState(uuidv4()); const [isLoading, setIsLoading] = useState(false); + const [chatCount, setChatCount] = useState(0); const scrollRef = useRef(null); @@ -53,6 +54,17 @@ function Gemini(props) { ) }; + const getDocumentCount = async (uid) => { + const collectionPath = `users/uid/discussions`; + try { + const querySnapshot = await getCountFromServer(collection(db, collectionPath)); + // const documentCount = querySnapshot.size; + // setChatCount(querySnapshot); + console.log(`Document count in the collection "${collectionPath}": ${JSON.stringify(querySnapshot._data.count.integerValue)}`); + } catch (error) { + console.error("Error getting document count:", error); + } + }; useEffect(() => { const loadChatHistory = async () => { @@ -60,6 +72,8 @@ function Gemini(props) { // const discussionId = uuidv4(); console.log(discussionId) + getDocumentCount(uid); + const collectionPath = `users/${uid}/discussions/${discussionId}/messages`; const q = query(collection(db, collectionPath), orderBy('createTime')); @@ -171,6 +185,7 @@ function Gemini(props) { return (