Support displaying polls in Admin UI (#35933)

Co-authored-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
Emelia Smith 2025-09-01 16:59:03 +02:00 committed by GitHub
parent 6f8187e595
commit 15401e6988
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 43 additions and 5 deletions

View File

@ -1873,7 +1873,7 @@ a.sparkline {
font-size: 15px;
line-height: 22px;
li {
> li {
counter-increment: step 1;
padding-inline-start: 2.5rem;
padding-bottom: 8px;

View File

@ -102,7 +102,8 @@
cursor: pointer;
}
&.editable {
&.editable,
&.disabled {
align-items: center;
overflow: visible;
}
@ -160,7 +161,8 @@
}
}
&__option.editable &__input {
&__option.editable &__input,
&__option.disabled &__input {
&:active,
&:focus,
&:hover {

View File

@ -43,16 +43,36 @@ class StatusEdit < ApplicationRecord
scope :ordered, -> { order(id: :asc) }
delegate :local?, :application, :edited?, :edited_at,
:discarded?, :visibility, :language, to: :status
:discarded?, :reply?, :visibility, :language, to: :status
def with_media?
ordered_media_attachments.any?
end
def with_poll?
poll_options.present?
end
def poll
return @poll if defined?(@poll)
return @poll = nil if poll_options.blank?
@poll = Poll.new({
options: poll_options,
account_id: account_id,
status_id: status_id,
})
end
alias preloadable_poll poll
def emojis
return @emojis if defined?(@emojis)
@emojis = CustomEmoji.from_text([spoiler_text, text].join(' '), status.account.domain)
fields = [spoiler_text, text]
fields += preloadable_poll.options unless preloadable_poll.nil?
@emojis = CustomEmoji.from_text(fields.join(' '), status.account.domain)
end
def ordered_media_attachments

View File

@ -1,3 +1,18 @@
- if status.with_poll?
.poll
%ul
- status.preloadable_poll.options.each_with_index do |option, _index|
%li
%label.poll__option.disabled<>
- if status.preloadable_poll.multiple?
%span.poll__input.checkbox{ role: 'checkbox', 'aria-label': option }
- else
%span.poll__input{ role: 'radio', 'aria-label': option }
%span.poll__option__text
= prerender_custom_emojis(html_aware_format(option, status.local?, multiline: false), status.emojis)
%button.button.button-secondary{ disabled: true }
= t('polls.vote')
- if status.with_media?
- if status.ordered_media_attachments.first.video?
= render_video_component(status, visible: false)

View File

@ -1740,6 +1740,7 @@ en:
self_vote: You cannot vote in your own polls
too_few_options: must have more than one item
too_many_options: can't contain more than %{max} items
vote: Vote
posting_defaults:
explanation: These settings will be used as defaults when you create new posts, but you can edit them per post within the composer.
preferences: