Skip to content

A platform for community discussion. Free, open, simple.

UX: post voting styling, accessibility, and small fixes (#39443)

chapoi8e44060201a2
diff --git a/plugins/discourse-post-voting/app/views/connectors/after_post_body/comments.html.erb b/plugins/discourse-post-voting/app/views/connectors/after_post_body/comments.html.erb
index c9ce925bc8b..3585595559c 100644
--- a/plugins/discourse-post-voting/app/views/connectors/after_post_body/comments.html.erb
+++ b/plugins/discourse-post-voting/app/views/connectors/after_post_body/comments.html.erb
@@ -1,12 +1,12 @@
<% if @topic_view.topic.is_post_voting? %>
<div class="post-voting-comments">
<% @topic_view.comments[post.id]&.each_with_index do |comment, i| %>
- <div class="post-voting-comment-row">
- <span class="post-voting-comment-cooked" itemprop="comment"><%= comment.cooked.html_safe %></span>
- <span class="post-voting-comment-info-separator">–</span>
- <span class="post-voting-comment-creator" itemprop="author" itemscope itemtype="http://schema.org/Person">
+ <div class="post-voting-comments__comment">
+ <span class="post-voting-comments__comment-cooked" itemprop="comment"><%= comment.cooked.html_safe %></span>
+ <span class="post-voting-comments__separator">–</span>
+ <span class="post-voting-comments__comment-creator" itemprop="author" itemscope itemtype="http://schema.org/Person">
<a itemprop="url" href='<%= Discourse.base_url %>/u/<%= comment.user.username %>'><span itemprop="name"><%= comment.user.username %></span></a>
- <time itemprop='datePublished' datetime='<%= comment.created_at.to_formatted_s(:iso8601) %>' class="post-voting-comment-time">
+ <time itemprop='datePublished' datetime='<%= comment.created_at.to_formatted_s(:iso8601) %>' class="post-voting-comments__comment-time">
(<%= l comment.created_at, format: :long %>)
</time>
</span>
@@ -20,7 +20,7 @@
%>
<div class="post-voting-answer-count">
<h3><%= t('topic.post-voting.answer_count', count: reply_count) %></h3>
- <span class="post-voting-answer-count-span" itemprop="answerCount"><%= reply_count %></span>
+ <span class="post-voting-answer-count__value" itemprop="answerCount"><%= reply_count %></span>
</div>
<% end %>
<% end %>
diff --git a/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-answer-header.gjs b/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-answer-header.gjs
index 8494d9f6695..d4e2965b82d 100644
--- a/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-answer-header.gjs
+++ b/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-answer-header.gjs
@@ -1,8 +1,7 @@
import Component from "@glimmer/component";
+import { on } from "@ember/modifier";
import { action } from "@ember/object";
-import DButton from "discourse/components/d-button";
import concatClass from "discourse/helpers/concat-class";
-import { not } from "discourse/truth-helpers";
import { i18n } from "discourse-i18n";
export const ORDER_BY_ACTIVITY_FILTER = "activity";
@@ -42,46 +41,64 @@ export default class PostVotingAnswerHeader extends Component {
);
}
+ get votesUrl() {
+ return this.post.topic.url;
+ }
+
+ get activityUrl() {
+ return `${this.post.topic.url}?filter=${ORDER_BY_ACTIVITY_FILTER}`;
+ }
+
@action
- async orderByVotes() {
+ async orderByVotes(event) {
+ event.preventDefault();
await this.post.topic.postStream.orderStreamByVotes();
this.args.outletArgs.actions.updateTopicPageQueryParams();
}
@action
- async orderByActivity() {
+ async orderByActivity(event) {
+ event.preventDefault();
await this.post.topic.postStream.orderStreamByActivity();
this.args.outletArgs.actions.updateTopicPageQueryParams();
}
<template>
- <div class="post-voting-answers-header small-action">
- <span class="post-voting-answers-headers-count">
+ <nav
+ class="post-voting-answers-header"
+ aria-label={{i18n "post_voting.topic.sort_by"}}
+ >
+ <h5 class="post-voting-answers-header__count">
{{i18n "post_voting.topic.answer_count" count=this.answersCount}}
- </span>
- <span class="post-voting-answers-headers-sort">
- <span>
- {{i18n "post_voting.topic.activity"}}
- </span>
- <DButton
- class={{concatClass
- "post-voting-answers-headers-sort-votes"
- (unless this.sortedByActivity "active")
- }}
- @disabled={{not this.sortedByActivity}}
- @label="post_voting.topic.votes"
- @action={{this.orderByVotes}}
- />
- <DButton
- class={{concatClass
- "post-voting-answers-headers-sort-activity"
- (if this.sortedByActivity "active")
- }}
- @disabled={{this.sortedByActivity}}
- @label="post_voting.topic.activity"
- @action={{this.orderByActivity}}
- />
- </span>
- </div>
+ </h5>
+ <ul class="nav-pills post-voting-answers-header__sort">
+ <li>
+ <a
+ href={{this.votesUrl}}
+ class={{concatClass
+ "--votes"
+ (unless this.sortedByActivity "active")
+ }}
+ aria-current={{unless this.sortedByActivity "true"}}
+ {{on "click" this.orderByVotes}}
+ >
+ {{i18n "post_voting.topic.votes"}}
+ </a>
+ </li>
+ <li>
+ <a
+ href={{this.activityUrl}}
+ class={{concatClass
+ "--activity"
+ (if this.sortedByActivity "active")
+ }}
+ aria-current={{if this.sortedByActivity "true"}}
+ {{on "click" this.orderByActivity}}
+ >
+ {{i18n "post_voting.topic.activity"}}
+ </a>
+ </li>
+ </ul>
+ </nav>
</template>
}
diff --git a/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-button.gjs b/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-button.gjs
index 9936b19cb78..bf78ab223e5 100644
--- a/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-button.gjs
+++ b/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-button.gjs
@@ -6,13 +6,10 @@ import concatClass from "discourse/helpers/concat-class";
export default class PostVotingButton extends Component {
get buttonClasses() {
- let classes =
- this.args.direction === "up"
- ? "post-voting-button-upvote"
- : "post-voting-button-downvote";
+ let classes = this.args.direction === "up" ? "--upvote" : "--downvote";
if (this.args.voted) {
- classes += " post-voting-button-voted";
+ classes += " --voted";
}
return classes;
@@ -23,7 +20,19 @@ export default class PostVotingButton extends Component {
}
get iconName() {
- return this.args.direction === "up" ? "angle-up" : "angle-down";
+ return this.args.voted ? "vote-up-filled" : "vote-up";
+ }
+
+ get ariaLabel() {
+ if (this.args.direction === "up") {
+ return this.args.voted
+ ? "vote.button.remove_upvote"
+ : "vote.button.upvote";
+ }
+
+ return this.args.voted
+ ? "vote.button.remove_downvote"
+ : "vote.button.downvote";
}
@action
@@ -44,7 +53,12 @@ export default class PostVotingButton extends Component {
{{on "click" this.onClick}}
@disabled={{this.disabled}}
@icon={{this.iconName}}
- class={{concatClass "btn-flat post-voting-button" this.buttonClasses}}
+ @title={{this.ariaLabel}}
+ @ariaLabel={{this.ariaLabel}}
+ class={{concatClass
+ "btn-transparent post-voting-button"
+ this.buttonClasses
+ }}
/>
</template>
}
diff --git a/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comment-actions.gjs b/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comment-actions.gjs
index 67d5953fbe7..596692d477f 100644
--- a/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comment-actions.gjs
+++ b/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comment-actions.gjs
@@ -70,27 +70,31 @@ export default class PostVotingCommentActions extends Component {
<template>
{{#if this.canEdit}}
- <span class="post-voting-comment-actions">
+ <span class="post-voting-comments__comment-actions">
<DButton
- @display="link"
- class="post-voting-comment-actions-edit-link"
+ class="post-voting-comments__comment-actions-edit-link btn-transparent"
@action={{@updateComment}}
@icon="pencil"
- />
- <DButton
- @display="link"
- class="post-voting-comment-actions-delete-link"
- @action={{this.deleteConfirm}}
- @icon="far-trash-can"
+ @title="post_voting.post.post_voting_comment.actions.edit"
+ @ariaLabel="post_voting.post.post_voting_comment.actions.edit"
/>
{{#if this.canFlag}}
<DButton
- @display="link"
- class="post-voting-comment-actions-flag-link"
+ class="post-voting-comments__comment-actions-flag-link btn-transparent"
@action={{this.showFlag}}
@icon="flag"
+ @title="post_voting.post.post_voting_comment.actions.flag"
+ @ariaLabel="post_voting.post.post_voting_comment.actions.flag"
/>
{{/if}}
+ <DButton
+ class="post-voting-comments__comment-actions-delete-link btn-transparent"
+ @action={{this.deleteConfirm}}
+ @icon="far-trash-can"
+ @title="post_voting.post.post_voting_comment.actions.delete"
+ @ariaLabel="post_voting.post.post_voting_comment.actions.delete"
+ />
+
</span>
{{/if}}
</template>
diff --git a/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comment-composer.gjs b/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comment-composer.gjs
index 7f163e21b16..008791cba36 100644
--- a/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comment-composer.gjs
+++ b/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comment-composer.gjs
@@ -39,25 +39,24 @@ export default class PostVotingCommentComposer extends Component {
}
<template>
- <div class="post-voting-comment-composer">
+ <div class="post-voting-comments__composer">
<textarea
- class="post-voting-comment-composer-textarea"
+ class="post-voting-comments__composer-textarea"
value={{this.value}}
{{on "input" this.onInput}}
{{on "keydown" @onKeyDown}}
+ maxlength={{this.siteSettings.post_voting_comment_max_raw_length}}
></textarea>
{{#if this.value.length}}
{{#if this.errorMessage}}
- <div class="post-voting-comment-composer-flash error">
+ <div class="post-voting-comments__composer-flash has-error">
{{this.errorMessage}}
</div>
{{else}}
- <div class="post-voting-comment-composer-flash">
- {{i18n
- "post_voting.post.post_voting_comment.composer.length_ok"
- count=this.remainingCharacters
- }}
+ <div class="post-voting-comments__composer-flash">
+ {{this.value.length}}/<span
+ >{{this.siteSettings.post_voting_comment_max_raw_length}}</span>
</div>
{{/if}}
{{/if}}
diff --git a/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comment-editor.gjs b/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comment-editor.gjs
index 90f7bb48f39..9f280a9d934 100644
--- a/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comment-editor.gjs
+++ b/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comment-editor.gjs
@@ -50,7 +50,9 @@ export default class PostVotingCommentEditor extends Component {
}
<template>
- <div class="post-voting-comment-editor post-voting-comment-editor-{{@id}}">
+ <div
+ class="post-voting-comments__comment-editor post-voting-comments__comment-editor-{{@id}}"
+ >
<PostVotingCommentComposer
@onInput={{this.updateValue}}
@raw={{@raw}}
@@ -62,14 +64,14 @@ export default class PostVotingCommentEditor extends Component {
@disabled={{this.submitDisabled}}
@label="post_voting.post.post_voting_comment.edit"
@icon="pencil"
- class="btn-primary post-voting-comment-editor-submit"
+ class="btn-primary post-voting-comments__comment-editor-submit"
/>
<DButton
@display="link"
@action={{@onCancel}}
@label="post_voting.post.post_voting_comment.cancel"
- class="post-voting-comment-editor-cancel"
+ class="post-voting-comments__comment-editor-cancel"
/>
</div>
</template>
diff --git a/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comment.gjs b/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comment.gjs
index ae9d4b88892..9a24a6e6402 100644
--- a/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comment.gjs
+++ b/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comment.gjs
@@ -94,8 +94,7 @@ export default class PostVotingComment extends Component {
<template>
<div
id={{this.anchorId}}
- class="post-voting-comment
- {{if @comment.deleted 'post-voting-comment-deleted'}}"
+ class="post-voting-comments__comment {{if @comment.deleted '--deleted'}}"
>
{{#if this.isEditing}}
<PostVotingCommentEditor
@@ -105,11 +104,13 @@ export default class PostVotingComment extends Component {
@onCancel={{this.onCancel}}
/>
{{else}}
- <div class="post-voting-comment-actions-vote">
+ <div class="post-voting-comments__vote">
{{#if @comment.post_voting_vote_count}}
<span
- class="post-voting-comment-actions-vote-count"
+ class="post-voting-comments__vote-count"
>{{@comment.post_voting_vote_count}}</span>
+ {{else}}
+ <span class="post-voting-comments__vote-count --none">0</span>
{{/if}}
<PostVotingButton
@@ -122,30 +123,28 @@ export default class PostVotingComment extends Component {
/>
</div>
- <div class="post-voting-comment-post">
- <span class="post-voting-comment-cooked">{{trustHTML
+ <div class="post-voting-comments__comment-post">
+ <span class="post-voting-comments__comment-cooked">{{trustHTML
@comment.cooked
}}</span>
- <span class="post-voting-comment-info-separator">–</span>
+ <span class="post-voting-comments__separator">–</span>
{{#if @comment.username}}
<a
href={{userPath @comment.username}}
- class="post-voting-comment-info-username"
+ class="post-voting-comments__username"
data-user-card={{@comment.username}}
>
{{formatUsername @comment.username}}
</a>
{{else}}
- <span
- class="post-voting-comment-info-username post-voting-comment-info-username-deleted"
- >
+ <span class="post-voting-comments__username --deleted">
{{i18n "post_voting.post.post_voting_comment.user.deleted"}}
</span>
{{/if}}
- <span class="post-voting-comment-info-created">
+ <span class="post-voting-comments__created">
{{formatDate @comment.created_at}}
</span>
diff --git a/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comments-menu-composer.gjs b/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comments-menu-composer.gjs
index fee2ca5e342..deff714d0de 100644
--- a/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comments-menu-composer.gjs
+++ b/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comments-menu-composer.gjs
@@ -47,26 +47,23 @@ export default class PostVotingCommentsMenuComposer extends Component {
}
<template>
- <div class="post-voting-comments-menu-composer">
- <PostVotingCommentComposer
- @onInput={{this.updateValue}}
- @onKeyDown={{this.onKeyDown}}
- />
+ <PostVotingCommentComposer
+ @onInput={{this.updateValue}}
+ @onKeyDown={{this.onKeyDown}}
+ />
- <DButton
- @action={{this.saveComment}}
- @disabled={{this.submitDisabled}}
- @icon="reply"
- @label="post_voting.post.post_voting_comment.submit"
- class="btn-primary post-voting-comments-menu-composer-submit"
- />
+ <DButton
+ @action={{this.saveComment}}
+ @disabled={{this.submitDisabled}}
+ @icon="reply"
+ @label="post_voting.post.post_voting_comment.submit"
+ class="btn-primary btn-small post-voting-comments__composer-submit"
+ />
- <DButton
- @display="link"
- @action={{@onCancel}}
- @label="post_voting.post.post_voting_comment.cancel"
- class="post-voting-comments-menu-composer-cancel"
- />
- </div>
+ <DButton
+ @action={{@onCancel}}
+ @label="post_voting.post.post_voting_comment.cancel"
+ class="btn-transparent btn-small post-voting-comments__composer-cancel"
+ />
</template>
}
diff --git a/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comments-menu.gjs b/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comments-menu.gjs
index 3722fd4c1cc..7715605349f 100644
--- a/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comments-menu.gjs
+++ b/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-comments-menu.gjs
@@ -33,7 +33,7 @@ export default class PostVotingCommentsMenu extends Component {
this.fetchComments().then(() => {
schedule("afterRender", () => {
const textArea = document.querySelector(
- `#post_${this.args.postNumber} .post-voting-comment-composer .post-voting-comment-composer-textarea`
+ `#post_${this.args.postNumber} .post-voting-comments__composer .post-voting-comments__composer-textarea`
);
textArea.focus();
textArea.select();
@@ -70,7 +70,7 @@ export default class PostVotingCommentsMenu extends Component {
}
<template>
- <div class="post-voting-comments-menu">
+ <div class="post-voting-comments__footer">
{{#if this.expanded}}
<PostVotingCommentsMenuComposer
@id={{@id}}
@@ -78,33 +78,28 @@ export default class PostVotingCommentsMenu extends Component {
@onCancel={{this.closeComposer}}
/>
{{else}}
- <DButton
- @display="link"
- @action={{if
- this.currentUser
- this.expandComposer
- (routeAction "showLogin")
- }}
- @label="post_voting.post.post_voting_comment.add"
- class="post-voting-comment-add-link"
- />
- {{/if}}
-
- {{#if this.hasMoreComments}}
- {{#unless this.expanded}}
- <span class="post-voting-comments-menu-separator"></span>
- {{/unless}}
-
- <div class="post-voting-comments-menu-show-more">
+ <div class="post-voting-comments__actions">
<DButton
- @display="link"
- @action={{this.fetchComments}}
- @translatedLabel={{i18n
- "post_voting.post.post_voting_comment.show"
- count=@moreCommentCount
+ @action={{if
+ this.currentUser
+ this.expandComposer
+ (routeAction "showLogin")
}}
- class="post-voting-comments-menu-show-more-link"
+ @label="post_voting.post.post_voting_comment.add"
+ class="btn-transparent --primary btn-small post-voting-comments__actions-add"
/>
+
+ {{#if this.hasMoreComments}}
+ <DButton
+ @action={{this.fetchComments}}
+ @translatedLabel={{i18n
+ "post_voting.post.post_voting_comment.show"
+ count=@moreCommentCount
+ }}
+ class="btn-transparent --primary btn-small post-voting-comments__actions-show-more"
+ />
+
+ {{/if}}
</div>
{{/if}}
</div>
diff --git a/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-vote-controls.gjs b/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-vote-controls.gjs
index 9b2fec96714..e4e0be20167 100644
--- a/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-vote-controls.gjs
+++ b/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-vote-controls.gjs
@@ -1,10 +1,10 @@
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
-import { concat } from "@ember/helper";
import { action } from "@ember/object";
import { service } from "@ember/service";
-import DButton from "discourse/components/d-button";
+import DMenu from "discourse/float-kit/components/d-menu";
import { popupAjaxError } from "discourse/lib/ajax-error";
+import { i18n } from "discourse-i18n";
import { castVote, removeVote } from "../lib/post-voting-utilities";
import PostVotingButton from "./post-voting-button";
import PostVotingWhoVotedList from "./post-voting-who-voted-list";
@@ -13,7 +13,6 @@ export default class PostVotingVoteControls extends Component {
@service currentUser;
@tracked loading;
- @tracked showWhoVoted = false;
get count() {
return this.args.post_voting_vote_count || 0;
@@ -101,11 +100,6 @@ export default class PostVotingVoteControls extends Component {
}
}
- @action
- toggleWhoVoted() {
- this.showWhoVoted = !this.showWhoVoted;
- }
-
<template>
<div class="post-voting-post">
<PostVotingButton
@@ -118,19 +112,23 @@ export default class PostVotingVoteControls extends Component {
/>
{{#if this.hasVotes}}
- <DButton
- class="post-voting-post-toggle-voters btn-flat"
- @action={{this.toggleWhoVoted}}
- @translatedLabel={{concat @post.post_voting_vote_count}}
- />
- {{#if this.showWhoVoted}}
- <PostVotingWhoVotedList
- @post={{@post}}
- @onClickOutside={{this.toggleWhoVoted}}
- />
- {{/if}}
+ <DMenu
+ @identifier="post-voting-popup"
+ @interactive={{true}}
+ @autofocus={{true}}
+ @title={{i18n "vote.toggle_voters"}}
+ @ariaLabel={{i18n "vote.toggle_voters"}}
+ @triggerClass="post-voting-post__toggle-voters btn-transparent"
+ >
+ <:trigger>
+ {{@post.post_voting_vote_count}}
+ </:trigger>
+ <:content>
+ <PostVotingWhoVotedList @post={{@post}} />
+ </:content>
+ </DMenu>
{{else}}
- <span class="post-voting-post-toggle-voters">
+ <span class="post-voting-post__toggle-voters">
{{this.count}}
</span>
{{/if}}
diff --git a/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-who-voted-list.gjs b/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-who-voted-list.gjs
index bf5ff0fc474..dd642d726f0 100644
--- a/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-who-voted-list.gjs
+++ b/plugins/discourse-post-voting/assets/javascripts/discourse/components/post-voting-who-voted-list.gjs
@@ -1,14 +1,13 @@
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
-import { hash } from "@ember/helper";
import { action, get } from "@ember/object";
import AsyncContent from "discourse/components/async-content";
import SmallUserList, {
smallUserAttrs,
} from "discourse/components/small-user-list";
+import concatClass from "discourse/helpers/concat-class";
import icon from "discourse/helpers/d-icon";
import { bind } from "discourse/lib/decorators";
-import closeOnClickOutside from "discourse/modifiers/close-on-click-outside";
import { eq } from "discourse/truth-helpers";
import { i18n } from "discourse-i18n";
import { whoVoted } from "../lib/post-voting-utilities";
@@ -50,55 +49,55 @@ export default class PostVotingWhoVotedList extends Component {
}
<template>
- <div
- class="post-voting-post-list"
- {{closeOnClickOutside
- @onClickOutside
- (hash
- targetSelector=".post-voting-post-list"
- secondaryTargetSelector=".post-voting-post-toggle-voters"
- )
- }}
- >
- <AsyncContent @asyncData={{this.loadWhoVoted}}>
- <:loading>
- {{i18n "loading"}}
- </:loading>
- <:content as |voters|>
- {{#let (this.splitUpAndDownLists voters) as |splitVoters|}}
- <PostVotingSmallUserList
- @list={{get splitVoters "up"}}
- @direction="up"
- />
- <PostVotingSmallUserList
- @list={{get splitVoters "down"}}
- @direction="down"
- />
- {{/let}}
- {{#let (this.calcRemainingCount voters) as |remainingCount|}}
- {{#if remainingCount}}
- <span>
- {{i18n
- "post_voting.topic.voters_count_diff"
- count=remainingCount
- }}
- </span>
- {{/if}}
- {{/let}}
- </:content>
- </AsyncContent>
- </div>
+ <AsyncContent @asyncData={{this.loadWhoVoted}}>
+ <:loading>
+ {{i18n "loading"}}
+ </:loading>
+ <:content as |voters|>
+ {{#let (this.splitUpAndDownLists voters) as |splitVoters|}}
+ <PostVotingSmallUserList
+ @list={{get splitVoters "up"}}
+ @direction="up"
+ />
+ <PostVotingSmallUserList
+ @list={{get splitVoters "down"}}
+ @direction="down"
+ />
+ {{/let}}
+ {{#let (this.calcRemainingCount voters) as |remainingCount|}}
+ {{#if remainingCount}}
+ <span>
+ {{i18n
+ "post_voting.topic.voters_count_diff"
+ count=remainingCount
+ }}
+ </span>
+ {{/if}}
+ {{/let}}
+ </:content>
+ </AsyncContent>
</template>
}
const PostVotingSmallUserList = <template>
{{#if @list}}
- <div class="post-voting-post-list-voters-wrapper">
- <span class="post-voting-post-list-icon">
- {{icon (if (eq @direction "up") "angle-up" "angle-down")}}
+ <div class="post-voting-popup-content__wrapper">
+ <span
+ class={{concatClass
+ "post-voting-popup-content__icon"
+ (if (eq @direction "up") "--upvote" "--downvote")
+ }}
+ aria-label={{i18n
+ (if (eq @direction "up") "vote.upvotes" "vote.downvotes")
+ }}
+ >
+ {{icon "vote-up-filled"}}
</span>
- <span class="post-voting-post-list-count">{{@list.length}}</span>
- <SmallUserList class="post-voting-post-list-voters" @users={{@list}} />
+ <span class="post-voting-popup-content__count">{{@list.length}}</span>
+ <SmallUserList
+ class="post-voting-popup-content__voters"
+ @users={{@list}}
+ />
</div>
{{/if}}
</template>;
diff --git a/plugins/discourse-post-voting/assets/javascripts/discourse/connectors/topic-above-post-stream/add-post-voting-topic-page-class.gjs b/plugins/discourse-post-voting/assets/javascripts/discourse/connectors/topic-above-post-stream/add-post-voting-topic-page-class.gjs
index 1f00ff3950a..645b458b269 100644
--- a/plugins/discourse-post-voting/assets/javascripts/discourse/connectors/topic-above-post-stream/add-post-voting-topic-page-class.gjs
+++ b/plugins/discourse-post-voting/assets/javascripts/discourse/connectors/topic-above-post-stream/add-post-voting-topic-page-class.gjs
@@ -4,13 +4,10 @@ import { ORDER_BY_ACTIVITY_FILTER } from "../../components/post-voting-answer-he
const AddPostVotingTopicPageClass = <template>
{{#if @outletArgs.model.is_post_voting}}
- {{bodyClass
- (if
- (eq @outletArgs.model.postStream.filter ORDER_BY_ACTIVITY_FILTER)
- "post-voting-topic-sort-by-activity"
- "post-voting-topic"
- )
- }}
+ {{bodyClass "post-voting-topic"}}
+ {{#if (eq @outletArgs.model.postStream.filter ORDER_BY_ACTIVITY_FILTER)}}
+ {{bodyClass "--sort-by-activity"}}
+ {{/if}}
{{/if}}
</template>;
diff --git a/plugins/discourse-post-voting/assets/javascripts/discourse/initializers/post-voting-edits.gjs b/plugins/discourse-post-voting/assets/javascripts/discourse/initializers/post-voting-edits.gjs
index fd3573071a1..a9caa85125f 100644
--- a/plugins/discourse-post-voting/assets/javascripts/discourse/initializers/post-voting-edits.gjs
+++ b/plugins/discourse-post-voting/assets/javascripts/discourse/initializers/post-voting-edits.gjs
@@ -57,12 +57,12 @@ function customizePost(api) {
orderStreamByActivity() {
this.cancelFilter();
this.set("filter", ORDER_BY_ACTIVITY_FILTER);
- return this.refreshAndJumpToSecondVisible();
+ return this.refresh({ refreshInPlace: true });
}
orderStreamByVotes() {
this.cancelFilter();
- return this.refreshAndJumpToSecondVisible();
+ return this.refresh({ refreshInPlace: true });
}
}
);
diff --git a/plugins/discourse-post-voting/assets/stylesheets/common/post-voting-crawler.scss b/plugins/discourse-post-voting/assets/stylesheets/common/post-voting-crawler.scss
index ca4a4384b4b..5302c997737 100644
--- a/plugins/discourse-post-voting/assets/stylesheets/common/post-voting-crawler.scss
+++ b/plugins/discourse-post-voting/assets/stylesheets/common/post-voting-crawler.scss
@@ -5,29 +5,29 @@ body > noscript {
}
.post-voting-comments {
- padding-top: 15px;
+ padding-top: var(--space-4);
- .post-voting-comment-row {
+ &__comment {
display: flex;
border-top: 1px solid var(--primary-low);
- padding: 5px 0 5px 0;
+ padding: var(--space-1) 0;
+ }
- .post-voting-comment-cooked p,
- .post-voting-comment-creator {
- display: inline;
- }
+ &__comment-cooked p,
+ &__comment-creator {
+ display: inline;
+ }
- .post-voting-comment-info-separator {
- display: inline;
- margin: 0 0.3em;
- }
+ &__separator {
+ display: inline;
+ margin: 0 var(--space-1);
}
}
.post-voting-answer-count {
- padding-top: 20px;
+ padding-top: var(--space-5);
- .post-voting-answer-count-span {
+ &__value {
display: none;
}
}
diff --git a/plugins/discourse-post-voting/assets/stylesheets/common/post-voting.scss b/plugins/discourse-post-voting/assets/stylesheets/common/post-voting.scss
index 5a46186608b..5a2155ceda9 100644
--- a/plugins/discourse-post-voting/assets/stylesheets/common/post-voting.scss
+++ b/plugins/discourse-post-voting/assets/stylesheets/common/post-voting.scss
@@ -1,5 +1,6 @@
-.post-voting-topic,
-.post-voting-topic-sort-by-activity {
+@use "lib/viewport";
+
+.post-voting-topic {
.time-gap,
.topic-post-visited-line,
.timeline-date-wrapper,
@@ -19,285 +20,305 @@
.posts-filtered-notice:empty {
display: none;
}
+
+ @include viewport.until(sm) {
+ .topic-body .cooked {
+ margin-left: calc(48px + var(--space-2));
+ }
+ }
}
.post-voting-answers-header {
box-sizing: border-box;
display: flex;
- flex-direction: row;
- padding: 0.5em;
+ align-items: center;
+ margin-top: var(--space-4);
- .post-voting-answers-headers-count {
- font-size: var(--font-up-1);
+ @include viewport.until(sm) {
+ margin-bottom: var(--space-4);
}
- .post-voting-answers-headers-sort {
- margin-left: auto;
-
- .btn {
- color: var(--primary-high);
- border: 1px solid var(--primary-low-mid);
-
- &:hover {
- background-color: var(--primary-very-low);
- }
+ @include viewport.from(sm) {
+ width: 100%;
+ }
- + .btn {
- margin-left: 0.3em;
- }
+ &__count {
+ margin: 0;
+ font-size: var(--font-0);
+ }
- &:first-of-type {
- margin-left: 0.5em;
- }
- }
+ &__sort {
+ margin: 0;
+ margin-left: auto;
- .btn.active[disabled] {
- background-color: var(--primary-low);
- color: var(--primary);
- opacity: 1;
- cursor: default;
+ .rtl & {
+ margin-right: auto;
}
}
-}
-
-.rtl .qa-answers-header {
- .qa-answers-headers-sort {
- margin-left: unset;
- margin-right: auto;
-
- .btn {
- + .btn {
- margin-left: 0;
- margin-right: 0.3em;
- }
- &:first-of-type {
- margin-left: 0;
- margin-right: 0.5em;
- }
- }
+ .--votes,
+ .--activity {
+ font-size: var(--font-down-1-rem);
}
}
.post-voting-comments {
- width: 100%;
- padding-top: 5px;
-}
+ margin-top: var(--space-1);
-.post-voting-comment {
- font-size: var(--font-down-1);
- border-top: 1px solid var(--primary-low);
- display: flex;
- flex-direction: row;
- align-items: flex-start;
- padding: 0.7em 0;
- word-break: break-word;
+ &__comment {
+ font-size: var(--font-down-1-rem);
+ border-top: 1px solid var(--primary-low);
+ display: flex;
+ align-items: flex-start;
+ padding: var(--space-3) 0;
+ word-break: break-word;
- &.post-voting-comment-deleted {
- background-color: var(--danger-low-mid);
- }
+ &.--deleted {
+ background-color: var(--danger-low);
+ }
- .post-voting-comment-actions-vote {
- margin-right: 0.5em;
- display: inline-grid;
- grid-auto-flow: column;
- align-items: flex-start;
+ &:hover:not(.--deleted) .post-voting-comments__comment-actions {
+ display: inline-block;
+ }
+ }
- .post-voting-comment-actions-vote-count {
- text-align: center;
- width: auto;
- min-width: 16px;
- padding: 0.1em 0;
- color: var(--primary-low-mid-or-secondary-high);
+ &__comment-cooked {
+ p {
+ display: inline;
}
+ }
+
+ &__vote {
+ margin-right: var(--space-2);
+ display: inline-flex;
+ align-items: center;
- .btn {
- font-size: var(--font-up-3);
- background: none;
+ .post-voting-button {
+ font-size: var(--font-up-1);
padding: 0;
- &.post-voting-button-voted {
+ .d-icon {
+ color: var(--primary-low-mid);
+ }
+
+ &.--voted {
.d-icon {
color: var(--success);
}
}
- }
- }
- .post-voting-comment-post {
- .post-voting-comment-cooked {
- p {
- display: inline;
+ &:focus-visible,
+ .discourse-no-touch &:hover {
+ .d-icon {
+ color: var(--primary-high);
+ }
}
}
+ }
- .post-voting-comment-info-separator {
- margin: 0 0.3em;
- }
+ &__vote-count {
+ color: var(--primary-high);
+ min-width: 3ch;
+ text-align: center;
- .post-voting-comment-info-username {
- display: inline;
- margin-right: 0.3em;
+ &.--none {
+ color: var(--primary-low-mid);
}
+ }
- .post-voting-comment-info-created,
- .post-voting-comment-info-username-deleted {
- color: var(--primary-med-or-secondary-med);
- }
+ &__separator {
+ margin: 0 var(--space-1);
+ }
- .post-voting-comment-actions {
- display: none;
- margin-left: 0.3em;
+ &__username {
+ display: inline;
+ margin-right: var(--space-1);
- .post-voting-comment-actions-edit-link {
- color: var(--primary-med-or-secondary-med);
- margin-right: 0.25em;
- }
+ &.--deleted {
+ color: var(--primary-med-or-secondary-med);
+ }
+ }
- .post-voting-comment-actions-delete-link {
- color: var(--primary-med-or-secondary-med);
- margin-right: 0.25em;
- }
+ &__created {
+ color: var(--primary-med-or-secondary-med);
+ }
- .post-voting-comment-actions-delete-link:hover {
- color: var(--danger);
- }
+ &__comment-actions {
+ display: none;
+ margin-left: var(--space-1);
+ }
- .post-voting-comment-actions-flag-link {
- color: var(--primary-med-or-secondary-med);
- }
+ &__comment-actions-edit-link,
+ &__comment-actions-delete-link,
+ &__comment-actions-flag-link {
+ padding: 0 var(--space-1);
+ height: 100%;
+ }
- .post-voting-comment-actions-flag-link:hover {
- color: var(--danger);
- }
+ &__comment-actions-delete-link:hover,
+ &__comment-actions-flag-link:hover {
+ .discourse-no-touch & {
+ color: var(--danger) !important;
}
}
- .post-voting-comment-editor {
- margin: 0.5em 0;
+ &__comment-editor {
+ margin: var(--space-2) 0;
width: 100%;
textarea {
width: 100%;
margin-bottom: 0;
- }
-
- .post-voting-comment-editor-cancel {
- margin-left: 0.5em;
+ font-size: var(--font-down-1-rem);
}
}
- &:hover {
- .post-voting-comment-actions {
- display: inline-block;
- }
+ &__comment-editor-cancel {
+ margin-left: var(--space-2);
}
-}
-
-.post-voting-comment-composer {
- width: 100%;
- .post-voting-comment-composer-textarea {
+ &__composer {
width: 100%;
- margin: 0.5em 0;
+ position: relative;
}
- .post-voting-comment-composer-flash {
+ &__composer-textarea {
width: 100%;
- color: var(--primary-med-or-secondary-med);
-
- &.error {
- color: var(--danger-hover);
- }
- margin-bottom: 0.5em;
- }
-}
-
-.post-voting-comments-menu {
- font-size: var(--font-down-1);
- margin: 0;
-
- .post-voting-comments-menu-composer-cancel {
- margin-left: 0.5em;
+ margin: var(--space-2) 0;
}
- .post-voting-comments-menu-separator {
- margin: 0 0.8em;
- display: inline;
-
- &::after {
- content: "|";
+ &__composer-flash {
+ position: absolute;
+ bottom: 0;
+ right: 0;
+ display: inline-block;
+ width: auto;
+ margin: 0;
+ transform: translateY(+50%);
+ color: var(--primary-medium);
+ font-size: var(--font-down-1-rem);
+
+ &.has-error {
+ color: var(--danger);
}
}
- .post-voting-comments-menu-show-more,
- .post-voting-comments-menu-add-link {
- display: inline;
+ &__composer-add {
+ font-size: var(--font-down-1);
+ margin: 0;
}
-}
-.topic-post:has(.post-voting-post-list) {
- position: relative;
- z-index: 3;
+ &__actions {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ }
}
.post-voting-post {
position: relative;
display: flex;
flex-direction: column;
- align-items: center;
- justify-content: center;
- margin-top: 0.5em;
+ align-items: stretch;
+ margin-top: var(--space-2);
+
+ @include viewport.until(sm) {
+ position: absolute;
+ left: 0;
+ top: var(--space-11);
+ width: var(--space-11);
+ }
.post-voting-button {
- padding-top: 0.1em;
- padding-bottom: 0.1em;
- font-size: var(--font-up-5);
+ padding: var(--space-half) var(--space-1);
+ color: var(--primary-low-mid);
+
+ .d-icon {
+ color: inherit;
+ }
+
+ &.--downvote {
+ .d-icon {
+ transform: rotate(180deg);
+ }
+ }
+
+ &:focus-visible,
+ .discourse-no-touch &:hover {
+ .d-icon {
+ color: var(--primary-high);
+ }
+ }
+
+ &.--voted {
+ .d-icon {
+ color: var(--success);
+ }
+
+ &.--downvote {
+ .d-icon {
+ color: var(--danger);
+ }
+ }
+ }
}
- .post-voting-post-list {
- position: absolute;
- z-index: 2;
- background-color: var(--secondary);
- border: 1px solid var(--primary-low);
- box-shadow: var(--shadow-card);
+ &__toggle-voters {
+ font-size: var(--font-down-1);
+ padding: var(--space-half) var(--space-2);
+ text-align: center;
+ color: var(--primary-high);
+ }
+}
+
+// DMenu
+.post-voting-popup-content {
+ .fk-d-menu__inner-content {
display: flex;
flex-direction: column;
- top: 4em;
- padding: 0.5em;
+ padding: var(--space-2) var(--space-3);
+ width: max-content;
max-width: 90vw;
- overflow: auto;
-
- .post-voting-post-list-voters-wrapper {
- display: flex;
- flex-direction: row;
- }
}
- .post-voting-post-list-voters {
+ &__wrapper {
display: flex;
+ flex-direction: row;
+ gap: var(--space-3);
- a {
- margin-left: 0.25em;
- margin-bottom: 0.25em;
+ // &:first-child {
+ // padding-bottom: var(--space-2);
+ // }
+ &:nth-child(2) {
+ border-top: 1px solid var(--primary-low);
+ padding-top: var(--space-2);
+ margin-top: var(--space-2);
}
}
- .post-voting-post-list-count,
- .post-voting-post-list-icon {
- margin: 0.15em 0.25em 0 0.25em;
- font-size: var(--font-up-1);
- color: var(--primary-low-mid);
+ &__voters {
+ .small-user-list-content {
+ gap: var(--space-1);
+ justify-content: flex-start;
+ }
}
- .post-voting-button-voted {
- .d-icon {
- color: var(--success);
- }
+ &__count {
+ color: var(--primary-high);
}
- .post-voting-post-toggle-voters {
- padding-top: 0;
- padding-bottom: 0;
+ &__icon {
+ &.--upvote {
+ .d-icon {
+ color: var(--success);
+ }
+ }
+
+ &.--downvote {
+ .d-icon {
+ color: var(--danger);
+ transform: rotate(180deg);
+ }
+ }
}
}
diff --git a/plugins/discourse-post-voting/assets/stylesheets/desktop/post-voting.scss b/plugins/discourse-post-voting/assets/stylesheets/desktop/post-voting.scss
deleted file mode 100644
index c46dfef0d6f..00000000000
--- a/plugins/discourse-post-voting/assets/stylesheets/desktop/post-voting.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-.post-voting-answers-header {
- width: 100%;
-}
diff --git a/plugins/discourse-post-voting/assets/stylesheets/mobile/post-voting.scss b/plugins/discourse-post-voting/assets/stylesheets/mobile/post-voting.scss
deleted file mode 100644
index 8ab4007f94f..00000000000
--- a/plugins/discourse-post-voting/assets/stylesheets/mobile/post-voting.scss
+++ /dev/null
@@ -1,33 +0,0 @@
-.post-voting-topic,
-.post-voting-topic-sort-by-activity {
- .post-voting-answers-header {
- width: unset;
- padding: 0;
- padding-bottom: 1em;
- border-top: none;
- border-bottom: 1px solid var(--primary-low);
- margin-bottom: 1em;
- }
-
- .topic-avatar {
- position: relative;
- }
-
- // TODO: avoid using magic values here
- // and in .post-voting-post below
- .topic-body .cooked {
- margin-left: 55px;
- min-height: 55px;
- }
-}
-
-.post-voting-post {
- position: absolute;
- left: 0;
- top: 45px;
- width: 45px;
-
- .post-voting-post-list {
- left: -5px;
- }
-}
diff --git a/plugins/discourse-post-voting/config/locales/client.en.yml b/plugins/discourse-post-voting/config/locales/client.en.yml
index 892e64f06e4..0a1fa8a0125 100644
--- a/plugins/discourse-post-voting/config/locales/client.en.yml
+++ b/plugins/discourse-post-voting/config/locales/client.en.yml
@@ -37,6 +37,14 @@ en:
already_voted: "You can only vote once per question."
user_over_limit: "You cannot exceed the number of votes for your trust level."
one_vote_per_post: "You can only vote once for each post."
+ button:
+ upvote: "Upvote"
+ remove_upvote: "Remove upvote"
+ downvote: "Downvote"
+ remove_downvote: "Remove downvote"
+ toggle_voters: "Show who voted"
+ upvotes: "Upvotes"
+ downvotes: "Downvotes"
last_answer_lowercase: last answer
answer_lowercase:
@@ -59,6 +67,10 @@ en:
edit: "edit"
cancel: "cancel"
add: "Add a comment"
+ actions:
+ edit: "Edit comment"
+ delete: "Delete comment"
+ flag: "Flag comment"
show:
one: Show %{count} more comment
other: Show %{count} more comments
diff --git a/plugins/discourse-post-voting/plugin.rb b/plugins/discourse-post-voting/plugin.rb
index 0749cd76d81..574f7240d23 100644
--- a/plugins/discourse-post-voting/plugin.rb
+++ b/plugins/discourse-post-voting/plugin.rb
@@ -7,9 +7,7 @@
# authors: Alan Tan
# url: https://github.com/discourse/discourse/tree/main/plugins/discourse-post-voting
-%i[common mobile desktop].each do |type|
- register_asset "stylesheets/#{type}/post-voting.scss", type
-end
+register_asset "stylesheets/common/post-voting.scss"
register_asset "stylesheets/common/post-voting-crawler.scss"
enabled_site_setting :post_voting_enabled
@@ -43,7 +41,8 @@ after_initialize do
require_relative "app/serializers/reviewable_post_voting_comments_serializer"
require_relative "config/routes"
- register_svg_icon "angle-up"
+ register_svg_icon "vote-up"
+ register_svg_icon "vote-up-filled"
register_svg_icon "info"
register_post_custom_field_type("vote_history", :json)
@@ -116,6 +115,12 @@ after_initialize do
TopicView.on_preload do |topic_view|
next if !topic_view.topic.is_post_voting?
+ topic_view.comments = {}
+ topic_view.comments_counts = {}
+ topic_view.posts_user_voted = {}
+ topic_view.comments_user_voted = {}
+ topic_view.posts_voted_on = []
+
post_ids = topic_view.posts.pluck(:id)
next if post_ids.blank?
@@ -142,7 +147,6 @@ after_initialize do
AND post_voting_comments.deleted_at IS NULL
SQL
- topic_view.comments = {}
PostVotingComment
.includes(:user)
.where("id IN (#{comment_ids_sql})")
@@ -154,9 +158,6 @@ after_initialize do
topic_view.comments_counts = PostVotingComment.where(post_id: post_ids).group(:post_id).count
- topic_view.posts_user_voted = {}
- topic_view.comments_user_voted = {}
-
if topic_view.guardian.user
PostVotingVote
.where(user: topic_view.guardian.user, votable_type: "Post", votable_id: post_ids)
diff --git a/plugins/discourse-post-voting/spec/requests/topics_controller_spec.rb b/plugins/discourse-post-voting/spec/requests/topics_controller_spec.rb
index 67fc392c4c5..57ee59a907b 100644
--- a/plugins/discourse-post-voting/spec/requests/topics_controller_spec.rb
+++ b/plugins/discourse-post-voting/spec/requests/topics_controller_spec.rb
@@ -61,10 +61,10 @@ describe TopicsController do
crawler_html = response.body
expect(crawler_html).to match(
- %r{<span class="post-voting-comment-cooked" itemprop="comment"><p>this is a comment!</p></span>},
+ %r{<span class="post-voting-comments__comment-cooked" itemprop="comment"><p>this is a comment!</p></span>},
)
expect(crawler_html).to match(
- %r{<span class="post-voting-answer-count-span" itemprop="answerCount">3</span>},
+ %r{<span class="post-voting-answer-count__value" itemprop="answerCount">3</span>},
)
end
end
diff --git a/plugins/discourse-post-voting/spec/system/page_objects/pages/post_voting_topic.rb b/plugins/discourse-post-voting/spec/system/page_objects/pages/post_voting_topic.rb
index 252dc17bee8..e9d17300d2b 100644
--- a/plugins/discourse-post-voting/spec/system/page_objects/pages/post_voting_topic.rb
+++ b/plugins/discourse-post-voting/spec/system/page_objects/pages/post_voting_topic.rb
@@ -3,16 +3,16 @@
module PageObjects
module Pages
class PostVotingTopic < PageObjects::Pages::Topic
- COMMENT_VOTE_BUTTON = ".post-voting-comment-actions-vote button"
+ COMMENT_VOTE_BUTTON = ".post-voting-comments__vote button"
POST_VOTE_BUTTON = ".post-voting-post button"
- COMMENT_ACTIONS = ".post-voting-comment-actions"
+ COMMENT_ACTIONS = ".post-voting-comments__comment-actions"
def has_no_comment_menu?
- has_no_css?(".post-voting-comments-menu")
+ has_no_css?(".post-voting-comments__menu")
end
def click_vote_count(post)
- find("#post_#{post.post_number} .post-voting-post-toggle-voters").click
+ find("#post_#{post.post_number} .post-voting-post__toggle-voters").click
self
end
diff --git a/plugins/discourse-post-voting/test/javascripts/acceptance/post-voting-test.js b/plugins/discourse-post-voting/test/javascripts/acceptance/post-voting-test.js
index 6153e644ec7..d36adbe74d7 100644
--- a/plugins/discourse-post-voting/test/javascripts/acceptance/post-voting-test.js
+++ b/plugins/discourse-post-voting/test/javascripts/acceptance/post-voting-test.js
@@ -214,27 +214,27 @@ acceptance("anon user", function (needs) {
await visit("/t/280");
assert
- .dom("#post_1 .post-voting-comment")
+ .dom("#post_1 .post-voting-comments__comment")
.exists(
{ count: 1 },
"displays the right number of comments for the first post"
);
assert
- .dom("#post_2 .post-voting-comment")
+ .dom("#post_2 .post-voting-comments__comment")
.exists(
{ count: 5 },
"displays the right number of comments for the second post"
);
assert
- .dom("#post_2 .post-voting-comment-action")
- .doesNotExist("does not display comment action to anon users");
+ .dom("#post_2 .post-voting-comments__comment-actions")
+ .doesNotExist("does not display comment actions to anon users");
- await click(".post-voting-comments-menu-show-more-link");
+ await click(".post-voting-comments__actions-show-more");
assert
- .dom("#post_2 .post-voting-comment")
+ .dom("#post_2 .post-voting-comments__comment")
.exists(
{ count: 6 },
"displays the right number of comments after loading more"
@@ -242,21 +242,21 @@ acceptance("anon user", function (needs) {
assert
.dom(
- "#post_2 .post-voting-comments #post-voting-comment-6 .post-voting-comment-info-username"
+ "#post_2 .post-voting-comments #post-voting-comment-6 .post-voting-comments__username"
)
.hasText(i18n("post_voting.post.post_voting_comment.user.deleted"));
});
test("adding a comment", async function (assert) {
await visit("/t/280");
- await click(".post-voting-comment-add-link");
+ await click(".post-voting-comments__actions-add");
assert.dom("#login-form").exists("displays the login screen");
});
test("voting a comment", async function (assert) {
await visit("/t/280");
- await click("#post_2 #post-voting-comment-2 .post-voting-button-upvote");
+ await click("#post_2 #post-voting-comment-2 .post-voting-button.--upvote");
assert.dom("#login-form").exists("displays the login screen");
});
@@ -302,6 +302,10 @@ acceptance("logged in user", function (needs) {
.doesNotHaveClass(
"post-voting-topic",
"does not append Post Voting specific class on body tag"
+ )
+ .doesNotHaveClass(
+ "--sort-by-activity",
+ "does not append sort-by-activity modifier on body tag"
);
});
@@ -320,8 +324,8 @@ acceptance("logged in user", function (needs) {
await visit("/t/280");
assert
- .dom(".post-voting-answers-headers-sort-votes")
- .isDisabled("sort by votes button is disabled by default");
+ .dom(".post-voting-answers-header__sort .--votes")
+ .hasClass("active", "sort by votes is active by default");
assert
.dom(document.body)
@@ -330,7 +334,7 @@ acceptance("logged in user", function (needs) {
"appends the right class to body when loading Post Voting topic"
);
- await click(".post-voting-answers-headers-sort-activity");
+ await click(".post-voting-answers-header__sort .--activity");
assert.true(
filteredByActivity,
@@ -340,25 +344,29 @@ acceptance("logged in user", function (needs) {
assert
.dom(document.body)
.hasClass(
- "post-voting-topic-sort-by-activity",
- "appends the right class to body when topic is filtered by activity"
+ "--sort-by-activity",
+ "appends the sort-by-activity modifier on body when topic is filtered by activity"
);
assert
- .dom(".post-voting-answers-headers-sort-activity")
- .isDisabled("disabled sort by activity button");
+ .dom(".post-voting-answers-header__sort .--activity")
+ .hasClass("active", "marks sort by activity as active");
- await click(".post-voting-answers-headers-sort-votes");
+ await click(".post-voting-answers-header__sort .--votes");
assert
- .dom(".post-voting-answers-headers-sort-votes")
- .isDisabled("disables sort by votes button");
+ .dom(".post-voting-answers-header__sort .--votes")
+ .hasClass("active", "marks sort by votes as active");
assert
.dom(document.body)
.hasClass(
"post-voting-topic",
- "appends the right class to body when topic is filtered by votes"
+ "keeps the topic class on body when filtered by votes"
+ )
+ .doesNotHaveClass(
+ "--sort-by-activity",
+ "removes the sort-by-activity modifier from body"
);
assert.false(
@@ -393,11 +401,11 @@ acceptance("logged in user", function (needs) {
test("validations for comment length", async function (assert) {
await visit("/t/280");
- await click("#post_1 .post-voting-comment-add-link");
+ await click("#post_1 .post-voting-comments__actions-add");
- await fillIn(".post-voting-comment-composer-textarea", "a".repeat(4));
+ await fillIn(".post-voting-comments__composer-textarea", "a".repeat(4));
- assert.dom(".post-voting-comment-composer-flash").hasText(
+ assert.dom(".post-voting-comments__composer-flash").hasText(
i18n("post_voting.post.post_voting_comment.composer.too_short", {
count: 5,
}),
@@ -405,87 +413,78 @@ acceptance("logged in user", function (needs) {
);
assert
- .dom(".post-voting-comments-menu-composer-submit")
+ .dom(".post-voting-comments__composer-submit")
.isDisabled("submit comment button is disabled");
- await fillIn(".post-voting-comment-composer-textarea", "a".repeat(6));
+ await fillIn(".post-voting-comments__composer-textarea", "a".repeat(6));
- assert.dom(".post-voting-comment-composer-flash").hasText(
- i18n("post_voting.post.post_voting_comment.composer.length_ok", {
- count: 44,
- }),
- "displays the right message about raw length when it is OK"
- );
+ assert
+ .dom(".post-voting-comments__composer-flash")
+ .hasText(
+ "6/50",
+ "displays current/max character count when length is OK"
+ );
assert
- .dom(".post-voting-comments-menu-composer-submit")
+ .dom(".post-voting-comments__composer-submit")
.isEnabled("submit comment button is enabled");
- await fillIn(".post-voting-comment-composer-textarea", "a".repeat(51));
-
- assert.dom(".post-voting-comment-composer-flash").hasText(
- i18n("post_voting.post.post_voting_comment.composer.too_long", {
- count: 50,
- }),
- "displays the right message about raw length when it is too long"
- );
-
assert
- .dom(".post-voting-comments-menu-composer-submit")
- .isDisabled("submit comment button is disabled");
+ .dom(".post-voting-comments__composer-textarea")
+ .hasAttribute(
+ "maxlength",
+ "50",
+ "enforces the comment length limit via maxlength"
+ );
});
test("adding a comment", async function (assert) {
await visit("/t/280");
assert
- .dom("#post_1 .post-voting-comment")
+ .dom("#post_1 .post-voting-comments__comment")
.exists(
{ count: 1 },
"displays the right number of comments for the first post"
);
- await click("#post_1 .post-voting-comment-add-link");
+ await click("#post_1 .post-voting-comments__actions-add");
assert
- .dom("#post_1 .post-voting-comment")
+ .dom("#post_1 .post-voting-comments__comment")
.exists({ count: 2 }, "loads all comments when composer is expanded");
await fillIn(
- ".post-voting-comment-composer-textarea",
+ ".post-voting-comments__composer-textarea",
"this is some comment"
);
- await click(".post-voting-comments-menu-composer-submit");
+ await click(".post-voting-comments__composer-submit");
assert
- .dom("#post_1 .post-voting-comment")
+ .dom("#post_1 .post-voting-comments__comment")
.exists({ count: 3 }, "should add the new comment");
});
test("adding a comment with keyboard shortcut", async function (assert) {
await visit("/t/280");
- await click("#post_1 .post-voting-comment-add-link");
+ await click("#post_1 .post-voting-comments__actions-add");
assert
- .dom("#post_1 .post-voting-comment")
+ .dom("#post_1 .post-voting-comments__comment")
.exists({ count: 2 }, "loads all comments when composer is expanded");
await fillIn(
- ".post-voting-comment-composer-textarea",
+ ".post-voting-comments__composer-textarea",
"this is a new test comment"
);
- await triggerEvent(
- ".post-voting-comments-menu-composer-submit",
- "keydown",
- {
- key: "Enter",
- ctrlKey: true,
- }
- );
+ await triggerEvent(".post-voting-comments__composer-submit", "keydown", {
+ key: "Enter",
+ ctrlKey: true,
+ });
assert
- .dom("#post_1 .post-voting-comment")
+ .dom("#post_1 .post-voting-comments__comment")
.exists({ count: 3 }, "should add the new comment");
});
@@ -495,7 +494,7 @@ acceptance("logged in user", function (needs) {
await visit("/t/280");
assert
- .dom("#post_2 .post-voting-comment-actions")
+ .dom("#post_2 .post-voting-comments__comment-actions")
.doesNotExist("does not display edit link on other people's comments");
});
@@ -505,7 +504,7 @@ acceptance("logged in user", function (needs) {
await visit("/t/280");
assert
- .dom("#post_2 .post-voting-comment-actions")
+ .dom("#post_2 .post-voting-comments__comment-actions")
.exists({ count: 5 }, "displays edit link on other people's comments");
});
@@ -515,7 +514,7 @@ acceptance("logged in user", function (needs) {
await visit("/t/280");
assert
- .dom("#post_2 .post-voting-comment-actions")
+ .dom("#post_2 .post-voting-comments__comment-actions")
.exists({ count: 5 }, "displays edit link on other people's comments");
});
@@ -525,17 +524,17 @@ acceptance("logged in user", function (needs) {
await visit("/t/280");
assert
- .dom("#post_1 .post-voting-comment-cooked")
+ .dom("#post_1 .post-voting-comments__comment-cooked")
.hasText(
"Test comment 1",
"displays the right content for the given comment"
);
- await click("#post_1 .post-voting-comment-actions-edit-link");
+ await click("#post_1 .post-voting-comments__comment-actions-edit-link");
- await fillIn(".post-voting-comment-composer-textarea", "a".repeat(4));
+ await fillIn(".post-voting-comments__composer-textarea", "a".repeat(4));
- assert.dom(".post-voting-comment-composer-flash").hasText(
+ assert.dom(".post-voting-comments__composer-flash").hasText(
i18n("post_voting.post.post_voting_comment.composer.too_short", {
count: 5,
}),
@@ -543,38 +542,38 @@ acceptance("logged in user", function (needs) {
);
assert
- .dom(".post-voting-comment-editor-submit")
+ .dom(".post-voting-comments__comment-editor-submit")
.isDisabled("submit comment button is disabled");
await fillIn(
- "#post_1 .post-voting-comment-editor-1 textarea",
+ "#post_1 .post-voting-comments__comment-editor-1 textarea",
"editing this"
);
- assert.dom(".post-voting-comment-composer-flash").hasText(
- i18n("post_voting.post.post_voting_comment.composer.length_ok", {
- count: 38,
- }),
- "displays the right message when comment length is OK"
- );
+ assert
+ .dom(".post-voting-comments__composer-flash")
+ .hasText(
+ "12/50",
+ "displays current/max character count when comment length is OK"
+ );
assert
- .dom(".post-voting-comment-editor-submit")
+ .dom(".post-voting-comments__comment-editor-submit")
.isEnabled("submit comment button is enabled");
await click(
- "#post_1 .post-voting-comment-editor-1 .post-voting-comment-editor-submit"
+ "#post_1 .post-voting-comments__comment-editor-1 .post-voting-comments__comment-editor-submit"
);
assert
- .dom("#post_1 .post-voting-comment-cooked")
+ .dom("#post_1 .post-voting-comments__comment-cooked")
.hasText(
"editing this",
"displays the right content after comment has been edited"
);
assert
- .dom("#post_1 .post-voting-comment-editor-1")
+ .dom("#post_1 .post-voting-comments__comment-editor-1")
.doesNotExist("hides editor after comment has been edited");
});
@@ -584,21 +583,18 @@ acceptance("logged in user", function (needs) {
await visit("/t/280");
assert
- .dom("#post_1 .post-voting-comment")
+ .dom("#post_1 .post-voting-comments__comment")
.exists(
{ count: 1 },
"displays the right number of comments for the first post"
);
- await click("#post_1 .post-voting-comment-actions-delete-link");
+ await click("#post_1 .post-voting-comments__comment-actions-delete-link");
await click("button.btn-danger");
assert
.dom("#post_1 #post-voting-comment-1")
- .hasClass(
- "post-voting-comment-deleted",
- "adds the right class to deleted comment"
- );
+ .hasClass("--deleted", "adds the right modifier to deleted comment");
});
test("deleting a comment after more comments have been loaded", async function (assert) {
@@ -607,73 +603,64 @@ acceptance("logged in user", function (needs) {
await visit("/t/280");
assert
- .dom("#post_2 .post-voting-comment")
+ .dom("#post_2 .post-voting-comments__comment")
.exists(
{ count: 5 },
"displays the right number of comments for the second post"
);
- await click("#post_2 .post-voting-comments-menu-show-more-link");
+ await click("#post_2 .post-voting-comments__actions-show-more");
assert
- .dom("#post_2 .post-voting-comment")
+ .dom("#post_2 .post-voting-comments__comment")
.exists({ count: 6 }, "appends the loaded comments");
const comments = document.querySelectorAll(
- "#post_2 .post-voting-comment-actions-delete-link"
+ "#post_2 .post-voting-comments__comment-actions-delete-link"
);
await click(comments[comments.length - 1]);
await click("button.btn-danger");
assert
- .dom("#post_2 .post-voting-comments-menu-show-more-link")
+ .dom("#post_2 .post-voting-comments__actions-show-more")
.doesNotExist(
"updates the comment count such that show more link is not displayed"
);
assert
.dom("#post_2 #post-voting-comment-7")
- .hasClass(
- "post-voting-comment-deleted",
- "adds the right class to deleted comment"
- );
+ .hasClass("--deleted", "adds the right modifier to deleted comment");
});
test("vote count display", async function (assert) {
await visit("/t/280");
assert
- .dom(
- "#post_2 #post-voting-comment-2 .post-voting-comment-actions-vote-count"
- )
- .doesNotExist("does not display element if vote count is zero");
+ .dom("#post_2 #post-voting-comment-2 .post-voting-comments__vote-count")
+ .hasClass("--none", "marks zero vote count with --none modifier")
+ .hasText("0", "displays 0 when vote count is zero");
assert
- .dom(
- "#post_2 #post-voting-comment-3 .post-voting-comment-actions-vote-count"
- )
+ .dom("#post_2 #post-voting-comment-3 .post-voting-comments__vote-count")
.hasText("3", "displays the right vote count");
});
test("voting on a comment and removing vote", async function (assert) {
await visit("/t/280");
- await click("#post_2 #post-voting-comment-2 .post-voting-button-upvote");
+ await click("#post_2 #post-voting-comment-2 .post-voting-button.--upvote");
assert
- .dom(
- "#post_2 #post-voting-comment-2 .post-voting-comment-actions-vote-count"
- )
+ .dom("#post_2 #post-voting-comment-2 .post-voting-comments__vote-count")
.hasText("1", "updates the comment vote count correctly");
- await click("#post_2 #post-voting-comment-2 .post-voting-button-upvote");
+ await click("#post_2 #post-voting-comment-2 .post-voting-button.--upvote");
assert
- .dom(
- "#post_2 #post-voting-comment-2 .post-voting-comment-actions-vote-count"
- )
- .doesNotExist("updates the comment vote count correctly");
+ .dom("#post_2 #post-voting-comment-2 .post-voting-comments__vote-count")
+ .hasClass("--none", "reverts to --none modifier when vote is removed")
+ .hasText("0", "displays 0 after vote is removed");
});
test("topic list link overrides work", async function (assert) {
@@ -707,15 +694,12 @@ acceptance("logged in user", function (needs) {
await settled();
assert
- .dom("#post_2 span.post-voting-post-toggle-voters")
+ .dom("#post_2 span.post-voting-post__toggle-voters")
.hasText("0", "displays the right count");
assert
- .dom("#post_2 .post-voting-button-upvote")
- .doesNotHaveClass(
- "post-voting-button-voted",
- "does not highlight the upvote button"
- );
+ .dom("#post_2 .post-voting-button.--upvote")
+ .doesNotHaveClass("--voted", "does not highlight the upvote button");
});
test("receiving user post voted message where post no longer has votes", async function (assert) {
@@ -733,7 +717,7 @@ acceptance("logged in user", function (needs) {
await settled();
assert
- .dom("#post_2 span.post-voting-post-toggle-voters")
+ .dom("#post_2 span.post-voting-post__toggle-voters")
.hasText("0", "does not render a button to show post voters");
});
@@ -752,7 +736,7 @@ acceptance("logged in user", function (needs) {
await settled();
assert
- .dom("#post_2 .post-voting-post-toggle-voters")
+ .dom("#post_2 .post-voting-post__toggle-voters")
.hasText("0", "displays 0 when upvotes and downvotes cancel out");
});
@@ -771,20 +755,17 @@ acceptance("logged in user", function (needs) {
await settled();
assert
- .dom("#post_2 .post-voting-post-toggle-voters")
+ .dom("#post_2 .post-voting-post__toggle-voters")
.hasText("5", "displays the right post vote count");
assert
- .dom("#post_2 .post-voting-button-upvote")
- .hasClass(
- "post-voting-button-voted",
- "highlights the upvote button for the current user"
- );
+ .dom("#post_2 .post-voting-button.--upvote")
+ .hasClass("--voted", "highlights the upvote button for the current user");
assert
- .dom("#post_2 .post-voting-button-downvote")
+ .dom("#post_2 .post-voting-button.--downvote")
.doesNotHaveClass(
- "post-voting-button-voted",
+ "--voted",
"does not highlight the downvote button for the current user"
);
});
@@ -804,15 +785,12 @@ acceptance("logged in user", function (needs) {
await settled();
assert
- .dom("#post_2 .post-voting-post-toggle-voters")
+ .dom("#post_2 .post-voting-post__toggle-voters")
.hasText("5", "displays the right post vote count");
assert
- .dom("#post_2 .post-voting-button-upvote")
- .hasClass(
- "post-voting-button-voted",
- "highlights the upvote button for the current user"
- );
+ .dom("#post_2 .post-voting-button.--upvote")
+ .hasClass("--voted", "highlights the upvote button for the current user");
});
test("receiving post commented message when comment has already been loaded", async function (assert) {
@@ -910,7 +888,7 @@ acceptance("logged in user", function (needs) {
);
assert
- .dom("#post_2 .post-voting-comments-menu-show-more-link")
+ .dom("#post_2 .post-voting-comments__actions-show-more")
.exists("updates the comments count to reflect the new comment");
});
@@ -927,7 +905,7 @@ acceptance("logged in user", function (needs) {
await settled();
assert
- .dom("#post_2 .post-voting-comments-menu-show-more-link")
+ .dom("#post_2 .post-voting-comments__actions-show-more")
.doesNotExist("removes the show more comments link");
});
@@ -945,10 +923,7 @@ acceptance("logged in user", function (needs) {
assert
.dom("#post_2 #post-voting-comment-2")
- .hasClass(
- "post-voting-comment-deleted",
- "adds the right class to the comment"
- );
+ .hasClass("--deleted", "adds the right modifier to the comment");
});
test("receiving post comment edited message for a comment that has been loaded", async function (assert) {
@@ -965,19 +940,21 @@ acceptance("logged in user", function (needs) {
await settled();
assert
- .dom("#post_1 #post-voting-comment-1 .post-voting-comment-cooked")
+ .dom(
+ "#post_1 #post-voting-comment-1 .post-voting-comments__comment-cooked"
+ )
.hasText(
"this is a new comment cooked",
"updates the content of the comment"
);
await click(
- "#post_1 #post-voting-comment-1 .post-voting-comment-actions-edit-link"
+ "#post_1 #post-voting-comment-1 .post-voting-comments__comment-actions-edit-link"
);
assert
.dom(
- "#post_1 #post-voting-comment-1 .post-voting-comment-composer textarea"
+ "#post_1 #post-voting-comment-1 .post-voting-comments__composer textarea"
)
.hasValue(
"this is a new comment raw",