Reputation: 729
I have comment section where people can talk and currently when I post comment, I have to refresh a page to see my new comment.
I’m really new to meteor so I’d like to know what steps should I take to invest this behavior.
client-side
const CommentList = ({ cardId }) => {
const query = useMemo(
() => ({
$or: [
{ commentType: COMMENT_TYPE.smsComment },
{
$and: [
{ commentType: COMMENT_TYPE.cardComment },
{ createdAt: { $gte: System.getChatCommentsDate() } }
]
}
]
}),
[]
);
const isCommentsLoading = useSubscribe("card.comments", cardId);
const comments = useFind(
() =>
CardComments.find(
{
cardId,
...query
},
{ sort: { createdAt: 1 } }
),
[cardId, isCommentsLoading()]
);
const memoizedComments = useMemo(
() =>
comments?.map(({ _id, userId }) => <Comment key={_id} commentId={_id} />),
[comments, reporterId]
);
return <>{isCommentsLoading() ? <LoadingIcon /> : memoizedComments}</>;
};
serverside/publication
Meteor.publish(
'card.comments',
(
cardId,
query = {
commentType: {$in: [COMMENT_TYPE.cardComment, COMMENT_TYPE.smsComment]},
},
) => {
check(cardId, String);
check(query, Object);
return CardComments.find(
{
cardId,
...query,
},
{
sort: {createdAt: -1},
},
);
},
);
So far, I read an article about useSubscribe and useFind https://blog.meteor.com/how-to-use-meteor-with-react-hooks-7e1791daabab
I made sure after I hit a submit comment button, comment is store in a database.
Also I looked at the meteor extension on chrome and Subscriptions tab. I see card.comments is subscribed.
in Minimongo tab, I only see three card_comments documents existing. but I have 8 comments displayed on the screen.
After I submitted the comment, I see nothing happens in DDP tab.
What do you expect happening here? or what else can I do?
Upvotes: 1
Views: 15