MishkaDocumentWeb.Live.Admin.Dashboard.Issue.IssueCommentsLive (Mishka Document v0.0.1)

Copy Markdown View Source

The comments thread of a single issue, rendered inside the expanded issue card.

It is a Phoenix.LiveComponent mounted by MishkaDocumentWeb.Templates.IssueCard once an issue row is expanded, and it owns everything below the action bar: the comment list, the "Load more comments" pager and the "Add Comment" button, which is hidden for issues whose status is :closed or :resolved.

Comments are read 20 at a time, newest first, through the :read action for tenant users and :master_read for master users, and are held in a LiveView stream so that paging only appends DOM nodes and keeps the scroll position intact. Sending the component a :pubsub_event assign of {:created, comment}, {:updated, comment} or {:deleted, comment} patches the stream in place without a refetch.

Usage

<.live_component
  module={MishkaDocumentWeb.Live.Admin.Dashboard.Issue.IssueCommentsLive}
  id={"issue-comments-" <> to_string(@record.id)}
  issue_id={@record.id}
  issue_status={@record.status}
  current_user={current_user}
  master_user?={master_user}
/>

Attributes

  • :issue_id - the issue whose comments are listed; changing it reloads the stream.
  • :issue_status - the issue status, used to gate the "Add Comment" button.
  • :current_user - the actor the comments are read as; a nil site_id means master.
  • :master_user? - when true, the author shown is the master contributor and every comment offers Edit and Delete. Otherwise a comment a master wrote offers neither, because MishkaDocument.IssueComment refuses a tenant both.

The "edit_comment", "delete_comment" and "add_comment" events bubble up to the parent LiveView, while "load_more_comments" is handled here. A comment pushed in through :pubsub_event must carry the same loads the list reads it with, :authored_by_master? included for a tenant.

See MishkaDocumentWeb.Templates.IssueCard for the card this component is embedded in.