Skip to content
Snippets Groups Projects
Commit e4ad31ea authored by Chris Beer's avatar Chris Beer
Browse files

Replace @researchgate/react-intersection-observer with react-intersection-observer

parent e792b85d
Branches
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ import React from 'react'; ...@@ -2,7 +2,7 @@ import React from 'react';
import { shallow } from 'enzyme'; import { shallow } from 'enzyme';
import { Utils } from 'manifesto.js'; import { Utils } from 'manifesto.js';
import Chip from '@material-ui/core/Chip'; import Chip from '@material-ui/core/Chip';
import IntersectionObserver from '@researchgate/react-intersection-observer'; import { InView } from 'react-intersection-observer';
import manifestJson from '../../fixtures/version-2/019.json'; import manifestJson from '../../fixtures/version-2/019.json';
import { GalleryViewThumbnail } from '../../../src/components/GalleryViewThumbnail'; import { GalleryViewThumbnail } from '../../../src/components/GalleryViewThumbnail';
import IIIFThumbnail from '../../../src/containers/IIIFThumbnail'; import IIIFThumbnail from '../../../src/containers/IIIFThumbnail';
...@@ -78,7 +78,7 @@ describe('GalleryView', () => { ...@@ -78,7 +78,7 @@ describe('GalleryView', () => {
}; };
wrapper = createWrapper({ annotationsCount: 0, canvas, requestCanvasAnnotations }); wrapper = createWrapper({ annotationsCount: 0, canvas, requestCanvasAnnotations });
wrapper.find(IntersectionObserver).simulate('change', { isIntersecting: true }); wrapper.find(InView).simulate('change', { isIntersecting: true });
expect(requestCanvasAnnotations).toHaveBeenCalled(); expect(requestCanvasAnnotations).toHaveBeenCalled();
}); });
it('does nothing if there is no intersection', () => { it('does nothing if there is no intersection', () => {
...@@ -89,7 +89,7 @@ describe('GalleryView', () => { ...@@ -89,7 +89,7 @@ describe('GalleryView', () => {
}; };
wrapper = createWrapper({ canvas, requestCanvasAnnotations }); wrapper = createWrapper({ canvas, requestCanvasAnnotations });
wrapper.find(IntersectionObserver).simulate('change', { isIntersecting: false }); wrapper.find(InView).simulate('change', { isIntersecting: false });
expect(requestCanvasAnnotations).not.toHaveBeenCalled(); expect(requestCanvasAnnotations).not.toHaveBeenCalled();
}); });
it('does nothing if there are already some annotations', () => { it('does nothing if there are already some annotations', () => {
...@@ -100,7 +100,7 @@ describe('GalleryView', () => { ...@@ -100,7 +100,7 @@ describe('GalleryView', () => {
}; };
wrapper = createWrapper({ annotationsCount: 5, canvas, requestCanvasAnnotations }); wrapper = createWrapper({ annotationsCount: 5, canvas, requestCanvasAnnotations });
wrapper.find(IntersectionObserver).simulate('change', { isIntersecting: true }); wrapper.find(InView).simulate('change', { isIntersecting: true });
expect(requestCanvasAnnotations).not.toHaveBeenCalled(); expect(requestCanvasAnnotations).not.toHaveBeenCalled();
}); });
}); });
......
import React from 'react'; import React from 'react';
import { shallow } from 'enzyme'; import { shallow } from 'enzyme';
import IntersectionObserver from '@researchgate/react-intersection-observer'; import { InView } from 'react-intersection-observer';
import Typography from '@material-ui/core/Typography'; import Typography from '@material-ui/core/Typography';
import { IIIFThumbnail } from '../../../src/components/IIIFThumbnail'; import { IIIFThumbnail } from '../../../src/components/IIIFThumbnail';
...@@ -26,9 +26,9 @@ describe('IIIFThumbnail', () => { ...@@ -26,9 +26,9 @@ describe('IIIFThumbnail', () => {
it('renders properly', () => { it('renders properly', () => {
expect(wrapper.matchesElement( expect(wrapper.matchesElement(
<div> <div>
<IntersectionObserver onChange={wrapper.instance().handleIntersection}> <InView onChange={wrapper.instance().handleIntersection}>
<img alt="" /> <img alt="" />
</IntersectionObserver> </InView>
</div>, </div>,
)).toBe(true); )).toBe(true);
}); });
...@@ -37,9 +37,9 @@ describe('IIIFThumbnail', () => { ...@@ -37,9 +37,9 @@ describe('IIIFThumbnail', () => {
wrapper = createWrapper({}); wrapper = createWrapper({});
expect(wrapper.matchesElement( expect(wrapper.matchesElement(
<div> <div>
<IntersectionObserver onChange={wrapper.instance().handleIntersection}> <InView onChange={wrapper.instance().handleIntersection}>
<img alt="" /> <img alt="" />
</IntersectionObserver> </InView>
</div>, </div>,
)).toBe(true); )).toBe(true);
expect(wrapper.find('img').props().src).toMatch(/data:image\/png;base64/); expect(wrapper.find('img').props().src).toMatch(/data:image\/png;base64/);
......
...@@ -5,7 +5,7 @@ import Chip from '@material-ui/core/Chip'; ...@@ -5,7 +5,7 @@ import Chip from '@material-ui/core/Chip';
import AnnotationIcon from '@material-ui/icons/CommentSharp'; import AnnotationIcon from '@material-ui/icons/CommentSharp';
import SearchIcon from '@material-ui/icons/SearchSharp'; import SearchIcon from '@material-ui/icons/SearchSharp';
import classNames from 'classnames'; import classNames from 'classnames';
import IntersectionObserver from '@researchgate/react-intersection-observer'; import { InView } from 'react-intersection-observer';
import MiradorCanvas from '../lib/MiradorCanvas'; import MiradorCanvas from '../lib/MiradorCanvas';
import IIIFThumbnail from '../containers/IIIFThumbnail'; import IIIFThumbnail from '../containers/IIIFThumbnail';
...@@ -108,7 +108,7 @@ export class GalleryViewThumbnail extends Component { ...@@ -108,7 +108,7 @@ export class GalleryViewThumbnail extends Component {
const miradorCanvas = new MiradorCanvas(canvas); const miradorCanvas = new MiradorCanvas(canvas);
return ( return (
<IntersectionObserver onChange={this.handleIntersection}> <InView onChange={this.handleIntersection}>
<div <div
key={canvas.index} key={canvas.index}
className={ className={
...@@ -167,7 +167,7 @@ export class GalleryViewThumbnail extends Component { ...@@ -167,7 +167,7 @@ export class GalleryViewThumbnail extends Component {
</div> </div>
</IIIFThumbnail> </IIIFThumbnail>
</div> </div>
</IntersectionObserver> </InView>
); );
} }
} }
......
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import Typography from '@material-ui/core/Typography'; import Typography from '@material-ui/core/Typography';
import IntersectionObserver from '@researchgate/react-intersection-observer'; import { InView } from 'react-intersection-observer';
import classNames from 'classnames'; import classNames from 'classnames';
import getThumbnail from '../lib/ThumbnailFactory'; import getThumbnail from '../lib/ThumbnailFactory';
...@@ -47,10 +47,10 @@ export class IIIFThumbnail extends Component { ...@@ -47,10 +47,10 @@ export class IIIFThumbnail extends Component {
* Handles the intersection (visibility) of a given thumbnail, by requesting * Handles the intersection (visibility) of a given thumbnail, by requesting
* the image and then updating the state. * the image and then updating the state.
*/ */
handleIntersection(event) { handleIntersection(inView, _entry) {
const { loaded } = this.state; const { loaded } = this.state;
if (loaded || !event.isIntersecting) return; if (loaded || !inView) return;
this.setState(state => ({ ...state, loaded: true })); this.setState(state => ({ ...state, loaded: true }));
} }
...@@ -151,7 +151,7 @@ export class IIIFThumbnail extends Component { ...@@ -151,7 +151,7 @@ export class IIIFThumbnail extends Component {
return ( return (
<div className={classNames(classes.root, { [classes[`${variant}Root`]]: variant })}> <div className={classNames(classes.root, { [classes[`${variant}Root`]]: variant })}>
<IntersectionObserver onChange={this.handleIntersection}> <InView as="span" onChange={this.handleIntersection}>
<img <img
alt="" alt=""
role="presentation" role="presentation"
...@@ -159,7 +159,7 @@ export class IIIFThumbnail extends Component { ...@@ -159,7 +159,7 @@ export class IIIFThumbnail extends Component {
style={this.imageStyles()} style={this.imageStyles()}
className={classes.image} className={classes.image}
/> />
</IntersectionObserver> </InView>
{ labelled && ( { labelled && (
<div className={classNames(classes.label, { [classes[`${variant}Label`]]: variant })}> <div className={classNames(classes.label, { [classes[`${variant}Label`]]: variant })}>
<Typography variant="caption" classes={{ root: classNames(classes.caption, { [classes[`${variant}Caption`]]: variant }) }}> <Typography variant="caption" classes={{ root: classNames(classes.caption, { [classes[`${variant}Caption`]]: variant }) }}>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment