beerose / use-comments

React hook to effortlessly add a comment section to your website, and start the discussion on your content.
https://use-comments.netlify.app/
MIT License
171 stars 6 forks source link

Feature Request: Reply To Comments #3

Open gupta-ji6 opened 3 years ago

gupta-ji6 commented 3 years ago

First of all, thank you so much for building and open sourcing use-comments. I love how simple it is to setup!

I would love a way to add replies to a particular comment. If someone asks a question, then we can publicly answer them or say thanks maybe.

Happy to make a PR myself if you can guide me a bit & help me get started.

beerose commented 3 years ago

Hi @gupta-ji6,

I'm sorry for the late reply. I'm currently working on a hosted version of this project in which I plan to implement reply to comments functionality. The project itself should be released in 2-3 weeks, and the reply functionality in another 2-3 weeks.

As for this project, I definitely won't have time to work on it right now, so the contributions are most welcome! I've been thinking about this functionality while building it for the first time, and here what I've wanted to do:

Example: Take this GitHub issue as an example. If your comment is the "main comment", and my response is a "reply to a comment", then the information would be stored somewhat this way:

id: 1
author: @gupta-ji6
content: ...
...
parentId: null

---

id: 2
author: @beerose 
content: ...
...
parentId: 1

Hope it makes some sense 😅

Let me know if you have more questions!

SaadBazaz commented 2 years ago

Hey @beerose . Awesome work here. Were you able to implement reply? Is it available now?

beerose commented 2 years ago

Not yet, but I got some more messages about it, and plan to work on it this weekend. Would you be more interested in "one-level" replies or "multi-level" replies? I wrote a blog post about it here: https://www.aleksandra.codes/comments-db-model, not I just need to apply it 😅

SaadBazaz commented 2 years ago

I saw your blog earlier. Some good stuff but it might take me some time to absorb in my schedule.

I think it'd be easier to start with one-level. E.g. blog posts where readers drop comments and the author replies, or product pages where potential customers ask questions, and the admin can reply only (suits my use case too, lol).

Maybe there can be a prop or a CLI which asks the Dev which one they prefer?

beerose commented 2 years ago

Hmm, let's do one-level first (didn't have anyone asking for multi-level yet 😅, and it'll take less time..), and later we can think about multi-level!

SaadBazaz commented 2 years ago

Sounds good. Any way I can help out?

gupta-ji6 commented 2 years ago

@beerose single level replies are good enough for the start and supports most of the cases 💯

Let me also know if I can contribute in any way 🙌🏻

beerose commented 2 years ago

@SaadBazaz @gupta-ji6 thank you!

I guess there are a few things to do:

  1. Decide on the API (more below) and DB structure.
  2. Update the hook implementation.
  3. Update the metadata in this repo (should reflect new db structure).
  4. Update the docs.

As for 1., there are multiple options and questions:

  1. How should we send a reply? Should it be a part of addComment function, with, for example, additional replyTo field, or should it be an additional method: addReply?
  2. How should users fetch the replies? Should they be fetched automatically for the comment? Or should we allow pagination? Or maybe there should be an includeReplies option and fetchReplies(parentCommentId)?

Could you describe what would be the best API for you?

As for the DB, I suggest adding a new column called parent_id or reply_to, and then when fetching "base" comment we would exclude the ones with parent_id being filled.

gupta-ji6 commented 2 years ago

How should we send a reply? Should it be a part of addComment function, with, for example, additional replyTo field, or should it be an additional method: addReply?

Technically, a reply is a comment only so adding it to the addComment function would be right. But, as an API, it might complicate addComment function. Adding an additional method addReply would be a better API in my opinion as it's easier to understand, will split the functionality, and is easy to maintain. What do you think? 🤔

How should users fetch the replies? Should they be fetched automatically for the comment? Or should we allow pagination? Or maybe there should be an includeReplies option and fetchReplies(parentCommentId)?

For a starter, I think we can automatically fetch replies to the comment (or give a boolean param for it). But to give more power to the developer and keep stage open for customization, there should be a includeReplies option and an additional fetchReplies(parentCommentId). If making these is not complex, we can start with fetching replies with comments at once and then provide customization options in later versions. ⚒️

As for the DB, I suggest adding a new column called parent_id or reply_to, and then when fetching "base" comment we would exclude the ones with parent_id being filled.

parent_id sounds good to me 👌🏻

@beerose