Skip to content

Commit

Permalink
Load thumbnail in window
Browse files Browse the repository at this point in the history
Co-Authored-By: Jack Reed <[email protected]>
  • Loading branch information
camillevilla and mejackreed committed Oct 24, 2018
1 parent a20e9cb commit 2fc4c92
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
3 changes: 2 additions & 1 deletion minimal_redux_poc/__tests__/src/components/Window.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('Window', () => {

it('renders without an error', () => {
expect(wrapper.find('div.mirador-window').length).toBe(1);
expect(wrapper.find('div.mirador-window').text()).toBe(window.id);
expect(wrapper.find('div.mirador-window h3').text()).toBe('Test 2 Manifest: Metadata Pairs');
expect(wrapper.find('div.mirador-window img').prop('src')).toBe('http://placekitten.com/200/300');
});
});
33 changes: 24 additions & 9 deletions minimal_redux_poc/src/components/Window.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,49 @@ import PropTypes from 'prop-types';
* @param {object} window
*/
class Window extends Component {
/**
* Fetches IIIF thumbnail URL
*/
thumbnail() {
const thumb = this.props.manifest.manifestation.getThumbnail() || { id: 'http://placekitten.com/200/300' };
return thumb.id;
}

/**
* Renders things
* @param {object} props (from react/redux)
*/
render() {
return (
<div
className="mirador-window"
>
{this.props.window.id}
<div className="mirador-window">
<h3>{this.props.manifest.manifestation.getLabel().map(label => label.value)[0]}</h3>
<img src={this.thumbnail()} alt="" />
<p>{this.props.window.id}</p>
</div>
);
}
}

Window.propTypes = {
window: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
manifest: PropTypes.object, // eslint-disable-line react/forbid-prop-types
};

Window.defaultProps = {
manifest: null,
};

/**
* mapStateToProps - used to hook up connect to action creators
* @memberof Window
* @private
*/
const mapStateToProps = ({ windows }, props) => (
{
window: windows.find(window => props.id === window.id),
}
);
const mapStateToProps = ({ windows, manifests }, props) => {
const window = windows.find(win => props.id === win.id);
return {
window,
manifest: manifests[window.manifestId],
};
};

export default connect(mapStateToProps)(Window);

0 comments on commit 2fc4c92

Please sign in to comment.