-
-
Notifications
You must be signed in to change notification settings - Fork 39
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 #1417 from Retrospring/feature/turbo-subscriptions
Move subscription functionality to Turbo Streams
- Loading branch information
Showing
11 changed files
with
66 additions
and
133 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,41 @@ | ||
# frozen_string_literal: true | ||
|
||
class SubscriptionsController < ApplicationController | ||
include TurboStreamable | ||
|
||
before_action :authenticate_user! | ||
|
||
turbo_stream_actions :create, :destroy | ||
|
||
def create | ||
answer = Answer.find(params[:answer]) | ||
result = Subscription.subscribe(current_user, answer) | ||
|
||
respond_to do |format| | ||
format.turbo_stream do | ||
render turbo_stream: [ | ||
turbo_stream.replace("subscription-#{answer.id}", partial: "subscriptions/destroy", locals: { answer: }), | ||
render_toast(t(result.present? ? ".success" : ".error"), result.present?) | ||
] | ||
end | ||
|
||
format.html { redirect_to answer_path(username: answer.user.screen_name, id: answer.id) } | ||
end | ||
end | ||
|
||
def destroy | ||
answer = Answer.find(params[:answer]) | ||
result = Subscription.unsubscribe(current_user, answer) | ||
|
||
respond_to do |format| | ||
format.turbo_stream do | ||
render turbo_stream: [ | ||
turbo_stream.replace("subscription-#{answer.id}", partial: "subscriptions/create", locals: { answer: }), | ||
render_toast(t(result.present? ? ".success" : ".error"), result.present?) | ||
] | ||
end | ||
|
||
format.html { redirect_to answer_path(username: answer.user.screen_name, id: answer.id) } | ||
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
44 changes: 0 additions & 44 deletions
44
app/javascript/retrospring/features/answerbox/subscribe.ts
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
= button_to subscriptions_path(answer: answer.id), class: "dropdown-item", form: { id: "subscription-#{answer.id}" } do | ||
%i.fa.fa-fw.fa-bell | ||
= t("voc.subscribe") |
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,3 @@ | ||
= button_to subscriptions_path(answer: answer.id), method: :delete, class: "dropdown-item", form: { id: "subscription-#{answer.id}" } do | ||
%i.fa.fa-fw.fa-bell-slash | ||
= t("voc.unsubscribe") |
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
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