Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load thumbnail in window #55

Merged
merged 1 commit into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);