-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #307 from joyofrails/feat/revisit-poll-vote-turbo-…
…streams In which I reinstate turbo_stream#replace for polls
- Loading branch information
Showing
9 changed files
with
100 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module Share | ||
module Polls | ||
class Ballot < ApplicationComponent | ||
include Phlex::Rails::Helpers::ButtonTo | ||
include Phlex::Rails::Helpers::DOMID | ||
include Phlex::Rails::Helpers::Pluralize | ||
|
||
attr_reader :poll, :question | ||
|
||
def initialize(poll, question, voted: false) | ||
@poll = poll | ||
@question = question | ||
@voted = voted | ||
end | ||
|
||
def view_template | ||
div id: dom_id(question, :ballot), class: "question flex flex-col gap-2" do | ||
p { question.body } | ||
|
||
question.answers.ordered.each do |answer| | ||
div id: dom_id(answer) do | ||
button_to answer.body, | ||
share_poll_votes_path(poll, answer_id: answer.id), | ||
class: "button transparent slim" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module Share | ||
module Polls | ||
class QuestionComponent < ApplicationComponent | ||
include Phlex::Rails::Helpers::TurboFrameTag | ||
include Phlex::Rails::Helpers::TurboStreamFrom | ||
|
||
attr_reader :poll, :question | ||
|
||
def initialize(poll, question, voted: false) | ||
@poll = poll | ||
@question = question | ||
@voted = voted | ||
end | ||
|
||
def view_template | ||
turbo_frame_tag question, class: "question flex flex-col gap-2" do | ||
if voted? | ||
render Share::Polls::Results.new(poll, question) | ||
else | ||
render Share::Polls::Ballot.new(poll, question) | ||
end | ||
end | ||
turbo_stream_from question | ||
end | ||
|
||
private | ||
|
||
def voted? = !!@voted | ||
end | ||
end | ||
end |
47 changes: 10 additions & 37 deletions
47
app/views/share/polls/question.rb → app/views/share/polls/results.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters