diff --git a/src/App.jsx b/src/App.jsx index 7531a34b08..276ff608ea 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,64 +1,28 @@ -import React, { useState, useEffect } from 'react'; -import { useSelector, useDispatch } from 'react-redux'; +import React from 'react'; +import { useSelector } from 'react-redux'; import Messages from './components/Messages'; import TextChat from './components/TextChat'; import Nav from './components/Nav'; import MobileNav from './components/MobileNav'; import useSWR from 'swr'; -import useSWRMutation from 'swr/mutation'; -import useDidMountEffect from './hooks/useDidMountEffect.js'; -import axios from 'axios'; const fetcher = (url) => fetch(url).then((res) => res.json()); -const postRequest = async (url, { arg }) => await axios.post(url, { arg }); +// const postRequest = async (url, { arg }) => await axios.post(url, { arg }); const App = () => { - // const [messages, setMessages] = useState([]); const messages = useSelector((state) => state.messages); - // const [convo, setConvo] = useState({ conversationId: null, parentMessageId: null }); const { data, error, isLoading, mutate } = useSWR('http://localhost:3050/convos', fetcher); - const convo = useSelector((state) => state.convo); - const conversationId = useSelector((state) => state.convo.conversationId); - console.log('conversationId', conversationId); - - // const conversation = useSWRMutation( - // //{ trigger, isMutating } - // `http://localhost:3050/messages/${conversationId}`, - // fetcher, - // { - // onSuccess: function (res) { - // console.log('success', res); - // setMessages(res); - // } - // } - // ); - - // useDidMountEffect(() => conversation.trigger(), [conversationId]); - - // const onConvoClick = (conversationId, parentMessageId) => { - // console.log('convo was clicked'); - // setConvo({ conversationId, parentMessageId }); - // }; - return (
{/*
*/} -
- - + {id === conversationId && } + {id === conversationId && }
); diff --git a/src/components/Nav.jsx b/src/components/Nav.jsx index 4099a9ec74..c070c7f9f1 100644 --- a/src/components/Nav.jsx +++ b/src/components/Nav.jsx @@ -3,14 +3,14 @@ import NewChat from './NewChat'; import Conversations from './Conversations'; import NavLinks from './NavLinks'; -export default function Nav({ conversations, convo, convoHandler }) { +export default function Nav({ conversations }) { return (
diff --git a/src/components/TextChat.jsx b/src/components/TextChat.jsx index 3a9127bef0..70a17927ef 100644 --- a/src/components/TextChat.jsx +++ b/src/components/TextChat.jsx @@ -6,9 +6,10 @@ import { useSelector, useDispatch } from 'react-redux'; import { setConversation } from '../../store/convoSlice'; import { setMessages } from '../../store/messageSlice'; -export default function TextChat({ messages, reloadConvos, convo }) { +export default function TextChat({ messages, reloadConvos }) { const [text, setText] = useState(''); const dispatch = useDispatch(); + const convo = useSelector((state) => state.convo); const submitMessage = () => { const payload = text.trim(); @@ -21,7 +22,6 @@ export default function TextChat({ messages, reloadConvos, convo }) { const convoHandler = (data) => { if (convo.conversationId === null && convo.parentMessageId === null) { const { conversationId, parentMessageId } = data; - // setConvo({ conversationId, parentMessageId: data.id }); dispatch(setConversation({ conversationId, parentMessageId: data.id })); } diff --git a/store/convoSlice.js b/store/convoSlice.js index 74cd6f6911..f4e9f337aa 100644 --- a/store/convoSlice.js +++ b/store/convoSlice.js @@ -11,7 +11,6 @@ const currentSlice = createSlice({ initialState, reducers: { setConversation: (state, action) => { - console.log('in setConversation reducer'); const { conversationId, parentMessageId } = action.payload; state.conversationId = conversationId; state.parentMessageId = parentMessageId; diff --git a/store/messageSlice.js b/store/messageSlice.js index 82601d311d..a7af90384d 100644 --- a/store/messageSlice.js +++ b/store/messageSlice.js @@ -7,13 +7,11 @@ const currentSlice = createSlice({ initialState, reducers: { setMessages: (state, action) => { - console.log('in setMessages reducer'); const { payload } = action; - state = payload; + return [...payload]; }, } }); -// export const { setMessages } = currentSlice.actions;