Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Reply To Comments #3

Open
gupta-ji6 opened this issue Feb 19, 2021 · 9 comments
Open

Feature Request: Reply To Comments #3

gupta-ji6 opened this issue Feb 19, 2021 · 9 comments
Labels
enhancement New feature or request

Comments

@gupta-ji6
Copy link

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
Copy link
Owner

beerose commented Apr 27, 2021

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:

  • Add new column to the comments table: parentComment or parentId.
  • Create a foreign key relation: comments.parentId -> comments.id. A comment could have multiple comments that point to it.
  • That said, a comment which is a reply to another one, would point to the "parent" comment.

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!

@beerose beerose added the enhancement New feature or request label Sep 9, 2021
@SaadBazaz
Copy link

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

@beerose
Copy link
Owner

beerose commented Dec 10, 2021

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
Copy link

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
Copy link
Owner

beerose commented Dec 10, 2021

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
Copy link

Sounds good. Any way I can help out?

@gupta-ji6
Copy link
Author

@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
Copy link
Owner

beerose commented Dec 11, 2021

@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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants