about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/features/ui/components/image_loader.js
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2018-04-08 23:15:25 +0200
committerThibaut Girka <thib@sitedethib.com>2018-04-08 23:15:25 +0200
commit87071d9e8133daf60f5c253fdc4250086e342143 (patch)
tree7cd622223b9ec38a19c9bf6a8e45b40d7648ccd4 /app/javascript/flavours/glitch/features/ui/components/image_loader.js
parent0b86ec4e7fb45c1388a692b23f5ffc7d78b5076f (diff)
[Glitch] Improved media modal
Port 4e929b2d173fa22b722c58c0e9f8223eb4f44b0e to glitch-soc
Diffstat (limited to 'app/javascript/flavours/glitch/features/ui/components/image_loader.js')
-rw-r--r--app/javascript/flavours/glitch/features/ui/components/image_loader.js32
1 files changed, 18 insertions, 14 deletions
diff --git a/app/javascript/flavours/glitch/features/ui/components/image_loader.js b/app/javascript/flavours/glitch/features/ui/components/image_loader.js
index e3e7197c5..c7360a726 100644
--- a/app/javascript/flavours/glitch/features/ui/components/image_loader.js
+++ b/app/javascript/flavours/glitch/features/ui/components/image_loader.js
@@ -1,6 +1,7 @@
 import React from 'react';
 import PropTypes from 'prop-types';
 import classNames from 'classnames';
+import ZoomableImage from './zoomable_image';
 
 export default class ImageLoader extends React.PureComponent {
 
@@ -10,6 +11,7 @@ export default class ImageLoader extends React.PureComponent {
     previewSrc: PropTypes.string,
     width: PropTypes.number,
     height: PropTypes.number,
+    onClick: PropTypes.func,
   }
 
   static defaultProps = {
@@ -24,6 +26,7 @@ export default class ImageLoader extends React.PureComponent {
   }
 
   removers = [];
+  canvas = null;
 
   get canvasContext() {
     if (!this.canvas) {
@@ -43,6 +46,10 @@ export default class ImageLoader extends React.PureComponent {
     }
   }
 
+  componentWillUnmount () {
+    this.removeEventListeners();
+  }
+
   loadImage (props) {
     this.removeEventListeners();
     this.setState({ loading: true, error: false });
@@ -118,7 +125,7 @@ export default class ImageLoader extends React.PureComponent {
   }
 
   render () {
-    const { alt, src, width, height } = this.props;
+    const { alt, src, width, height, onClick } = this.props;
     const { loading } = this.state;
 
     const className = classNames('image-loader', {
@@ -128,22 +135,19 @@ export default class ImageLoader extends React.PureComponent {
 
     return (
       <div className={className}>
-        <canvas
-          className='image-loader__preview-canvas'
-          width={width}
-          height={height}
-          ref={this.setCanvasRef}
-          style={{ opacity: loading ? 1 : 0 }}
-        />
-
-        {!loading && (
-          <img
-            alt={alt}
-            className='image-loader__img'
-            src={src}
+        {loading ? (
+          <canvas
+            className='image-loader__preview-canvas'
+            ref={this.setCanvasRef}
             width={width}
             height={height}
           />
+        ) : (
+          <ZoomableImage
+            alt={alt}
+            src={src}
+            onClick={onClick}
+          />
         )}
       </div>
     );