From e395b65fc17547c5c8a416ae7033e1d2628c0bb1 Mon Sep 17 00:00:00 2001 From: Ricardo Hernandez-Montoya Date: Mon, 8 May 2017 12:27:36 +0200 Subject: [PATCH] fixed imaged widget, load image by id --- src/components/widget-image.js | 40 +++++++++++++++------------------- src/config.js | 6 +++++ 2 files changed, 24 insertions(+), 22 deletions(-) create mode 100644 src/config.js diff --git a/src/components/widget-image.js b/src/components/widget-image.js index aeb9642..2bbba8c 100644 --- a/src/components/widget-image.js +++ b/src/components/widget-image.js @@ -21,37 +21,33 @@ import React, { Component } from 'react'; -const API_URL = 'http://localhost:4000/'; +import AppDispatcher from '../app-dispatcher'; +import config from '../config'; class WidgetImage extends Component { - constructor(props) { - super(props); - - this.state = { - file: null - }; - } componentWillReceiveProps(nextProps) { - // check if file is set - if (nextProps.widget.file == null) { - this.setState({ file: null }); - return; - } - // get file by id - nextProps.files.forEach(file => { - if (file._id === nextProps.widget.file) { - this.setState({ file: file }); - } - }); + // Query the image referenced by the widget (public request, no token required) + let widgetFile = nextProps.widget.file; + if (widgetFile && !nextProps.files.find( file => file._id === widgetFile ) ) { + + AppDispatcher.dispatch({ + type: 'files/start-load', + data: widgetFile + }); + + } } render() { + + let file = this.props.files.find( (file) => file._id === this.props.widget.file ); + return ( -
- {this.state.file && - {this.state.file.name} +
+ {file && + {file.name} e.preventDefault() } /> }
); diff --git a/src/config.js b/src/config.js new file mode 100644 index 0000000..4ade8ce --- /dev/null +++ b/src/config.js @@ -0,0 +1,6 @@ + +const config = { + publicPathBase: 'public/' +} + +export default config \ No newline at end of file