feat: Add poll results to a status (#1219)

This commit is contained in:
sgenoud 2019-05-25 17:36:44 +02:00 committed by Nolan Lawson
parent 692e8b57c3
commit af955492e8
2 changed files with 52 additions and 0 deletions

View file

@ -31,6 +31,9 @@
{#if showMedia } {#if showMedia }
<StatusMediaAttachments {...params} on:recalculateHeight /> <StatusMediaAttachments {...params} on:recalculateHeight />
{/if} {/if}
{#if showPoll}
<StatusPoll {...params} />
{/if}
{#if isStatusInOwnThread} {#if isStatusInOwnThread}
<StatusDetails {...params} /> <StatusDetails {...params} />
{/if} {/if}
@ -58,6 +61,7 @@
"sidebar content content content" "sidebar content content content"
"sidebar card card card" "sidebar card card card"
"sidebar media-grp media-grp media-grp" "sidebar media-grp media-grp media-grp"
"sidebar poll poll poll"
"media media media media" "media media media media"
"....... toolbar toolbar toolbar" "....... toolbar toolbar toolbar"
"compose compose compose compose"; "compose compose compose compose";
@ -92,6 +96,7 @@
"card card" "card card"
"media-grp media-grp" "media-grp media-grp"
"media media" "media media"
"poll poll"
"details details" "details details"
"toolbar toolbar" "toolbar toolbar"
"compose compose"; "compose compose";
@ -119,6 +124,7 @@
import StatusSpoiler from './StatusSpoiler.html' import StatusSpoiler from './StatusSpoiler.html'
import StatusComposeBox from './StatusComposeBox.html' import StatusComposeBox from './StatusComposeBox.html'
import StatusMentions from './StatusMentions.html' import StatusMentions from './StatusMentions.html'
import StatusPoll from './StatusPoll.html'
import Shortcut from '../shortcut/Shortcut.html' import Shortcut from '../shortcut/Shortcut.html'
import { store } from '../../_store/store' import { store } from '../../_store/store'
import { goto } from '../../../../__sapper__/client' import { goto } from '../../../../__sapper__/client'
@ -170,6 +176,7 @@
StatusMediaAttachments, StatusMediaAttachments,
StatusContent, StatusContent,
StatusCard, StatusCard,
StatusPoll,
StatusSpoiler, StatusSpoiler,
StatusComposeBox, StatusComposeBox,
StatusMentions, StatusMentions,
@ -261,6 +268,9 @@
originalStatus.card && originalStatus.card &&
originalStatus.card.title originalStatus.card.title
), ),
showPoll: ({ originalStatus, isStatusInNotification }) => (
!isStatusInNotification && originalStatus.poll
),
showMedia: ({ originalStatus, isStatusInNotification }) => ( showMedia: ({ originalStatus, isStatusInNotification }) => (
!isStatusInNotification && !isStatusInNotification &&
originalStatus.media_attachments && originalStatus.media_attachments &&

View file

@ -0,0 +1,42 @@
<div class="poll" >
{#each options as option}
<div class="option">
<div>{option.title} ({option.share}%)</div>
<svg height="2px" width="100%">
<line x1="0" y1="0" x2="{option.share}%" y2="0" />
</svg>
</div>
{/each}
</div>
<style>
.poll {
grid-area: poll;
margin: 10px 10px 10px 5px;
word-wrap: break-word;
white-space: pre-wrap;
}
.option {
display: flex;
flex-direction: column;
stroke: var(--svg-fill);
stroke-width:2;
}
.option:not(:last-child) {
margin-bottom: 3px;
}
</style>
<script>
export default {
computed: {
poll: ({ originalStatus }) => originalStatus.poll,
options: ({ poll }) => poll.options.map(({ title, votes_count: votesCount }) => ({
title,
share: poll.votes_count ? Math.round(votesCount / poll.votes_count * 100) : 0
}))
}
}
</script>