Skip to content

Commit

Permalink
Fix an issue where the template data input didn't reset properly
Browse files Browse the repository at this point in the history
Signed-off-by: Axel Boberg <[email protected]>
  • Loading branch information
axelboberg committed Mar 18, 2024
1 parent dbf8568 commit 18e5618
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions plugins/caspar/app/components/Monaco/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const CUSTOM_LANGUAGE_NAME = 'bridgeLang'
*
* @see https://microsoft.github.io/monaco-editor/typedoc/index.html
*/
export const Monaco = ({ defaultValue = '', value = '', onChange = () => {} }) => {
export const Monaco = ({ defaultValue = '', value = '', reset, onChange = () => {} }) => {
const elRef = React.useRef()
const modelRef = React.useRef()

Expand Down Expand Up @@ -158,10 +158,11 @@ export const Monaco = ({ defaultValue = '', value = '', onChange = () => {} }) =
return
}
if (value == null) {
modelRef.current.setValue(defaultValue)
return
}
modelRef.current.setValue(value)
}, [value])
}, [value, defaultValue, reset])

return (
<div ref={elRef} className='Monaco' />
Expand Down
4 changes: 4 additions & 0 deletions plugins/caspar/app/views/InspectorTemplate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const InspectorTemplate = () => {
const [state] = React.useContext(SharedContext)
const [selection, setSelection] = React.useState([])

const [id, setId] = React.useState()
const [value, setValue] = React.useState()

const selectionRef = React.useRef([])
Expand All @@ -29,6 +30,7 @@ export const InspectorTemplate = () => {
React.useEffect(() => {
const items = selection.map(id => state?.items?.[id])
const value = items?.[0]?.data?.caspar?.templateDataString
setId(items?.[0]?.id)
setValue(value)
}, [JSON.stringify(selection)])

Expand Down Expand Up @@ -59,7 +61,9 @@ export const InspectorTemplate = () => {
return (
<div className='View--spread'>
<Monaco
reset={id}
value={value ?? ['{', '', '}'].join('\n')}
defaultValue={['{', '', '}'].join('\n')}
onChange={newValue => handleChange(newValue)}
/>
</div>
Expand Down

0 comments on commit 18e5618

Please sign in to comment.