Skip to content

Commit

Permalink
Format javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
hunchr committed Nov 5, 2024
1 parent 886a83b commit 59d64c7
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 83 deletions.
16 changes: 1 addition & 15 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 0 additions & 3 deletions .rspec

This file was deleted.

2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/hotsheet/channels/consumer.js
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import consumer from "channels/consumer";
import consumer from "channels/consumer"

consumer.subscriptions.create({ channel: "InlineEditChannel" });
consumer.subscriptions.create({ channel: "InlineEditChannel" })
7 changes: 3 additions & 4 deletions app/assets/javascripts/hotsheet/controllers/application.js
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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()
}
}
10 changes: 5 additions & 5 deletions app/controllers/hotsheet/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Binary file added spec/dummy/public/favicon.ico
Binary file not shown.

0 comments on commit 59d64c7

Please sign in to comment.