Skip to content

Commit 13f7215

Browse files
authored
Merge branch 'develop' into revert-4732-greenkeeper/scratch-render-0.1.0-prerelease.20190410184112
2 parents 0caee11 + b435ac3 commit 13f7215

File tree

6 files changed

+34
-214
lines changed

6 files changed

+34
-214
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@
100100
"react-test-renderer": "16.2.0",
101101
"react-tooltip": "3.8.0",
102102
"react-virtualized": "9.20.1",
103-
"react-visibility-sensor": "5.0.2",
104103
"redux": "3.7.2",
105104
"redux-mock-store": "^1.2.3",
106105
"redux-throttle": "0.1.1",
@@ -110,7 +109,7 @@
110109
"scratch-l10n": "3.1.20190410143750",
111110
"scratch-paint": "0.2.0-prerelease.20190318170811",
112111
"scratch-render": "0.1.0-prerelease.20190326161919",
113-
"scratch-storage": "1.3.1",
112+
"scratch-storage": "1.2.2",
114113
"scratch-svg-renderer": "0.2.0-prerelease.20190329052730",
115114
"scratch-vm": "0.2.0-prerelease.20190410143927",
116115
"selenium-webdriver": "3.6.0",

src/components/library-item/library-item.jsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import PropTypes from 'prop-types';
33
import React from 'react';
44

55
import Box from '../box/box.jsx';
6-
import ScratchImage from '../scratch-image/scratch-image.jsx';
76
import styles from './library-item.css';
87
import classNames from 'classnames';
98

@@ -36,12 +35,10 @@ class LibraryItemComponent extends React.PureComponent {
3635
/>
3736
</div>
3837
) : null}
39-
{this.props.iconSource ? (
40-
<ScratchImage
41-
className={styles.featuredImage}
42-
imageSource={this.props.iconSource}
43-
/>
44-
) : null}
38+
<img
39+
className={styles.featuredImage}
40+
src={this.props.iconURL}
41+
/>
4542
</div>
4643
{this.props.insetIconURL ? (
4744
<div className={styles.libraryItemInsetImageContainer}>
@@ -124,9 +121,9 @@ class LibraryItemComponent extends React.PureComponent {
124121
{/* Layers of wrapping is to prevent layout thrashing on animation */}
125122
<Box className={styles.libraryItemImageContainerWrapper}>
126123
<Box className={styles.libraryItemImageContainer}>
127-
<ScratchImage
124+
<img
128125
className={styles.libraryItemImage}
129-
imageSource={this.props.iconSource}
126+
src={this.props.iconURL}
130127
/>
131128
</Box>
132129
</Box>
@@ -149,7 +146,7 @@ LibraryItemComponent.propTypes = {
149146
extensionId: PropTypes.string,
150147
featured: PropTypes.bool,
151148
hidden: PropTypes.bool,
152-
iconSource: ScratchImage.ImageSourcePropType,
149+
iconURL: PropTypes.string,
153150
insetIconURL: PropTypes.string,
154151
internetConnectionRequired: PropTypes.bool,
155152
name: PropTypes.oneOfType([

src/components/library/library.jsx

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import Modal from '../../containers/modal.jsx';
99
import Divider from '../divider/divider.jsx';
1010
import Filter from '../filter/filter.jsx';
1111
import TagButton from '../../containers/tag-button.jsx';
12-
import storage from '../../lib/storage';
1312

1413
import styles from './library.css';
1514

@@ -29,47 +28,6 @@ const messages = defineMessages({
2928
const ALL_TAG = {tag: 'all', intlLabel: messages.allTag};
3029
const tagListPrefix = [ALL_TAG];
3130

32-
/**
33-
* Find the AssetType which corresponds to a particular file extension. For example, 'png' => AssetType.ImageBitmap.
34-
* @param {string} fileExtension - the file extension to look up.
35-
* @returns {AssetType} - the AssetType corresponding to the extension, if any.
36-
*/
37-
const getAssetTypeForFileExtension = function (fileExtension) {
38-
const compareOptions = {
39-
sensitivity: 'accent',
40-
usage: 'search'
41-
};
42-
for (const assetTypeId in storage.AssetType) {
43-
const assetType = storage.AssetType[assetTypeId];
44-
if (fileExtension.localeCompare(assetType.runtimeFormat, compareOptions) === 0) {
45-
return assetType;
46-
}
47-
}
48-
};
49-
50-
/**
51-
* Figure out an `imageSource` (URI or asset ID & type) for a library item's icon.
52-
* @param {object} item - either a library item or one of a library item's costumes.
53-
* @returns {object} - an `imageSource` ready to be passed to a `ScratchImage`.
54-
*/
55-
const getItemImageSource = function (item) {
56-
if (item.rawURL) {
57-
return {
58-
uri: item.rawURL
59-
};
60-
}
61-
62-
// TODO: adjust libraries to be more storage-friendly; don't use split() here.
63-
const md5 = item.md5 || item.baseLayerMD5;
64-
if (md5) {
65-
const [assetId, fileExtension] = md5.split('.');
66-
return {
67-
assetId: assetId,
68-
assetType: getAssetTypeForFileExtension(fileExtension)
69-
};
70-
}
71-
};
72-
7331
class LibraryComponent extends React.Component {
7432
constructor (props) {
7533
super(props);
@@ -204,19 +162,18 @@ class LibraryComponent extends React.Component {
204162
})}
205163
ref={this.setFilteredDataRef}
206164
>
207-
{this.getFilteredData().map((dataItem, index) => {
208-
const iconSource = getItemImageSource(dataItem);
209-
const icons = dataItem.json && dataItem.json.costumes.map(getItemImageSource);
210-
return (<LibraryItem
165+
{this.getFilteredData().map((dataItem, index) => (
166+
<LibraryItem
211167
bluetoothRequired={dataItem.bluetoothRequired}
212168
collaborator={dataItem.collaborator}
213169
description={dataItem.description}
214170
disabled={dataItem.disabled}
215171
extensionId={dataItem.extensionId}
216172
featured={dataItem.featured}
217173
hidden={dataItem.hidden}
218-
iconSource={iconSource}
219-
icons={icons}
174+
iconMd5={dataItem.md5}
175+
iconRawURL={dataItem.rawURL}
176+
icons={dataItem.json && dataItem.json.costumes}
220177
id={index}
221178
insetIconURL={dataItem.insetIconURL}
222179
internetConnectionRequired={dataItem.internetConnectionRequired}
@@ -225,8 +182,8 @@ class LibraryComponent extends React.Component {
225182
onMouseEnter={this.handleMouseEnter}
226183
onMouseLeave={this.handleMouseLeave}
227184
onSelect={this.handleSelect}
228-
/>);
229-
})}
185+
/>
186+
))}
230187
</div>
231188
</Modal>
232189
);

src/components/scratch-image/scratch-image.jsx

Lines changed: 0 additions & 139 deletions
This file was deleted.

src/containers/library-item.jsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,21 @@ class LibraryItem extends React.PureComponent {
7575
const nextIconIndex = (this.state.iconIndex + 1) % this.props.icons.length;
7676
this.setState({iconIndex: nextIconIndex});
7777
}
78-
curIconSource () {
78+
curIconMd5 () {
7979
if (this.props.icons &&
8080
this.state.isRotatingIcon &&
8181
this.state.iconIndex < this.props.icons.length &&
82-
this.props.icons[this.state.iconIndex]) {
83-
return this.props.icons[this.state.iconIndex];
82+
this.props.icons[this.state.iconIndex] &&
83+
this.props.icons[this.state.iconIndex].baseLayerMD5) {
84+
return this.props.icons[this.state.iconIndex].baseLayerMD5;
8485
}
85-
return this.props.iconSource;
86+
return this.props.iconMd5;
8687
}
8788
render () {
88-
const iconSource = this.curIconSource();
89+
const iconMd5 = this.curIconMd5();
90+
const iconURL = iconMd5 ?
91+
`https://cdn.assets.scratch.mit.edu/internalapi/asset/${iconMd5}/get/` :
92+
this.props.iconRawURL;
8993
return (
9094
<LibraryItemComponent
9195
bluetoothRequired={this.props.bluetoothRequired}
@@ -95,7 +99,8 @@ class LibraryItem extends React.PureComponent {
9599
extensionId={this.props.extensionId}
96100
featured={this.props.featured}
97101
hidden={this.props.hidden}
98-
iconSource={iconSource}
102+
iconURL={iconURL}
103+
icons={this.props.icons}
99104
id={this.props.id}
100105
insetIconURL={this.props.insetIconURL}
101106
internetConnectionRequired={this.props.internetConnectionRequired}
@@ -122,8 +127,13 @@ LibraryItem.propTypes = {
122127
extensionId: PropTypes.string,
123128
featured: PropTypes.bool,
124129
hidden: PropTypes.bool,
125-
iconSource: LibraryItemComponent.propTypes.iconSource, // single icon
126-
icons: PropTypes.arrayOf(LibraryItemComponent.propTypes.iconSource), // rotating icons
130+
iconMd5: PropTypes.string,
131+
iconRawURL: PropTypes.string,
132+
icons: PropTypes.arrayOf(
133+
PropTypes.shape({
134+
baseLayerMD5: PropTypes.string
135+
})
136+
),
127137
id: PropTypes.number.isRequired,
128138
insetIconURL: PropTypes.string,
129139
internetConnectionRequired: PropTypes.bool,

test/integration/costumes.test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,7 @@ describe('Working with costumes', () => {
193193
.mouseMove(abbyElement)
194194
.perform();
195195
// wait for one of Abby's alternate costumes to appear
196-
const src1 = await abbyElement.findElement({css: 'img'}).getAttribute('src');
197-
await driver.sleep(300);
198-
const src2 = await abbyElement.findElement({css: 'img'}).getAttribute('src');
199-
const sourcesMatch = (src1 === src2);
200-
await expect(sourcesMatch).toBeFalsy(); // 'src' attribute should have changed by now
196+
await findByXpath('//img[@src="https://cdn.assets.scratch.mit.edu/internalapi/asset/b6e23922f23b49ddc6f62f675e77417c.svg/get/"]');
201197
const logs = await getLogs();
202198
await expect(logs).toEqual([]);
203199
});

0 commit comments

Comments
 (0)