Skip to content

Commit 70226f4

Browse files
Rework Asset Pack add to a list of filtered assets
Do not show in changelog
1 parent b157210 commit 70226f4

File tree

2 files changed

+36
-45
lines changed

2 files changed

+36
-45
lines changed

newIDE/app/src/AssetStore/AssetPackDialog.js

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type Props = {|
2828
assetShortHeaders: Array<AssetShortHeader>,
2929
addedAssetIds: Array<string>,
3030
onClose: () => void,
31-
onAssetPackAdded: () => void,
31+
onAssetsAdded: () => void,
3232
project: gdProject,
3333
objectsContainer: gdObjectsContainer,
3434
events: gdEventsList,
@@ -40,7 +40,7 @@ export const AssetPackDialog = ({
4040
assetShortHeaders,
4141
addedAssetIds,
4242
onClose,
43-
onAssetPackAdded,
43+
onAssetsAdded,
4444
project,
4545
objectsContainer,
4646
events,
@@ -56,18 +56,18 @@ export const AssetPackDialog = ({
5656

5757
const resourcesFetcher = useResourceFetcher();
5858
const [
59-
isAssetPackBeingInstalled,
60-
setIsAssetPackBeingInstalled,
59+
areAssetsBeingInstalled,
60+
setAreAssetsBeingInstalled,
6161
] = React.useState<boolean>(false);
6262

6363
const eventsFunctionsExtensionsState = React.useContext(
6464
EventsFunctionsExtensionsContext
6565
);
6666

67-
const onInstallAssetPack = React.useCallback(
67+
const onInstallAssets = React.useCallback(
6868
async (assetShortHeaders: Array<AssetShortHeader>) => {
6969
if (!assetShortHeaders || !assetShortHeaders.length) return;
70-
setIsAssetPackBeingInstalled(true);
70+
setAreAssetsBeingInstalled(true);
7171
try {
7272
const installOutputs = await Promise.all(
7373
assetShortHeaders.map(assetShortHeader =>
@@ -88,14 +88,14 @@ export const AssetPackDialog = ({
8888

8989
await resourcesFetcher.ensureResourcesAreFetched(project);
9090

91-
setIsAssetPackBeingInstalled(false);
92-
onAssetPackAdded();
91+
setAreAssetsBeingInstalled(false);
92+
onAssetsAdded();
9393
} catch (error) {
94-
setIsAssetPackBeingInstalled(false);
95-
console.error('Error while installing the asset pack', error);
94+
setAreAssetsBeingInstalled(false);
95+
console.error('Error while installing the assets', error);
9696
showErrorBox({
9797
message:
98-
'There was an error while installing the asset pack. Verify your internet connection or try again later.',
98+
'There was an error while installing the assets. Verify your internet connection or try again later.',
9999
rawError: error,
100100
errorId: 'install-asset-pack-error',
101101
});
@@ -108,11 +108,11 @@ export const AssetPackDialog = ({
108108
objectsContainer,
109109
events,
110110
onObjectAddedFromAsset,
111-
onAssetPackAdded,
111+
onAssetsAdded,
112112
]
113113
);
114114

115-
const dialogContent = isAssetPackBeingInstalled
115+
const dialogContent = areAssetsBeingInstalled
116116
? {
117117
actionButton: (
118118
<TextButton
@@ -141,15 +141,15 @@ export const AssetPackDialog = ({
141141
key="install-again"
142142
label={<Trans>Install again</Trans>}
143143
primary={false}
144-
onClick={() => onInstallAssetPack(assetShortHeaders)}
144+
onClick={() => onInstallAssets(assetShortHeaders)}
145145
/>
146146
),
147-
onApply: () => onInstallAssetPack(assetShortHeaders),
147+
onApply: () => onInstallAssets(assetShortHeaders),
148148
content: (
149149
<Text>
150150
<Trans>
151-
You already have this asset pack installed, do you want to add the{' '}
152-
{assetShortHeaders.length} assets again?
151+
You already have these {assetShortHeaders.length} assets
152+
installed, do you want to add them again?
153153
</Trans>
154154
</Text>
155155
),
@@ -161,15 +161,14 @@ export const AssetPackDialog = ({
161161
key="continue"
162162
label={<Trans>Continue</Trans>}
163163
primary
164-
onClick={() => onInstallAssetPack(assetShortHeaders)}
164+
onClick={() => onInstallAssets(assetShortHeaders)}
165165
/>
166166
),
167-
onApply: () => onInstallAssetPack(assetShortHeaders),
167+
onApply: () => onInstallAssets(assetShortHeaders),
168168
content: (
169169
<Text>
170170
<Trans>
171-
You're about to add {assetShortHeaders.length} assets from the
172-
asset pack. Continue?
171+
You're about to add {assetShortHeaders.length} assets. Continue?
173172
</Trans>
174173
</Text>
175174
),
@@ -181,24 +180,24 @@ export const AssetPackDialog = ({
181180
key="install-missing"
182181
primary
183182
onClick={() => {
184-
onInstallAssetPack(missingAssetShortHeaders);
183+
onInstallAssets(missingAssetShortHeaders);
185184
}}
186185
buildMenuTemplate={i18n => [
187186
{
188187
label: i18n._(t`Install all the assets`),
189-
click: () => onInstallAssetPack(assetShortHeaders),
188+
click: () => onInstallAssets(assetShortHeaders),
190189
},
191190
]}
192191
/>
193192
),
194-
onApply: () => onInstallAssetPack(missingAssetShortHeaders),
193+
onApply: () => onInstallAssets(missingAssetShortHeaders),
195194
content: (
196195
<Text>
197196
<Trans>
198197
You already have{' '}
199198
{assetShortHeaders.length - missingAssetShortHeaders.length}{' '}
200-
asset(s) from this pack in your scene. Do you want to add the
201-
remaining {missingAssetShortHeaders.length} asset(s)?
199+
asset(s) in your scene. Do you want to add the remaining{' '}
200+
{missingAssetShortHeaders.length} one(s)?
202201
</Trans>
203202
</Text>
204203
),
@@ -210,12 +209,12 @@ export const AssetPackDialog = ({
210209
title={assetPack.name}
211210
open
212211
onRequestClose={() => {
213-
if (!isAssetPackBeingInstalled) onClose();
212+
if (!areAssetsBeingInstalled) onClose();
214213
}}
215214
cannotBeDismissed
216215
actions={[
217-
// Installing a pack is not cancelable, so we hide the button while installing.
218-
!isAssetPackBeingInstalled ? (
216+
// Installing a list of assets is not cancelable, so we hide the button while installing.
217+
!areAssetsBeingInstalled ? (
219218
<TextButton
220219
key="cancel"
221220
label={<Trans>Cancel</Trans>}

newIDE/app/src/AssetStore/index.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ export const AssetStore = ({
100100
isAssetPackDialogInstallOpen,
101101
setIsAssetPackDialogInstallOpen,
102102
] = React.useState(false);
103-
const [isAssetPackAdded, setIsAssetPackAdded] = React.useState(false);
104103
const [
105104
isAssetBeingInstalled,
106105
setIsAssetBeingInstalled,
@@ -235,7 +234,6 @@ export const AssetStore = ({
235234
navigationState.openHome();
236235
clearAllFilters(assetFiltersState);
237236
setIsFiltersPanelOpen(false);
238-
setIsAssetPackAdded(false);
239237
}}
240238
size="small"
241239
>
@@ -280,7 +278,6 @@ export const AssetStore = ({
280278
if (navigationState.getCurrentPage().isOnHomePage) {
281279
clearAllFilters(assetFiltersState);
282280
setIsFiltersPanelOpen(false);
283-
setIsAssetPackAdded(false);
284281
}
285282
}}
286283
/>
@@ -308,17 +305,13 @@ export const AssetStore = ({
308305
<Column expand alignItems="flex-end" noMargin>
309306
<RaisedButton
310307
primary
311-
label={
312-
isAssetPackAdded ? (
313-
<Trans>Asset pack added</Trans>
314-
) : (
315-
<Trans>Add pack to my scene</Trans>
316-
)
317-
}
308+
label={<Trans>Add all assets to my scene</Trans>}
318309
onClick={() =>
319310
setIsAssetPackDialogInstallOpen(true)
320311
}
321-
disabled={isAssetPackAdded}
312+
disabled={
313+
!searchResults || searchResults.length === 0
314+
}
322315
/>
323316
</Column>
324317
</>
@@ -377,9 +370,9 @@ export const AssetStore = ({
377370
>
378371
<AssetStoreFilterPanel
379372
assetFiltersState={assetFiltersState}
380-
onChoiceChange={() =>
381-
navigationState.openSearchIfNeeded()
382-
}
373+
onChoiceChange={() => {
374+
navigationState.openSearchIfNeeded();
375+
}}
383376
/>
384377
</Line>
385378
</ScrollView>
@@ -439,8 +432,7 @@ export const AssetStore = ({
439432
assetShortHeaders={searchResults}
440433
addedAssetIds={addedAssetIds}
441434
onClose={() => setIsAssetPackDialogInstallOpen(false)}
442-
onAssetPackAdded={() => {
443-
setIsAssetPackAdded(true);
435+
onAssetsAdded={() => {
444436
setIsAssetPackDialogInstallOpen(false);
445437
}}
446438
project={project}

0 commit comments

Comments
 (0)