This commit is contained in:
parent
3108e32fa5
commit
7063631787
4 changed files with 62 additions and 8 deletions
|
@ -190,6 +190,13 @@ defp represent(%Activity{object: %Object{data: data}} = activity, selected) do
|
|||
nil
|
||||
end
|
||||
|
||||
total_votes =
|
||||
if data["oneOf"] do
|
||||
Enum.sum(for option <- data["oneOf"], do: option["replies"]["totalItems"])
|
||||
else
|
||||
0
|
||||
end
|
||||
|
||||
%{
|
||||
user: User.sanitize_html(user),
|
||||
title: get_title(activity.object),
|
||||
|
@ -204,7 +211,9 @@ defp represent(%Activity{object: %Object{data: data}} = activity, selected) do
|
|||
visibility: Visibility.get_visibility(activity.object),
|
||||
reply_to: data["inReplyTo"],
|
||||
reply_to_user: reply_to_user,
|
||||
edited_at: data["updated"]
|
||||
edited_at: data["updated"],
|
||||
poll: data["oneOf"],
|
||||
total_votes: total_votes
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -45,4 +45,14 @@ def open_content? do
|
|||
def get_attachment_name(%{"name" => name}), do: name
|
||||
|
||||
def get_attachment_name(_), do: ""
|
||||
|
||||
def poll_percentage(count, total_votes) do
|
||||
case count do
|
||||
0 ->
|
||||
"0%"
|
||||
|
||||
_ ->
|
||||
Integer.to_string(trunc(count / total_votes * 100)) <> "%"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -66,6 +66,17 @@
|
|||
<% end %>
|
||||
<div class="status-body">
|
||||
<%= raw @content %>
|
||||
<%= if @poll && length(@poll) > 0 do %>
|
||||
<div class="poll">
|
||||
<%= for %{"name" => option, "replies" => %{"totalItems" => count}} <- @poll do %>
|
||||
<div class="poll-option" title="<%= count %>/<%= @total_votes %>">
|
||||
<span class="percentage"><%= poll_percentage(count, @total_votes) %></span>
|
||||
<span><%= raw option %></span>
|
||||
<div class="fill" style="width: <%= poll_percentage(count, @total_votes) %>"></div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
<%= if length(@attachment) > 0 do %>
|
||||
<div class="attachments">
|
||||
<%= for attachment = %{"url" => [url | _]} <- @attachment do %>
|
||||
|
|
|
@ -26,6 +26,7 @@ :root {
|
|||
--link: rgba(226, 177, 136, 1);
|
||||
--text: rgba(185, 185, 186, 1);
|
||||
--border: rgba(26, 37, 53, 1);
|
||||
--poll: rgba(99, 84, 72, 1);
|
||||
}
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root {
|
||||
|
@ -55,6 +56,7 @@ @media (prefers-color-scheme: light) {
|
|||
--link: rgba(245, 91, 27, 1);
|
||||
--text: rgba(48, 64, 85, 1);
|
||||
--border: rgba(216, 230, 249, 1);
|
||||
--poll: rgba(243, 184, 160, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -332,6 +334,28 @@ .nsfw-banner:hover div {
|
|||
display: none;
|
||||
}
|
||||
|
||||
.poll-option {
|
||||
position: relative;
|
||||
display: flex;
|
||||
margin: 0.75em 0.5em;
|
||||
padding: 0.1em 0.25em;
|
||||
word-break: break-word;
|
||||
z-index: 1;
|
||||
}
|
||||
.poll-option .percentage {
|
||||
width: 3.5em;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.poll-option .fill {
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
background-color: var(--poll);
|
||||
border-radius: 3px;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: -1;
|
||||
}
|
||||
|
||||
.status-actions {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
|
|
Loading…
Reference in a new issue