From c794287cedd5a3831b59c1cfe6f4df9eb6a55386 Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Mon, 6 Feb 2023 16:00:59 -0500 Subject: [PATCH] load convos on message send & other conditional rendering --- models/Conversation.js | 6 ++---- src/App.jsx | 8 +++++++- src/components/Conversation.jsx | 8 ++++---- src/components/Conversations.jsx | 18 +++++++++++++----- src/components/Nav.jsx | 4 ++-- src/components/TextChat.jsx | 11 +++++++++-- src/style.css | 4 ++-- 7 files changed, 39 insertions(+), 20 deletions(-) diff --git a/models/Conversation.js b/models/Conversation.js index 6f95fbc1b1..e237b5ffcf 100644 --- a/models/Conversation.js +++ b/models/Conversation.js @@ -27,7 +27,7 @@ const Conversation = module.exports = { saveConversation: async ({ conversationId, parentMessageId, title }) => { - const messages = await Message.find({ conversationId }); + const messages = await Message.find({ conversationId }).exec(); const update = { parentMessageId, messages }; if (title) { update.title = title; @@ -39,7 +39,5 @@ module.exports = { { new: true, upsert: true } ).exec(); }, - getConversations: async () => { - return await Conversation.find({}).exec(); - }, + getConversations: async () => await Conversation.find({}).exec(), }; diff --git a/src/App.jsx b/src/App.jsx index 541f9ffb10..929036d44a 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -3,14 +3,19 @@ import Messages from './components/Messages'; import TextChat from './components/TextChat'; import Nav from './components/Nav'; import MobileNav from './components/MobileNav'; +import useSWR from 'swr'; + +const fetcher = (url) => fetch(url).then((res) => res.json()); const App = () => { const [messages, setMessages] = useState([]); + const { data, error, isLoading, mutate } = useSWR('http://localhost:3050/convos', fetcher); + console.log(data, isLoading); return (
{/*
*/} -