add ReactionController to disable button during submits

This commit is contained in:
Andreas Nedbal 2023-12-20 23:53:22 +01:00 committed by Andreas Nedbal
parent 855d0fa867
commit 950443bbb8
4 changed files with 37 additions and 8 deletions

View File

@ -0,0 +1,15 @@
import { Controller } from '@hotwired/stimulus';
export default class extends Controller {
static targets = ['button'];
declare readonly buttonTarget: HTMLButtonElement;
enable(): void {
this.buttonTarget.disabled = false;
}
disable(): void {
this.buttonTarget.disabled = true;
}
}

View File

@ -16,6 +16,7 @@ import NavigationController from "retrospring/controllers/navigation_controller"
import ShareController from "retrospring/controllers/share_controller";
import ClipboardController from "retrospring/controllers/clipboard_controller";
import QuestionboxFocusController from "retrospring/controllers/questionbox_focus_controller";
import ReactionController from "retrospring/controllers/reaction_controller";
/**
* This module sets up Stimulus and our controllers
@ -43,4 +44,5 @@ export default function (): void {
window['Stimulus'].register('share', ShareController);
window['Stimulus'].register('clipboard', ClipboardController);
window['Stimulus'].register('questionbox-focus', QuestionboxFocusController);
window['Stimulus'].register('reaction', ReactionController);
}

View File

@ -1,13 +1,19 @@
- if type == "Answer"
= button_to create_reactions_path(id: target.id, username: target.user.screen_name),
form: { class: "d-inline-block", id: "reaction-#{type}-#{target.id}" },
class: "btn btn-link answerbox__action smile" do
form: { class: "d-inline-block",
id: "reaction-#{type}-#{target.id}",
data: { controller: :reaction, action: "turbo:submit-start->reaction#disable turbo:submit-end->reaction#enable" } },
class: "btn btn-link answerbox__action smile",
data: { reaction_target: :button } do
%i.fa.fa-fw.fa-smile-o
%span= target.smile_count
- if type == "Comment"
= button_to create_comment_reactions_path(id: target.id, username: target.user.screen_name),
form: { class: "d-inline-block", id: "reaction-#{type}-#{target.id}" },
class: "btn btn-link answerbox__action smile" do
form: { class: "d-inline-block",
id: "reaction-#{type}-#{target.id}",
data: { controller: :reaction, action: "turbo:submit-start->reaction#disable turbo:submit-end->reaction#enable" } },
class: "btn btn-link answerbox__action smile",
data: { reaction_target: :button } do
%i.fa.fa-fw.fa-smile-o
%span= target.smile_count

View File

@ -1,15 +1,21 @@
- if type == "Answer"
= button_to destroy_reactions_path(id: target.id, username: target.user.screen_name),
method: :delete,
form: { class: "d-inline-block", id: "reaction-#{type}-#{target.id}" },
class: "btn btn-link answerbox__action unsmile" do
form: { class: "d-inline-block",
id: "reaction-#{type}-#{target.id}",
data: { controller: :reaction, action: "turbo:submit-start->reaction#disable turbo:submit-end->reaction#enable" } },
class: "btn btn-link answerbox__action unsmile",
data: { reaction_target: :button } do
%i.fa.fa-fw.fa-smile-o
%span= target.smile_count
- if type == "Comment"
= button_to destroy_comment_reactions_path(id: target.id, username: target.user.screen_name),
method: :delete,
form: { class: "d-inline-block", id: "reaction-#{type}-#{target.id}" },
class: "btn btn-link answerbox__action unsmile" do
form: { class: "d-inline-block",
id: "reaction-#{type}-#{target.id}",
data: { controller: :reaction, action: "turbo:submit-start->reaction#disable turbo:submit-end->reaction#enable" } },
class: "btn btn-link answerbox__action unsmile",
data: { reaction_target: :button } do
%i.fa.fa-fw.fa-smile-o
%span= target.smile_count