import {
collection,
addDoc,
serverTimestamp,
query,
orderBy,
onSnapshot,
getDocs,
} from "firebase/firestore";
import { db } from "./firebase";
export const getMessages = () => {
const messagesRef = collection(
db,
"envs/PROD/hotels/Hotel_001/chats/Chat_001/messages" '// this is working
);
const q = query(messagesRef);
return onSnapshot(q, (snapshot: any) => {
const messages = snapshot.docs.map((doc: any) => ({
id: doc.id,
...doc.data(),
}));
console.log(messages); // [{text: 'hi'}, {text: 'great'}...]
});
};
export const getChats = () => {
const messagesRef = collection(
db,
"envs/PROD/hotels/Hotel_001/chats" '// this is not working
);
const q = query(messagesRef);
return onSnapshot(q, (snapshot: any) => {
const messages = snapshot.docs.map((doc: any) => ({
id: doc.id,
...doc.data(),
}));
console.log(messages); // []
});
};