diff options
| author | Yuval Adam <yuval@y3xz.com> | 2016-01-02 01:23:14 +0200 |
|---|---|---|
| committer | Yuval Adam <yuval@y3xz.com> | 2016-01-02 01:23:14 +0200 |
| commit | 7831cf281921fdab1ac652528451100bf3479206 (patch) | |
| tree | 934ddb317c083207bc930e317d6e73a170cf8dc5 | |
| parent | 8ffcc2bbd0460616495d18feb74763f31a459c1d (diff) | |
Render imgs into global state
| -rw-r--r-- | geshem.js | 6 | ||||
| -rw-r--r-- | geshem.py | 4 | ||||
| -rw-r--r-- | static/js/bundle.js | 17 | ||||
| -rw-r--r-- | templates/index.html | 3 |
4 files changed, 21 insertions, 9 deletions
@@ -20,6 +20,10 @@ class GLMap extends React.Component { token: React.PropTypes.string // mapbox auth token } + getInitialState () { + return window.imgs + } + componentDidMount () { mapboxgl.accessToken = this.props.token @@ -171,7 +175,7 @@ class Map extends React.Component { <GLMap view={view} token='pk.eyJ1IjoieXV2YWRtIiwiYSI6ImNpaWRuaWFxazAwMTJ2b2tyZGRmaWpsNWYifQ.qf_V3CFP_NZtLjk5luNM4g' /> - <Slider step={2} defaultValue={50} /> + <Slider step={1} min={1} max={7} defaultValue={7} /> </div> } } @@ -48,11 +48,11 @@ def get_imgs(): '140': img_140_files[:7], '280': img_280_files[:7] } - return jsonify(imgs) + return imgs @app.route('/') def home(): - return render_template('index.html') + return render_template('index.html', imgs=get_imgs()) @app.after_request diff --git a/static/js/bundle.js b/static/js/bundle.js index bb4f28b..f94c182 100644 --- a/static/js/bundle.js +++ b/static/js/bundle.js @@ -86,8 +86,17 @@ } _createClass(GLMap, [{ - key: 'componentDidMount', + key: 'getInitialState', // mapbox auth token + value: function getInitialState() { + return window.imgs; + } + + // Adapted from Tim Welch's code that can be found at + // https://github.com/twelch/react-mapbox-gl-seed/blob/4d78eb0/src/components/GLMap.js + + }, { + key: 'componentDidMount', value: function componentDidMount() { var _this2 = this; @@ -127,10 +136,6 @@ }); }); } - - // Adapted from Tim Welch's code that can be found at - // https://github.com/twelch/react-mapbox-gl-seed/blob/4d78eb0/src/components/GLMap.js - }, { key: 'componentWillUnmount', value: function componentWillUnmount() { @@ -248,7 +253,7 @@ _react2.default.createElement(GLMap, { view: view, token: 'pk.eyJ1IjoieXV2YWRtIiwiYSI6ImNpaWRuaWFxazAwMTJ2b2tyZGRmaWpsNWYifQ.qf_V3CFP_NZtLjk5luNM4g' }), - _react2.default.createElement(_rcSlider2.default, { step: 2, defaultValue: 50 }) + _react2.default.createElement(_rcSlider2.default, { step: 1, min: 1, max: 7, defaultValue: 7 }) ); } }]); diff --git a/templates/index.html b/templates/index.html index 61cbb05..052b318 100644 --- a/templates/index.html +++ b/templates/index.html @@ -16,6 +16,9 @@ </head> <body> <div id='root'></div> + <script> + window.imgs = {{ imgs|safe }}; + </script> <script src='/static/js/bundle.js'></script> </body> </html> |
