]> cat aescling's git repositories - mastodon.git/commitdiff
Add non-JS fallback for polls on public pages (#10155)
authorThibG <thib@sitedethib.com>
Mon, 4 Mar 2019 17:03:12 +0000 (18:03 +0100)
committerEugen Rochko <eugen@zeonfederated.com>
Mon, 4 Mar 2019 17:03:12 +0000 (18:03 +0100)
app/views/stream_entries/_detailed_status.html.haml
app/views/stream_entries/_poll.html.haml [new file with mode: 0644]
app/views/stream_entries/_simple_status.html.haml
config/locales/en.yml

index b9327a546cadd7d820072536e3b1f62770a72b66..b19d2452ad9a66ea3febe007372f56a7f706d65d 100644 (file)
@@ -23,7 +23,8 @@
     .e-content{ lang: status.language, style: "display: #{!current_account&.user&.setting_expand_spoilers && status.spoiler_text? ? 'none' : 'block'}; direction: #{rtl_status?(status) ? 'rtl' : 'ltr'}" }= Formatter.instance.format(status, custom_emojify: true, autoplay: autoplay)
 
   - if status.poll
-    = react_component :poll, disabled: true, poll: ActiveModelSerializers::SerializableResource.new(status.poll, serializer: REST::PollSerializer, scope: current_user, scope_name: :current_user).as_json
+    = react_component :poll, disabled: true, poll: ActiveModelSerializers::SerializableResource.new(status.poll, serializer: REST::PollSerializer, scope: current_user, scope_name: :current_user).as_json do
+      = render partial: 'stream_entries/poll', locals: { poll: status.poll }
   - elsif !status.media_attachments.empty?
     - if status.media_attachments.first.video?
       - video = status.media_attachments.first
diff --git a/app/views/stream_entries/_poll.html.haml b/app/views/stream_entries/_poll.html.haml
new file mode 100644 (file)
index 0000000..974aff9
--- /dev/null
@@ -0,0 +1,25 @@
+- options = (!poll.expired? && poll.hide_totals?) ? poll.unloaded_options : poll.loaded_options
+- voted = poll.votes.where(account: current_user.account).exists?
+- show_results = voted || poll.expired?
+
+.poll
+  %ul
+    - options.each do |option|
+      %li
+        - if show_results
+          - percent = 100 * option.votes_count / poll.votes_count
+          %span.poll__chart{ style: "width: #{percent}%" }
+          %label.poll__text><
+            %span.poll__number= percent
+            = option.title
+        - else
+          %label.poll__text><
+            %span.poll__input{ class: poll.multiple ? 'checkbox' : nil}><
+            = option.title
+  .poll__footer
+    - unless show_results
+      %button.button.button-secondary{ disabled: true }
+        = t('statuses.poll.vote')
+    %span= t('statuses.poll.total_votes', count: poll.votes_count)
+    ยท
+    %span= poll.expires_at
index a000c02f4c5048c985dc16bb5a665c5f4c4782a7..68e48edbb8c506ed9721e2a3aa92bd2b219b75cf 100644 (file)
@@ -27,7 +27,8 @@
     .e-content{ lang: status.language, style: "display: #{!current_account&.user&.setting_expand_spoilers && status.spoiler_text? ? 'none' : 'block'}; direction: #{rtl_status?(status) ? 'rtl' : 'ltr'}" }= Formatter.instance.format(status, custom_emojify: true, autoplay: autoplay)
 
   - if status.poll
-    = react_component :poll, disabled: true, poll: ActiveModelSerializers::SerializableResource.new(status.poll, serializer: REST::PollSerializer, scope: current_user, scope_name: :current_user).as_json
+    = react_component :poll, disabled: true, poll: ActiveModelSerializers::SerializableResource.new(status.poll, serializer: REST::PollSerializer, scope: current_user, scope_name: :current_user).as_json do
+      = render partial: 'stream_entries/poll', locals: { poll: status.poll }
   - elsif !status.media_attachments.empty?
     - if status.media_attachments.first.video?
       - video = status.media_attachments.first
index b1f6166b4beaa2952ea63af000ca7d484264d1d6..2d23b1eb6e9f24a4e8e4cebc06afbf3929870eff 100644 (file)
@@ -853,6 +853,11 @@ en:
       ownership: Someone else's toot cannot be pinned
       private: Non-public toot cannot be pinned
       reblog: A boost cannot be pinned
+    poll:
+      total_votes:
+        one: "%{count} vote"
+        other: "%{count} votes"
+      vote: Vote
     show_more: Show more
     sign_in_to_participate: Sign in to participate in the conversation
     title: '%{name}: "%{quote}"'