Skip to content
Snippets Groups Projects
Unverified Commit 6bb6f30f authored by Jack Reed's avatar Jack Reed Committed by GitHub
Browse files

Merge pull request #2170 from ProjectMirador/2138-thumbnails

Try harder to get manifest thumbnails
parents 5de70240 fbee2ca1
No related branches found
No related tags found
No related merge requests found
...@@ -29,7 +29,7 @@ describe('ManifestListItem', () => { ...@@ -29,7 +29,7 @@ describe('ManifestListItem', () => {
const wrapper = createWrapper({ ready: false }); const wrapper = createWrapper({ ready: false });
expect(wrapper.find('.mirador-manifest-list-item').length).toBe(1); expect(wrapper.find('.mirador-manifest-list-item').length).toBe(1);
expect(wrapper.find('ReactPlaceholder').length).toBe(1); expect(wrapper.find('ReactPlaceholder').length > 0).toBe(true);
}); });
it('renders an error message if fetching the manifest failed', () => { it('renders an error message if fetching the manifest failed', () => {
const wrapper = createWrapper({ error: 'This is an error message' }); const wrapper = createWrapper({ error: 'This is an error message' });
......
...@@ -83,6 +83,30 @@ describe('getManifestThumbnail()', () => { ...@@ -83,6 +83,30 @@ describe('getManifestThumbnail()', () => {
expect(received).toEqual(manifestFixture001.thumbnail['@id']); expect(received).toEqual(manifestFixture001.thumbnail['@id']);
}); });
it('returns the first canvas thumbnail id', () => {
const manifest = {
manifestation: {
getThumbnail: () => (null),
getSequences: () => [
{
getCanvases: () => [
{ getThumbnail: () => ({ id: 'xyz' }) },
],
},
],
},
};
const received = getManifestThumbnail(manifest);
expect(received).toEqual('xyz');
});
it('returns a thumbnail sized image url from the first canvas', () => {
const manifest = { manifestation: manifesto.create(manifestFixture019) };
const received = getManifestThumbnail(manifest);
expect(received).toEqual('https://stacks.stanford.edu/image/iiif/hg676jb4964%2F0380_796-44/full/,80/0/default.jpg');
});
it('should return null if manifest has no thumbnail', () => { it('should return null if manifest has no thumbnail', () => {
const manifest = { manifestation: manifesto.create({}) }; const manifest = { manifestation: manifesto.create({}) };
const received = getManifestThumbnail(manifest); const received = getManifestThumbnail(manifest);
......
...@@ -95,14 +95,14 @@ export class ManifestListItem extends React.Component { ...@@ -95,14 +95,14 @@ export class ManifestListItem extends React.Component {
<Grid container spacing={24} className={classes.label}> <Grid container spacing={24} className={classes.label}>
<Grid item xs={4} sm={3}> <Grid item xs={4} sm={3}>
{ {
thumbnail && ( <ReactPlaceholder ready={!!thumbnail} type="rect" style={{ width: 120, height: 80 }}>
<img <img
className={ns('manifest-list-item-thumb')} className={ns('manifest-list-item-thumb')}
src={thumbnail} src={thumbnail}
alt="" alt=""
height="80" height="80"
/> />
) </ReactPlaceholder>
} }
</Grid> </Grid>
<Grid item xs={8} sm={9}> <Grid item xs={8} sm={9}>
......
...@@ -2,6 +2,7 @@ import filter from 'lodash/filter'; ...@@ -2,6 +2,7 @@ import filter from 'lodash/filter';
import flatten from 'lodash/flatten'; import flatten from 'lodash/flatten';
import { LanguageMap } from 'manifesto.js'; import { LanguageMap } from 'manifesto.js';
import Annotation from '../../lib/Annotation'; import Annotation from '../../lib/Annotation';
import ManifestoCanvas from '../../lib/ManifestoCanvas';
/** /**
* Return the manifest that belongs to a certain window. * Return the manifest that belongs to a certain window.
...@@ -43,16 +44,41 @@ export function getManifestProvider(manifest) { ...@@ -43,16 +44,41 @@ export function getManifestProvider(manifest) {
} }
/** /**
* Return the logo of a manifest or null * Return the supplied thumbnail for a manifest or null
* @param {object} manifest * @param {object} manifest
* @return {String|null} * @return {String|null}
*/ */
export function getManifestThumbnail(manifest) { export function getManifestThumbnail(manifest) {
/** */
function getTopLevelManifestThumbnail() {
return manifest.manifestation return manifest.manifestation
&& manifest.manifestation.getThumbnail() && manifest.manifestation.getThumbnail()
&& manifest.manifestation.getThumbnail().id; && manifest.manifestation.getThumbnail().id;
} }
/** */
function getFirstCanvasThumbnail() {
const canvases = getManifestCanvases(manifest);
return canvases.length > 0 && canvases[0].getThumbnail() && canvases[0].getThumbnail().id;
}
/** */
function generateThumbnailFromFirstCanvas() {
const canvases = getManifestCanvases(manifest);
if (canvases.length === 0) return null;
const manifestoCanvas = new ManifestoCanvas(canvases[0]);
return manifestoCanvas.thumbnail(null, 80);
}
return getTopLevelManifestThumbnail()
|| getFirstCanvasThumbnail()
|| generateThumbnailFromFirstCanvas();
}
/** /**
* Return the logo of a manifest or null * Return the logo of a manifest or null
* @param {object} manifest * @param {object} manifest
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment