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

Make voting tool sticky #933

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/assets/stylesheets/posts.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
}
}

.sticky {
position: sticky;
top: 50px;
}

.post--container {
max-width: 100%;

Expand Down
76 changes: 40 additions & 36 deletions app/views/posts/_expanded.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,44 +38,47 @@
<div class="post--container <%= 'deleted-content' if post.deleted? %> grid is-nowrap">
<% if post_type.has_votes %>
<div>
<div class="post--votes has-text-align-center" title="Score : <%= post.score %>">
<% existing_vote = my_vote(post) %>
<% unless post.locked? %>
<button class="vote-button button is-icon-only-button <%= (existing_vote&.vote_type == 1) ? 'is-active' : '' %>"
data-vote-type="1" data-vote-id="<%= existing_vote&.id %>" id="post-<%= post.id %>-up" aria-label="Upvote">
<svg width="2em" height="1.33em" viewbox="0 0 100 50">
<path d="M50,0 L100,50 L0,50 Z" fill="currentColor" />
</svg>
</button>
<% end %>
<div class="score has-font-size-subheading js-upvote-count">
+<%= post.upvote_count %>
</div>
<div class="score has-font-size-subheading js-downvote-count">
&minus;<%= post.downvote_count %>
</div>
<% unless post.locked? %>
<button class="vote-button button is-icon-only-button <%= (existing_vote&.vote_type == -1) ? 'is-active' : '' %>"
data-vote-type="-1" data-vote-id="<%= existing_vote&.id %>" id="post-<%= post.id %>-up" aria-label="Downvote">
<svg width="2em" height="1.33em" viewbox="0 0 100 50">
<path d="M0,0 L100,0 L50,50 Z" fill="currentColor" />
</svg>
</button>
<% end %>
</div>
<% if user_signed_in? && post.post_type.has_reactions && post.post_type.reactions.any? %>
<div class="post--react has-text-align-center">
<% sticky_votes = user_preference('sticky_vote_tool', community: false) == 'true' %>
<div <% if sticky_votes then %> class="sticky" <% end %>>
<div class="post--votes has-text-align-center" title="Score : <%= post.score %>">
<% existing_vote = my_vote(post) %>
<% unless post.locked? %>
<button class="vote-button button is-icon-only-button <%= (existing_vote&.vote_type == 1) ? 'is-active' : '' %>"
data-vote-type="1" data-vote-id="<%= existing_vote&.id %>" id="post-<%= post.id %>-up" aria-label="Upvote">
<svg width="2em" height="1.33em" viewbox="0 0 100 50">
<path d="M50,0 L100,50 L0,50 Z" fill="currentColor" />
</svg>
</button>
<% end %>
<div class="score has-font-size-subheading js-upvote-count">
+<%= post.upvote_count %>
</div>
<div class="score has-font-size-subheading js-downvote-count">
&minus;<%= post.downvote_count %>
</div>
<% unless post.locked? %>
<button class="react-button button is-muted is-icon-only-button h-fw-bold"
id="post-<%= post.id %>-react" aria-label="Add Reaction"
data-drop="#post-<%= post.id %>-reactions-panel"
data-drop-self-class-toggle="is-active"
data-drop-force-dir="down">
react
<button class="vote-button button is-icon-only-button <%= (existing_vote&.vote_type == -1) ? 'is-active' : '' %>"
data-vote-type="-1" data-vote-id="<%= existing_vote&.id %>" id="post-<%= post.id %>-up" aria-label="Downvote">
<svg width="2em" height="1.33em" viewbox="0 0 100 50">
<path d="M0,0 L100,0 L50,50 Z" fill="currentColor" />
</svg>
</button>
<% end %>
</div>
<% end %>
<% if user_signed_in? && post.post_type.has_reactions && post.post_type.reactions.any? %>
<div class="post--react has-text-align-center">
<% unless post.locked? %>
<button class="react-button button is-muted is-icon-only-button h-fw-bold"
id="post-<%= post.id %>-react" aria-label="Add Reaction"
data-drop="#post-<%= post.id %>-reactions-panel"
data-drop-self-class-toggle="is-active"
data-drop-force-dir="down">
react
</button>
<% end %>
</div>
<% end %>
</div>
</div>
<% end %>

Expand Down Expand Up @@ -148,9 +151,10 @@
<% end %>
<% end %>

<div class="post--body">
<article class="post--body">
<%= raw(sanitize(post.body, scrubber: scrubber)) %>

</article>
<div>
<% been_edited = post.last_edited_by_id != nil %>
<% if been_edited then last_edited_by_self = post.user_id == post.last_edited_by_id end %>

Expand Down
6 changes: 6 additions & 0 deletions config/config/preferences.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,10 @@ sticky_header:
type: boolean
description: >
Make the top navigation bar sticky.
default: false

sticky_vote_tool:
type: boolean
description: >
Make the up and downvote buttons scroll along with the post
default: false