Skip to content

Commit

Permalink
fix(template): fix js template (#277)
Browse files Browse the repository at this point in the history
Co-authored-by: Bibiana Sebestianova <[email protected]>
  • Loading branch information
eunjae-lee and BibiSebi authored Sep 25, 2023
1 parent d9bdb1b commit 46ef2e9
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions packages/cli/templates/js/src/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createFieldPlugin } from '@storyblok/field-plugin'
import { updateData, renderFieldPlugin } from './components'
import { renderFieldPlugin, updateData } from './components'
import './style.css'

let rootElement = document.querySelector('#app')
Expand All @@ -14,21 +14,24 @@ rootElement.innerHTML = `<span>Loading...</span>`
let previousType = 'loading'

// Establish communication with the Visual Editor
createFieldPlugin((response) => {
// Re-render the button element when messages
const { data, actions, type } = response
// #region DELETE THIS BOILERPLATE
if (previousType === 'loading') {
previousType = type
if (type === 'error') {
rootElement.innerHTML = `<span>Error</span>`
} else if (type === 'loaded') {
renderFieldPlugin({ data, actions, container: rootElement })
createFieldPlugin({
parseContent: (content) => (typeof content === 'number' ? content : 0),
onUpdateState: (response) => {
// Re-render the button element when messages
const { data, actions, type } = response
// #region DELETE THIS BOILERPLATE
if (previousType === 'loading') {
previousType = type
if (type === 'error') {
rootElement.innerHTML = `<span>Error</span>`
} else if (type === 'loaded') {
renderFieldPlugin({ data, actions, container: rootElement })
}
} else {
updateData({ data, container: rootElement })
}
} else {
updateData({ data, container: rootElement })
}
// #endregion
// #endregion
},
})

// This error replaces another error which message is harder to understand and impossible to avoid util the issue https://github.com/storyblok/field-plugin/issues/107 has been resolved.
Expand Down

1 comment on commit 46ef2e9

@vercel
Copy link

@vercel vercel bot commented on 46ef2e9 Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.