Skip to content

Commit

Permalink
fixed images not rendering issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjaminklein99 committed Jul 22, 2023
1 parent 7c6eea9 commit 4f3dab7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
15 changes: 10 additions & 5 deletions client/components/MessageComponents/ContinueConversation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { React, useState } from 'react';
import axios from 'axios';
import Conversation from './Conversation.jsx';

const StartConversation = (props) => {
const { convo, loggedIn, otherUser, updateView } = props;
const ContinueConversation = (props) => {
const { convoId, loggedIn, otherUser, updateView } = props;

const [ topText, updateTopText ] = useState('');

Expand All @@ -15,11 +15,16 @@ const StartConversation = (props) => {
axios.post('/messagesHandling/message', {
senderId: loggedIn.id,
recipientId: otherUser.id,
conversationId: convo.id,
conversationId: convoId,
img: `https://apimeme.com/meme?meme=${meme}&top=${topText}&bottom=${bottomText}`.replaceAll(' ', '+')
})
.then((res) => {
updateView(<Conversation convo={convo} loggedIn={loggedIn} otherUser={otherUser} updateView={updateView}/>);
updateView(<Conversation
convoId={convoId}
loggedIn={loggedIn}
otherUser={otherUser}
updateView={updateView}
/>);
})
.catch((err) => {
console.log(err);
Expand Down Expand Up @@ -63,4 +68,4 @@ const StartConversation = (props) => {
);
};

export default StartConversation;
export default ContinueConversation;
11 changes: 4 additions & 7 deletions client/components/MessageComponents/Conversation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@ import MessageItem from './ConvoMessageItem.jsx';
import ContinueConversation from './ContinueConversation.jsx';

const Conversation = (props) => {
const { convo, loggedIn, otherUser, updateView } = props;

const { convoId, loggedIn, otherUser, updateView } = props;
const [ conversations, setConversations ] = useState([]);



useEffect(() => {
const fetchAllConvoMessages = async () => {
const request = await axios.get(`/messagesHandling/messages${convo.id}`);
const request = await axios.get(`/messagesHandling/messages${convoId}`);
setConversations(request.data);
return request;
};
fetchAllConvoMessages();
}, [convo]);
}, [convoId]);

return (
<div>
Expand All @@ -26,7 +23,7 @@ const Conversation = (props) => {
className='btn btn-primary'
onClick={ () => {
updateView(<ContinueConversation
convo={convo}
convoId={convoId}
loggedIn={loggedIn}
otherUser={otherUser}
updateView={updateView}/>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const ConversationListItem = (props) => {
}, [loggedIn]);

return (
<div onClick={ () => { updateView(<Conversation loggedIn={loggedIn} convo={convo} otherUser={otherUser} updateView={updateView}/>); }}>
<div onClick={ () => { updateView(<Conversation loggedIn={loggedIn} convoId={convo.id} otherUser={otherUser} updateView={updateView}/>); }}>
<p className="scream modal-content text-white pt-3">
<span className="scream modal-content text-sm-left">
between you and { `${otherUser.username}` }
Expand Down
10 changes: 7 additions & 3 deletions client/components/MessageComponents/StartConversation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ const StartConversation = (props) => {
recipientId: recipient.id,
img: `https://apimeme.com/meme?meme=${meme}&top=${topText}&bottom=${bottomText}`.replaceAll(' ', '+')
})
.then((res) => {
console.log(res.data);
updateView(<Conversation convo={res.data} loggedIn={props.loggedIn} />);
.then((message) => {
updateView(<Conversation
convoId={message.data.conversationId}
loggedIn={loggedIn}
otherUser={recipient}
updateView={updateView}
/>);
})
.catch((err) => {
console.log(err);
Expand Down
1 change: 0 additions & 1 deletion server/routes/messagesHandling.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ messageRouter.get('/messages:convoId', (req, res) => {
const {convoId} = req.params;
Messages.findAll({ where: { conversationId: convoId } })
.then((data) => {
console.log(data);
res.send(data.reverse());
})
.catch((err) => {
Expand Down

0 comments on commit 4f3dab7

Please sign in to comment.