From 709b17460fe9d7a8ab45b21c37063b3dbe5ac5e7 Mon Sep 17 00:00:00 2001 From: Chris <76159444+hunchr@users.noreply.github.com> Date: Tue, 5 Nov 2024 08:03:38 +0000 Subject: [PATCH] Format JavaScript (#4) --- .gitignore | 16 +-- .prettierrc | 13 +++ .rspec | 3 - README.md | 2 - .../javascripts/hotsheet/channels/consumer.js | 4 +- .../hotsheet/channels/inline_edit_channel.js | 4 +- .../hotsheet/controllers/application.js | 7 +- .../editable_attribute_controller.js | 95 +++++++++--------- app/controllers/hotsheet/pages_controller.rb | 10 +- spec/dummy/public/favicon.ico | Bin 0 -> 4286 bytes 10 files changed, 71 insertions(+), 83 deletions(-) create mode 100644 .prettierrc delete mode 100644 .rspec create mode 100644 spec/dummy/public/favicon.ico diff --git a/.gitignore b/.gitignore index a15579c..b4cf798 100644 --- a/.gitignore +++ b/.gitignore @@ -1,17 +1,3 @@ -/.bundle/ -/.yardoc -/_yardoc/ -/coverage/ -/doc/ -/pkg/ -/spec/reports/ -/tmp/ -/log/*.log -/test/dummy/db/*.sqlite3 -/test/dummy/db/*.sqlite3-* -/test/dummy/log/*.log -/test/dummy/storage/ -/test/dummy/tmp/ +/.bundle /Gemfile.lock -.rspec_status diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..941e555 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,13 @@ +{ + "arrowParens": "always", + "bracketSameLine": true, + "bracketSpacing": true, + "endOfLine": "lf", + "printWidth": 80, + "quoteProps": "consistent", + "semi": false, + "singleQuote": false, + "tabWidth": 2, + "trailingComma": "all", + "useTabs": false +} diff --git a/.rspec b/.rspec deleted file mode 100644 index 34c5164..0000000 --- a/.rspec +++ /dev/null @@ -1,3 +0,0 @@ ---format documentation ---color ---require spec_helper diff --git a/README.md b/README.md index 968eceb..6ece777 100644 --- a/README.md +++ b/README.md @@ -44,8 +44,6 @@ end Finally, you will need to create a configuration file to specify which models you want to manage with Hotsheet. - - ## TODO - Support live updates (show when someone has the intention to edit a resource) via ActionCable diff --git a/app/assets/javascripts/hotsheet/channels/consumer.js b/app/assets/javascripts/hotsheet/channels/consumer.js index 8e1cdae..083c449 100644 --- a/app/assets/javascripts/hotsheet/channels/consumer.js +++ b/app/assets/javascripts/hotsheet/channels/consumer.js @@ -1,3 +1,3 @@ -import { createConsumer } from "https://unpkg.com/@rails/actioncable@7.1.3-4/app/assets/javascripts/actioncable.esm.js"; +import { createConsumer } from "https://unpkg.com/@rails/actioncable@7.1.3-4/app/assets/javascripts/actioncable.esm.js" -export default createConsumer(); +export default createConsumer() diff --git a/app/assets/javascripts/hotsheet/channels/inline_edit_channel.js b/app/assets/javascripts/hotsheet/channels/inline_edit_channel.js index dbd57e5..8e95df7 100644 --- a/app/assets/javascripts/hotsheet/channels/inline_edit_channel.js +++ b/app/assets/javascripts/hotsheet/channels/inline_edit_channel.js @@ -1,3 +1,3 @@ -import consumer from "channels/consumer"; +import consumer from "channels/consumer" -consumer.subscriptions.create({ channel: "InlineEditChannel" }); +consumer.subscriptions.create({ channel: "InlineEditChannel" }) diff --git a/app/assets/javascripts/hotsheet/controllers/application.js b/app/assets/javascripts/hotsheet/controllers/application.js index 3492322..78e15a7 100644 --- a/app/assets/javascripts/hotsheet/controllers/application.js +++ b/app/assets/javascripts/hotsheet/controllers/application.js @@ -1,7 +1,6 @@ -import { Application } from "https://unpkg.com/@hotwired/stimulus/dist/stimulus.js"; +import { Application } from "https://unpkg.com/@hotwired/stimulus/dist/stimulus.js" +import EditableAttributeController from "./controllers/editable_attribute_controller" -import EditableAttributeController from "./controllers/editable_attribute_controller.js"; - -window.Stimulus = Application.start(); +window.Stimulus = Application.start() Stimulus.register("editable-attribute", EditableAttributeController) diff --git a/app/assets/javascripts/hotsheet/controllers/editable_attribute_controller.js b/app/assets/javascripts/hotsheet/controllers/editable_attribute_controller.js index c82f720..ab27b20 100644 --- a/app/assets/javascripts/hotsheet/controllers/editable_attribute_controller.js +++ b/app/assets/javascripts/hotsheet/controllers/editable_attribute_controller.js @@ -1,56 +1,51 @@ -import { - Controller, -} from "https://unpkg.com/@hotwired/stimulus/dist/stimulus.js"; +import { Controller } from "https://unpkg.com/@hotwired/stimulus/dist/stimulus.js" export default class extends Controller { - static values = { - broadcastUrl: String, - resourceName: String, - resourceId: Number - }; - - static targets = [ - 'readonlyAttribute', - 'attributeForm', - 'attributeFormInput' - ]; - - displayInputField() { - this.broadcastEditIntent(); - this.readonlyAttributeTarget.style.display = 'none'; - this.attributeFormTarget.style.display = 'block'; - this.attributeFormInputTarget.focus(); + static values = { + broadcastUrl: String, + resourceName: String, + resourceId: Number, + } + + static targets = ["readonlyAttribute", "attributeForm", "attributeFormInput"] + + displayInputField() { + // this.broadcastEditIntent() + this.readonlyAttributeTarget.style.display = "none" + this.attributeFormTarget.style.display = "block" + this.attributeFormInputTarget.focus() + } + + broadcastEditIntent() { + const headers = { + "Content-Type": "application/json", + "X-CSRF-Token": document.querySelector("meta[name=csrf-token]").content, } - - broadcastEditIntent() { - const headers = new Headers(); - headers.append("Content-Type", "application/json"); - headers.append("X-CSRF-Token", document.querySelector("meta[name=csrf-token]").content); - - const data = JSON.stringify({ - broadcast: { - resource_name: this.resourceNameValue, - resource_id: this.resourceIdValue - } - }); - - fetch(this.broadcastUrlValue, { method: "POST", headers: headers, body: data }).then(); + const body = JSON.stringify({ + broadcast: { + resource_name: this.resourceNameValue, + resource_id: this.resourceIdValue, + }, + }) + + fetch(this.broadcastUrlValue, { method: "POST", headers, body }) + } + + submitForm(event) { + // Prevent standard submission triggered by Enter press + event.preventDefault() + + const previousValue = this.readonlyAttributeTarget.innerText.trim() + const newValue = this.attributeFormInputTarget.value + + if (previousValue && previousValue === newValue) { + this.readonlyAttributeTarget.style.display = "block" + this.attributeFormTarget.style.display = "none" + return } - submitForm(event) { - // Prevent standard submission triggered by Enter press - event.preventDefault(); - - const previousValue = this.readonlyAttributeTarget.innerText.trim(); - const newValue = this.attributeFormInputTarget.value; - if (previousValue && previousValue === newValue) { - this.readonlyAttributeTarget.style.display = 'block'; - this.attributeFormTarget.style.display = 'none'; - return; - } - - // It's important to use requestSubmit() instead of simply submit() as the latter will circumvent the - // Turbo mechanism, causing the PATCH request to be submitted as HTML instead of TURBO_STREAM - this.attributeFormInputTarget.form.requestSubmit(); - } + // It's important to use requestSubmit() instead of simply submit() as the latter will circumvent the + // Turbo mechanism, causing the PATCH request to be submitted as HTML instead of TURBO_STREAM + this.attributeFormInputTarget.form.requestSubmit() + } } diff --git a/app/controllers/hotsheet/pages_controller.rb b/app/controllers/hotsheet/pages_controller.rb index b68ef21..585e40b 100644 --- a/app/controllers/hotsheet/pages_controller.rb +++ b/app/controllers/hotsheet/pages_controller.rb @@ -7,10 +7,10 @@ def index end def broadcast_edit_intent - ActionCable.server.broadcast(InlineEditChannel::STREAM_NAME, { - resource_name: broadcast_params[:resource_name], - resource_id: broadcast_params[:resource_id] - }) + ActionCable.server.broadcast InlineEditChannel::STREAM_NAME, { + resource_name: broadcast_params[:resource_name], + resource_id: broadcast_params[:resource_id] + } end def update # rubocop:disable Metrics/AbcSize @@ -29,7 +29,7 @@ def update # rubocop:disable Metrics/AbcSize private def broadcast_params - params.require(:broadcast).permit(:resource_name, :resource_id) + params.require(:broadcast).permit :resource_name, :resource_id end def model_params diff --git a/spec/dummy/public/favicon.ico b/spec/dummy/public/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..2e8667ca3a165ad7381ff751dd425fc1b5393c42 GIT binary patch literal 4286 zcmc(jJx&8L5QQfMi4rOb8d3s1KOJx%I0I?n0^|r3aEHJtAO%Sa6@mtdpXGgKX9ZCd zoXr{=J?z*s@68hLc#K&~Kb?;8+b&kjR?Tcf(3Bkr%!j76*;^r(Vo}%>j)W`WPIwkR zN-!P>tQ`y3;xoHkq-;@B0=g`w~!XkjX_!L}#h3rEHJ_W;{~HT9>$qo9dez!wg< zO5SM^xJ|Jw`y1g?sH^RMaKHuUlo))iIFudVulqOE!wL6<7<{hS(fVxyZGQ&1(HM&% zeC9j4PN?lMpi%Az_CnBJP|rSbo76p8XuAHM#t;9fj~1Hf^M3Mvr+(&fel*eE5{4P{ z?@Mj+WlUZhkAL3JXnH=Mm#eP-rD8~tYhvT^b1c@rX*)kdo92z>^Yc5_zG*x3`5QFN z8_S1w?)^v26dP~TcD#SN^H1*loBRCX49t1{qW|CZ$62W$r}PiD&seyMNP?&@C$ Uz-l)4?~7|BPPoxP3r)1Y0N0<