Skip to content

Commit 44daf70

Browse files
authored
Fix asset store display speed and reduce the burst of requests (#7241)
1 parent c9e5272 commit 44daf70

File tree

8 files changed

+33
-10
lines changed

8 files changed

+33
-10
lines changed

newIDE/app/src/AssetStore/AssetCard.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ export const AssetCard = ({
5454
<div id={id} style={{ ...styles.cardContainer, width: size, height: size }}>
5555
<div style={{ ...styles.previewContainer, width: size, height: size }}>
5656
<CheckeredBackground />
57-
<AssetPreviewImage assetShortHeader={assetShortHeader} maxSize={128} />
57+
<AssetPreviewImage
58+
assetShortHeader={assetShortHeader}
59+
maxSize={128}
60+
loading="lazy"
61+
/>
5862
</div>
5963
<div
6064
style={{

newIDE/app/src/AssetStore/AssetPreviewImage.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,14 @@ const styles = {
2828
type Props = {|
2929
assetShortHeader: AssetShortHeader,
3030
maxSize?: number,
31+
loading?: 'lazy',
3132
|};
3233

33-
export const AssetPreviewImage = ({ assetShortHeader, maxSize }: Props) => {
34+
export const AssetPreviewImage = ({
35+
assetShortHeader,
36+
maxSize,
37+
loading,
38+
}: Props) => {
3439
const previewImageUrl = assetShortHeader.previewImageUrls[0];
3540
const isPrivate = isPrivateAsset(assetShortHeader);
3641
const [isLoaded, setIsLoaded] = React.useState(false);
@@ -55,6 +60,7 @@ export const AssetPreviewImage = ({ assetShortHeader, maxSize }: Props) => {
5560
url={previewImageUrl}
5661
alt={assetShortHeader.name}
5762
onLoad={onLoad}
63+
loading={loading}
5864
/>
5965
) : (
6066
<CorsAwareImage
@@ -63,6 +69,7 @@ export const AssetPreviewImage = ({ assetShortHeader, maxSize }: Props) => {
6369
src={previewImageUrl}
6470
alt={assetShortHeader.name}
6571
onLoad={onLoad}
72+
loading={loading}
6673
/>
6774
);
6875
};

newIDE/app/src/AssetStore/AssetsList.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import HelpIcon from '../UI/HelpIcon';
5353
import { OwnedProductLicense } from './ProductLicense/ProductLicenseOptions';
5454
import { getUserProductPurchaseUsageType } from './ProductPageHelper';
5555

56-
const ASSETS_DISPLAY_LIMIT = 250;
56+
const ASSETS_DISPLAY_LIMIT = 60;
5757

5858
const getAssetSize = (windowSize: WindowSizeType) => {
5959
switch (windowSize) {
@@ -338,7 +338,7 @@ const AssetsList = React.forwardRef<Props, AssetsListInterface>(
338338
scrollViewElement.scrollToPosition(y);
339339
},
340340
setPageBreakIndex: (index: number) => {
341-
setPageBreakIndex(0);
341+
setPageBreakIndex(index);
342342
},
343343
}));
344344

@@ -471,6 +471,8 @@ const AssetsList = React.forwardRef<Props, AssetsListInterface>(
471471
if (!assetShortHeaders) return null;
472472
// Don't show assets if filtering on asset packs.)
473473
if (hasAssetPackFiltersApplied && !openedAssetPack) return [];
474+
const assetSize = getAssetSize(windowSize);
475+
const margin = cellSpacing / 2;
474476

475477
return getAssetShortHeadersToDisplay(
476478
assetShortHeaders,
@@ -480,9 +482,9 @@ const AssetsList = React.forwardRef<Props, AssetsListInterface>(
480482
<AssetCardTile
481483
assetShortHeader={assetShortHeader}
482484
onOpenDetails={() => onOpenDetails(assetShortHeader)}
483-
size={getAssetSize(windowSize)}
485+
size={assetSize}
484486
key={assetShortHeader.id}
485-
margin={cellSpacing / 2}
487+
margin={margin}
486488
hideShortDescription={!!hideDetails}
487489
/>
488490
));

newIDE/app/src/AssetStore/PrivateAssets/AuthorizedAssetImage.js

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type Props = {|
1111
onError?: () => void,
1212
onLoad?: (e: any) => void,
1313
hideLoader?: boolean,
14+
loading?: 'lazy',
1415
|};
1516

1617
const AuthorizedAssetImage = ({
@@ -20,6 +21,7 @@ const AuthorizedAssetImage = ({
2021
onError,
2122
onLoad,
2223
hideLoader,
24+
loading,
2325
}: Props) => {
2426
const [authorizedUrl, setAuthorizedUrl] = React.useState(null);
2527
const [isImageLoaded, setIsImageLoaded] = React.useState(false);
@@ -78,6 +80,7 @@ const AuthorizedAssetImage = ({
7880
<img
7981
alt={alt}
8082
src={authorizedUrl}
83+
loading={loading}
8184
style={{
8285
...style,
8386
// Use display none to load the image in the background, but not

newIDE/app/src/AssetStore/ShopTiles.js

+6
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ export const PublicAssetPackTile = ({
244244
style={styles.previewImage}
245245
src={assetPack.thumbnailUrl}
246246
alt={`Preview image of asset pack ${assetPack.name}`}
247+
loading="lazy"
247248
/>
248249
<Column>
249250
<Line justifyContent="space-between" noMargin>
@@ -299,6 +300,7 @@ export const PrivateAssetPackTile = ({
299300
style={styles.previewImage}
300301
src={assetPackListingData.thumbnailUrls[0]}
301302
alt={`Preview image of asset pack ${assetPackListingData.name}`}
303+
loading="lazy"
302304
/>
303305
{assetPackListingData.redeemConditions && !owned && (
304306
<div style={styles.redeemableContainer}>
@@ -367,6 +369,7 @@ export const PromoBundleCard = ({
367369
}}
368370
src={productListingData.thumbnailUrls[0]}
369371
alt={`Preview image of bundle ${productListingData.name}`}
372+
loading="lazy"
370373
/>
371374
</div>
372375
<Column expand alignItems="flex-start" justifyContent="center">
@@ -476,6 +479,7 @@ export const CategoryTile = ({
476479
}}
477480
src={imageSource}
478481
alt={imageAlt}
482+
// No lazy loading because categories are the first seen tiles in the shop.
479483
/>
480484
<Column>
481485
<Line justifyContent="center" noMargin>
@@ -527,6 +531,7 @@ export const PrivateGameTemplateTile = ({
527531
alt={`Preview image of game template ${
528532
privateGameTemplateListingData.name
529533
}`}
534+
loading="lazy"
530535
/>
531536
<div style={styles.priceTagContainer}>
532537
<ProductPriceTag
@@ -603,6 +608,7 @@ export const ExampleTile = ({
603608
style={styles.previewImage}
604609
src={thumbnailImgUrl}
605610
alt={`Preview image of example ${exampleShortHeader.name}`}
611+
loading="lazy"
606612
/>
607613
) : (
608614
<EmptyMessage

newIDE/app/src/AssetStore/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -645,11 +645,11 @@ export const AssetStore = React.forwardRef<Props, AssetStoreInterface>(
645645
<Column expand useFullHeight noMargin>
646646
<SearchBar
647647
placeholder={
648-
hideGameTemplates ? t`Search assets` : `Search the shop`
648+
hideGameTemplates ? t`Search assets` : t`Search the shop`
649649
}
650650
value={searchText}
651651
onChange={(newValue: string) => {
652-
if (searchText === newValue) {
652+
if (searchText === newValue || newValue.length === 1) {
653653
return;
654654
}
655655
setSearchText(newValue);

newIDE/app/src/UI/CorsAwareImage.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type Props = {|
1010
title?: ?string,
1111
onError?: (?Error) => void,
1212
onLoad?: (e: any) => void,
13+
loading?: 'lazy',
1314
|};
1415

1516
const addSearchParameterToUrl = (

newIDE/app/src/UI/Search/UseSearchItem.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,6 @@ export const useSearchItem = <SearchItem: SearchableItem>(
289289
[searchItemsById, getItemDescription]
290290
);
291291

292-
// Update the search results according to the items, search term
293-
// chosen category and chosen filters.
294292
const searchApi = searchApiRef.current;
295293
React.useEffect(
296294
() => {
@@ -351,6 +349,8 @@ export const useSearchItem = <SearchItem: SearchableItem>(
351349
discardSearch = true;
352350
};
353351
},
352+
// Update the search results according to the items, search term
353+
// chosen category and chosen filters.
354354
[
355355
shuffledSearchItems,
356356
sortedSearchItems,

0 commit comments

Comments
 (0)