hummingbird-me/kitsu-web

View on GitHub
app/templates/components/stream-feed/items/post/comments.hbs

Summary

Maintainability
Test Coverage
{{#if post.topLevelCommentsCount}}
  {{#if getComments.isRunning}}
    <div class="p-t-1 p-b-1 text-xs-center">
      {{loading-spinner size="small"}}
    </div>
  {{else}}
    <div class="comments-header">
      {{! Viewing single comment }}
      {{#if comment}}
        <div class="comment-actions clearfix">
          <div class="pull-sm-left">
            <a href={{href-to "posts" post.id}}>{{t "components.stream-feed.post.comments.all"}}</a>
            {{#if (and isReply comment.parent)}}
              &mdash;
              <a href={{href-to "comments" comment.parent.id}}>{{t "components.stream-feed.post.comments.parent"}}</a>
            {{/if}}
          </div>
        </div>
      {{else if comments}}
        {{! Sort dropdown }}
        {{#if isPermalinkPage}}
          <div class="comment-sort-dropdown">
            {{#bootstrap/bs-dropdown as |dropdown|}}
              {{#dropdown.button}}
                {{t (concat "feeds.post.sorts." sort)}}
              {{/dropdown.button}}
              {{#dropdown.menu}}
                {{#each sortOptions as |option|}}
                  {{#dropdown.menu-item onClick=(action "updateSort" option)}}
                    {{t (concat "feeds.post.sorts." option)}}
                    {{#if (eq option sort)}}
                      <span class="dropdown-checkmark">{{svg-jar "checkmark"}}</span>
                    {{/if}}
                  {{/dropdown.menu-item}}
                {{/each}}
              {{/dropdown.menu}}
            {{/bootstrap/bs-dropdown}}
          </div>
        {{/if}}

        {{! Comment Pagination }}
        {{#if hasNextPage}}
          <div class="comment-actions clearfix">
            {{! action }}
            {{#unless isModalView}}
              <div class="pull-sm-left">
                {{#if isLoading}}
                  {{loading-spinner size="small"}}
                {{else}}
                  <a href="#" {{action "onPagination"}}>{{t "components.stream-feed.post.comments.previous-comments"}}</a>
                {{/if}}
              </div>
            {{/unless}}
            {{! Comment count }}
            <div class="pull-sm-right">
              {{t "components.stream-feed.post.comment-count" count=comments.length total=post.topLevelCommentsCount}}
            </div>
          </div>
        {{/if}}
      {{/if}}
    </div>

    {{! List of comments }}
    <ul class="media-list">
      {{! barf }}
      {{#if isModalView}}
        {{#infinite-pagination loaderSize="small" onPagination=(action "onPagination")}}
          {{#each comments as |comment|}}
            {{stream-feed/items/post/comment
              isTopLevel=true
              isReply=isReply
              comment=comment
              post=post
              readOnly=readOnly
              kitsuGroupMembership=kitsuGroupMembership
              isModalView=isModalView
              onDelete=(action "deletedComment")
              likesCountUpdate=(action (mut comment.likesCount))
              replyCountUpdate=(action (mut comment.repliesCount))
              trackEngagement=(action "trackEngagement")
              updateFollow=updateFollow
              tagName="li"
              class="media new-comment"}} {{! HACK: Until we have transitions }}
            {{/each}}
        {{/infinite-pagination}}
      {{else}}
        {{#each comments as |comment|}}
          {{stream-feed/items/post/comment
            isTopLevel=true
            isReply=isReply
            comment=comment
            post=post
            readOnly=readOnly
            kitsuGroupMembership=kitsuGroupMembership
            isModalView=isModalView
            onDelete=(action "deletedComment")
            likesCountUpdate=(action (mut comment.likesCount))
            replyCountUpdate=(action (mut comment.repliesCount))
            trackEngagement=(action "trackEngagement")
            updateFollow=updateFollow
            tagName="li"
            class="media new-comment"}} {{! HACK: Until we have transitions }}
        {{/each}}
      {{/if}}
    </ul>
  {{/if}}
{{/if}}

{{! Comment Box }}
{{#unless getComments.isRunning}}
  {{#if (and (not comment) (not readOnly))}}
    <div class="add-comment-wrapper">
      {{stream-feed/items/post/comment-box
        onSubmit=createComment
        placeholder=(t "components.stream-feed.post.comments.leave-comment")
        className="form-control add-comment"
        upload=upload
      }}
    </div>
  {{/if}}
{{/unless}}