Skip to content

Commit

Permalink
Add request.js in order to process turbo-stream responses
Browse files Browse the repository at this point in the history
  • Loading branch information
luciajanikova committed Sep 21, 2023
1 parent db377b0 commit c0c31f6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
15 changes: 7 additions & 8 deletions app/javascript/controllers/autogram_controller.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Controller } from "@hotwired/stimulus"
import { get, patch } from '@rails/request.js'

export default class extends Controller {

async sign(messageObjectId, messageId, that, batchId = null) {
return new Promise((resolve, reject) => {
fetch(`/messages/${messageId}/message_objects/${messageObjectId}/signing_data.json`)
get(`/messages/${messageId}/message_objects/${messageObjectId}/signing_data.json`)
.then(function (response) {
return response.json();
return response.json;
})
.then(async function (messageObjectData) {
let payloadMimeType = `${messageObjectData.mime_type};base64`;
Expand Down Expand Up @@ -79,17 +80,15 @@ export default class extends Controller {
const authenticityToken = this.data.get("authenticityToken");

return new Promise((resolve, reject) => {
fetch(`/messages/${messageId}/message_objects/${messageObjectId}`, {
method: "PATCH",
headers: {"Content-Type": "application/json"},
patch(`/messages/${messageId}/message_objects/${messageObjectId}`, {
body: JSON.stringify({
authenticity_token: authenticityToken,
name: signedFileName,
mimetype: signedFileMimeType,
is_signed: true,
content: signedContent,
format: "turbo_stream"
})
content: signedContent
}),
responseKind: "turbo-stream"
}).then(function () {
resolve();
})
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"dependencies": {
"@hotwired/stimulus": "^3.2.1",
"@hotwired/turbo-rails": "^7.3.0",
"@rails/request.js": "^0.0.8",
"esbuild": "^0.17.19",
"tailwindcss-stimulus-components": "^3.0.4"
},
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c0c31f6

Please sign in to comment.