Skip to content
Snippets Groups Projects
Commit 1ef34e24 authored by Audrey Hamelers's avatar Audrey Hamelers
Browse files

fix HTMLPreview/annotator state leak

parent 24ab781d
No related branches found
No related tags found
2 merge requests!98Dev,!97Shared data model
...@@ -25,26 +25,28 @@ const Annotator = BaseComponent => ...@@ -25,26 +25,28 @@ const Annotator = BaseComponent =>
} }
} }
async start(elm, options) { async start(elm, options) {
const app = new annotator.App() if (this.elem) {
await app const app = new annotator.App()
.include(annotator.ui.main, { element: elm }) await app
.include(annotator.storage.http, { .include(annotator.ui.main, { element: elm })
prefix: '/annotations', .include(annotator.storage.http, {
urls: { prefix: '/annotations',
create: '/', urls: {
update: `/{id}`, create: '/',
destroy: `/{id}`, update: `/{id}`,
search: `/file/${options.file_id}`, destroy: `/{id}`,
}, search: `/file/${options.file_id}`,
}) },
.include(this.addHooks, options) })
.start() .include(this.addHooks, options)
await app.annotations.store.setHeader( .start()
'Authorization', await app.annotations.store.setHeader(
`Bearer ${window.localStorage.getItem('token')}`, 'Authorization',
) `Bearer ${window.localStorage.getItem('token')}`,
await app.annotations.load() )
this.setState({ app }) await app.annotations.load()
this.setState({ app })
}
} }
addHooks = options => ({ addHooks = options => ({
annotationsLoaded: annotations => {}, annotationsLoaded: annotations => {},
......
...@@ -10,21 +10,28 @@ class HTMLPreview extends React.Component { ...@@ -10,21 +10,28 @@ class HTMLPreview extends React.Component {
try { try {
const response = await fetch(this.props.url) const response = await fetch(this.props.url)
const html = await response.text() const html = await response.text()
await this.setState({ html }) if (this.div) {
await this.setState({ html })
}
} catch (error) { } catch (error) {
this.setState({ html: `'No Web Preview generated. Error: ${error}` }) if (this.div) {
this.setState({ html: `'No Web Preview generated. Error: ${error}` })
}
} }
} }
componentDidUpdate(prevProps, prevState) { componentDidUpdate(prevProps, prevState) {
if (this.props.loaded) { if (this.props.loaded && this.div) {
if (prevState.html === null && this.state.html !== null) { if (prevState.html === null && this.state.html !== null) {
this.props.loaded(true) this.props.loaded(true)
} }
} }
} }
setRef = div => {
this.div = div
}
render() { render() {
return ( return (
<div id="html-preview"> <div id="html-preview" ref={this.setRef}>
{ReactHtmlParser(this.state.html, { {ReactHtmlParser(this.state.html, {
transform: function transform(node, index) { transform: function transform(node, index) {
if ( if (
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment