From 8f0ae5171d2cb853ff1803414db54a8a35a4d5a0 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sun, 5 Feb 2023 20:18:51 +0100 Subject: [PATCH] Appease the dog overlords --- app/controllers/ajax/answer_controller.rb | 27 +++++++++---------- .../controllers/inbox_sharing_controller.ts | 4 +-- app/views/inbox/_entry.html.haml | 5 ++-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/app/controllers/ajax/answer_controller.rb b/app/controllers/ajax/answer_controller.rb index 84d0607b..859ae794 100644 --- a/app/controllers/ajax/answer_controller.rb +++ b/app/controllers/ajax/answer_controller.rb @@ -1,4 +1,6 @@ -require 'cgi' +# frozen_string_literal: true + +require "cgi" class Ajax::AnswerController < AjaxController include SocialHelper::TwitterMethods @@ -9,7 +11,7 @@ class Ajax::AnswerController < AjaxController params.require :answer params.require :inbox - inbox = (params[:inbox] == 'true') + inbox = (params[:inbox] == "true") if inbox inbox_entry = Inbox.find(params[:id]) @@ -35,7 +37,6 @@ class Ajax::AnswerController < AjaxController current_user.answer question, params[:answer] end - @response[:status] = :okay @response[:message] = t(".success") @response[:success] = true @@ -43,16 +44,16 @@ class Ajax::AnswerController < AjaxController if current_user.sharing_enabled @response[:sharing] = { twitter: twitter_share_url(answer), - tumblr: tumblr_share_url(answer), - custom: CGI.escape(prepare_tweet(answer)) + tumblr: tumblr_share_url(answer), + custom: CGI.escape(prepare_tweet(answer)) } end - unless inbox - # this assign is needed because shared/_answerbox relies on it, I think - @question = 1 - @response[:render] = render_to_string(partial: 'answerbox', locals: { a: answer, show_question: false }) - end + return if inbox + + # this assign is needed because shared/_answerbox relies on it, I think + @question = 1 + @response[:render] = render_to_string(partial: "answerbox", locals: { a: answer, show_question: false }) end def destroy @@ -60,15 +61,13 @@ class Ajax::AnswerController < AjaxController answer = Answer.find(params[:answer]) - unless (current_user == answer.user) or (privileged? answer.user) + unless (current_user == answer.user) || (privileged? answer.user) @response[:status] = :nopriv @response[:message] = t(".nopriv") return end - if answer.user == current_user - Inbox.create!(user: answer.user, question: answer.question, new: true, returning: true) - end + Inbox.create!(user: answer.user, question: answer.question, new: true, returning: true) if answer.user == current_user answer.destroy @response[:status] = :okay diff --git a/app/javascript/retrospring/controllers/inbox_sharing_controller.ts b/app/javascript/retrospring/controllers/inbox_sharing_controller.ts index bec8dd0e..48f0a905 100644 --- a/app/javascript/retrospring/controllers/inbox_sharing_controller.ts +++ b/app/javascript/retrospring/controllers/inbox_sharing_controller.ts @@ -16,7 +16,7 @@ export default class extends Controller { declare readonly configValue: Record; declare readonly autoCloseValue: boolean; - connect() { + connect(): void { if (this.autoCloseValue) { this.twitterTarget.addEventListener('click', () => this.close()); this.tumblrTarget.addEventListener('click', () => this.close()); @@ -27,7 +27,7 @@ export default class extends Controller { } } - configValueChanged(value): void { + configValueChanged(value: Record): void { if (Object.keys(value).length === 0) { return; } diff --git a/app/views/inbox/_entry.html.haml b/app/views/inbox/_entry.html.haml index c696c29b..29fcfaa7 100644 --- a/app/views/inbox/_entry.html.haml +++ b/app/views/inbox/_entry.html.haml @@ -36,10 +36,11 @@ %p.format-help.ms-auto.align-self-center.mt-2.mt-sm-0.text-center = render "shared/format_link" - if current_user.sharing_enabled - .inbox-entry__sharing.text-center.p-2.justify-content-center.d-none{ data: { controller: "inbox-sharing", inbox_sharing_config_value: "{}", inbox_sharing_auto_close_value: current_user.sharing_autoclose.to_s }} + .inbox-entry__sharing.text-center.p-2.justify-content-center.d-none{ + data: { controller: "inbox-sharing", inbox_sharing_config_value: "{}", inbox_sharing_auto_close_value: current_user.sharing_autoclose.to_s } } %button.btn-close.inbox-entry__close{ data: { action: "inbox-sharing#close" } } %span.visually-hidden= t("voc.close") - %div.align-self-center + .align-self-center %p.fs-3.fw-bold= t(".sharing.heading") %p %a.btn.btn-primary{ href: "https://twitter.com/intent/tweet?text=", data: { inbox_sharing_target: "twitter" }, target: "_blank" }