11import { FormattedMessage } from 'react-intl' ;
22import PropTypes from 'prop-types' ;
3+ import bindAll from 'lodash.bindall' ;
34import React from 'react' ;
45
56import Box from '../box/box.jsx' ;
@@ -15,26 +16,34 @@ import {PLATFORM} from '../../lib/platform.js';
1516
1617/* eslint-disable react/prefer-stateless-function */
1718class LibraryItemComponent extends React . PureComponent {
18- render ( ) {
19- const renderImage = ( className , imageSource ) => {
20- // Scratch Android and Scratch Desktop assume the user is offline and has
21- // local access to the image assets. In those cases we use the `ScratchImage`
22- // component which loads the local assets by using a queue. In Scratch Web
23- // we don't have the assets locally and want to directly download them from
24- // the assets service.
25- // TODO: Abstract this logic in the `ScratchImage` component itself.
26- const url = imageSource . rawUrl ?? imageSource . assetServiceUri ;
27- return this . props . platform === PLATFORM . ANDROID ||
28- this . props . platform === PLATFORM . DESKTOP ?
29- < ScratchImage
30- className = { className }
31- imageSource = { imageSource }
32- /> :
33- < img
34- className = { className }
35- src = { url }
36- />
19+ constructor ( props ) {
20+ super ( props ) ;
21+ bindAll ( this , [
22+ 'renderImage'
23+ ] ) ;
24+ }
25+ renderImage ( className , imageSource ) {
26+ // Scratch Android and Scratch Desktop assume the user is offline and has
27+ // local access to the image assets. In those cases we use the `ScratchImage`
28+ // component which loads the local assets by using a queue. In Scratch Web
29+ // we don't have the assets locally and want to directly download them from
30+ // the assets service.
31+ // TODO: Abstract this logic in the `ScratchImage` component itself.
32+ const url = imageSource . rawUrl ?? imageSource . assetServiceUri ;
33+
34+ if ( this . props . platform === PLATFORM . ANDROID ||
35+ this . props . platform === PLATFORM . DESKTOP ) {
36+ return ( < ScratchImage
37+ className = { className }
38+ imageSource = { imageSource }
39+ /> ) ;
3740 }
41+ return ( < img
42+ className = { className }
43+ src = { url }
44+ /> ) ;
45+ }
46+ render ( ) {
3847 return this . props . featured ? (
3948 < div
4049 className = { classNames (
@@ -59,7 +68,7 @@ class LibraryItemComponent extends React.PureComponent {
5968 </ div >
6069 ) : null }
6170 { this . props . iconSource ? (
62- renderImage ( styles . featuredImage , this . props . iconSource )
71+ this . renderImage ( styles . featuredImage , this . props . iconSource )
6372 ) : null }
6473 </ div >
6574 { this . props . insetIconURL ? (
@@ -148,7 +157,7 @@ class LibraryItemComponent extends React.PureComponent {
148157 onMouseEnter = { this . props . showPlayButton ? this . props . onMouseEnter : null }
149158 onMouseLeave = { this . props . showPlayButton ? this . props . onMouseLeave : null }
150159 >
151- { renderImage ( styles . libraryItemImage , this . props . iconSource ) }
160+ { this . renderImage ( styles . libraryItemImage , this . props . iconSource ) }
152161 </ Box >
153162 </ Box >
154163 < span className = { styles . libraryItemName } > { this . props . name } </ span >
0 commit comments