Skip to content
This repository was archived by the owner on Dec 7, 2021. It is now read-only.

Commit 57f430f

Browse files
tbarlow12wbreza
authored andcommitted
Saving assets in async foreach loop
1 parent f11edfa commit 57f430f

2 files changed

Lines changed: 76 additions & 27 deletions

File tree

src/react/components/pages/editorPage/editorPage.tsx

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export default class EditorPage extends React.Component<IEditorPageProps, IEdito
229229
</div>
230230
<div className="editor-page-right-sidebar">
231231
<TagInput
232-
tags={this.props.project.tags}
232+
tags={this.state.project ? this.state.project.tags : this.props.project.tags}
233233
lockedTags={this.state.lockedTags}
234234
selectedRegions={this.state.selectedRegions}
235235
onChange={this.onTagsChanged}
@@ -309,44 +309,75 @@ export default class EditorPage extends React.Component<IEditorPageProps, IEdito
309309
}
310310

311311
private onTagRenamed = async (tagName: string, newTagName: string): Promise<void> => {
312-
const { project, selectedAsset } = this.state;
313-
const assetService = new AssetService(project);
314-
const asset = await assetService.renameTag(project.assets, tagName, newTagName, selectedAsset);
315-
316-
const newProject: IProject = {
317-
...project,
318-
tags: project.tags.map((t) => (t.name === tagName) ? {...t, name: newTagName} : t),
319-
};
312+
const { project } = this.state;
320313
this.setState({
321-
project: newProject,
322-
selectedAsset: asset || selectedAsset,
314+
project: {
315+
...project,
316+
tags: project.tags.map((t) => (t.name === tagName) ? {...t, name: newTagName} : t),
317+
}
323318
}, async () => {
324-
await this.props.actions.saveProject(newProject);
325-
if (asset) {
326-
this.canvas.current.updateCanvasToolsRegions(asset);
319+
await this.props.actions.saveProject(project);
320+
if (this.canvas.current) {
321+
this.canvas.current.updateCanvasToolsRegions();
327322
}
328323
});
324+
325+
// const { project, selectedAsset } = this.state;
326+
// const assetService = new AssetService(project);
327+
// const asset = await assetService.renameTag(project.assets, tagName, newTagName, selectedAsset);
328+
329+
// const newProject: IProject = {
330+
// ...project,
331+
// tags: project.tags.map((t) => (t.name === tagName) ? {...t, name: newTagName} : t),
332+
// };
333+
// this.setState({
334+
// project: newProject,
335+
// selectedAsset: asset || selectedAsset,
336+
// }, async () => {
337+
// await this.props.actions.saveProject(newProject);
338+
// if (asset) {
339+
// this.canvas.current.updateCanvasToolsRegions(asset);
340+
// }
341+
// });
329342
}
330343

331344
private confirmTagDeleted = (tagName: string): void => {
332345
this.deleteTagConfirm.current.open(tagName);
333346
}
334347

335348
private onTagDeleted = async (tagName: string): Promise<void> => {
336-
const { selectedAsset } = this.state;
337-
const { project } = this.props;
338-
const newProject: IProject = {
349+
const { project, selectedAsset } = this.state;
350+
const newProject = {
339351
...project,
340352
tags: project.tags.filter((t) => t.name !== tagName),
341-
};
342-
await this.props.actions.saveProject(newProject);
353+
}
343354

344-
const assetService = new AssetService(project);
355+
const assetService = new AssetService(newProject);
345356
const asset = await assetService.deleteTag(project.assets, tagName, selectedAsset);
346-
if (asset) {
347-
this.canvas.current.updateCanvasToolsRegions(asset);
348-
this.setState({selectedAsset: asset});
349-
}
357+
this.setState({
358+
project: newProject,
359+
selectedAsset: asset || selectedAsset,
360+
}, async () => {
361+
await this.props.actions.saveProject(newProject);
362+
if (this.canvas.current) {
363+
this.canvas.current.updateCanvasToolsRegions(asset);
364+
}
365+
});
366+
367+
// const { selectedAsset } = this.state;
368+
// const { project } = this.props;
369+
// const newProject: IProject = {
370+
// ...project,
371+
// tags: project.tags.filter((t) => t.name !== tagName),
372+
// };
373+
// await this.props.actions.saveProject(newProject);
374+
375+
// const assetService = new AssetService(project);
376+
// const asset = await assetService.deleteTag(project.assets, tagName, selectedAsset);
377+
// if (asset) {
378+
// this.canvas.current.updateCanvasToolsRegions(asset);
379+
// this.setState({selectedAsset: asset});
380+
// }
350381
}
351382

352383
private onCtrlTagClicked = (tag: ITag): void => {

src/services/assetService.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,33 @@ export class AssetService {
251251
// Loop over assets and update if necessary
252252
await assetKeys.forEachAsync(async (assetKey) => {
253253
const asset = assets[assetKey];
254-
if (asset.state !== AssetState.Tagged) {
255-
return;
256-
}
257254
const assetMetadata = await this.getAssetMetadata(asset);
258255
const updatedAssetMetadata = this.updateTagInAssetMetadata(assetMetadata, tagName, transformer);
259256
if (updatedAssetMetadata) {
260257
await this.save(updatedAssetMetadata);
261258
}
262259
});
260+
261+
// for (const assetKey of assetKeys) {
262+
// const asset = assets[assetKey];
263+
// if (asset.state !== AssetState.Tagged) {
264+
// debugger;
265+
// return;
266+
// }
267+
// const assetMetadata = await this.getAssetMetadata(asset);
268+
// debugger;
269+
// const updatedAssetMetadata = this.updateTagInAssetMetadata(assetMetadata, tagName, transformer);
270+
// debugger;
271+
// if (updatedAssetMetadata) {
272+
// await this.save(updatedAssetMetadata);
273+
// }
274+
// }
275+
276+
if (currentAsset) {
277+
const asset = this.updateTagInAssetMetadata(currentAsset, tagName, transformer);
278+
debugger;
279+
return asset;
280+
}
263281
}
264282

265283
/**

0 commit comments

Comments
 (0)