diff --git a/src/react/components/pages/editorPage/editorPage.tsx b/src/react/components/pages/editorPage/editorPage.tsx index afbad529e7..5ebcbe5b86 100644 --- a/src/react/components/pages/editorPage/editorPage.tsx +++ b/src/react/components/pages/editorPage/editorPage.tsx @@ -229,7 +229,7 @@ export default class EditorPage extends React.Component
=> { - const { project, selectedAsset } = this.state; - const assetService = new AssetService(project); - const asset = await assetService.renameTag(project.assets, tagName, newTagName, selectedAsset); - - const newProject: IProject = { - ...project, - tags: project.tags.map((t) => (t.name === tagName) ? {...t, name: newTagName} : t), - }; + const { project } = this.state; this.setState({ - project: newProject, - selectedAsset: asset || selectedAsset, + project: { + ...project, + tags: project.tags.map((t) => (t.name === tagName) ? {...t, name: newTagName} : t), + } }, async () => { - await this.props.actions.saveProject(newProject); - if (asset) { - this.canvas.current.updateCanvasToolsRegions(asset); + await this.props.actions.saveProject(project); + if (this.canvas.current) { + this.canvas.current.updateCanvasToolsRegions(); } }); + + // const { project, selectedAsset } = this.state; + // const assetService = new AssetService(project); + // const asset = await assetService.renameTag(project.assets, tagName, newTagName, selectedAsset); + + // const newProject: IProject = { + // ...project, + // tags: project.tags.map((t) => (t.name === tagName) ? {...t, name: newTagName} : t), + // }; + // this.setState({ + // project: newProject, + // selectedAsset: asset || selectedAsset, + // }, async () => { + // await this.props.actions.saveProject(newProject); + // if (asset) { + // this.canvas.current.updateCanvasToolsRegions(asset); + // } + // }); } private confirmTagDeleted = (tagName: string): void => { @@ -333,20 +346,38 @@ export default class EditorPage extends React.Component => { - const { selectedAsset } = this.state; - const { project } = this.props; - const newProject: IProject = { + const { project, selectedAsset } = this.state; + const newProject = { ...project, tags: project.tags.filter((t) => t.name !== tagName), - }; - await this.props.actions.saveProject(newProject); + } - const assetService = new AssetService(project); + const assetService = new AssetService(newProject); const asset = await assetService.deleteTag(project.assets, tagName, selectedAsset); - if (asset) { - this.canvas.current.updateCanvasToolsRegions(asset); - this.setState({selectedAsset: asset}); - } + this.setState({ + project: newProject, + selectedAsset: asset || selectedAsset, + }, async () => { + await this.props.actions.saveProject(newProject); + if (this.canvas.current) { + this.canvas.current.updateCanvasToolsRegions(asset); + } + }); + + // const { selectedAsset } = this.state; + // const { project } = this.props; + // const newProject: IProject = { + // ...project, + // tags: project.tags.filter((t) => t.name !== tagName), + // }; + // await this.props.actions.saveProject(newProject); + + // const assetService = new AssetService(project); + // const asset = await assetService.deleteTag(project.assets, tagName, selectedAsset); + // if (asset) { + // this.canvas.current.updateCanvasToolsRegions(asset); + // this.setState({selectedAsset: asset}); + // } } private onCtrlTagClicked = (tag: ITag): void => { diff --git a/src/services/assetService.ts b/src/services/assetService.ts index 8ec2fe5386..53d05087f0 100644 --- a/src/services/assetService.ts +++ b/src/services/assetService.ts @@ -251,15 +251,33 @@ export class AssetService { // Loop over assets and update if necessary await assetKeys.forEachAsync(async (assetKey) => { const asset = assets[assetKey]; - if (asset.state !== AssetState.Tagged) { - return; - } const assetMetadata = await this.getAssetMetadata(asset); const updatedAssetMetadata = this.updateTagInAssetMetadata(assetMetadata, tagName, transformer); if (updatedAssetMetadata) { await this.save(updatedAssetMetadata); } }); + + // for (const assetKey of assetKeys) { + // const asset = assets[assetKey]; + // if (asset.state !== AssetState.Tagged) { + // debugger; + // return; + // } + // const assetMetadata = await this.getAssetMetadata(asset); + // debugger; + // const updatedAssetMetadata = this.updateTagInAssetMetadata(assetMetadata, tagName, transformer); + // debugger; + // if (updatedAssetMetadata) { + // await this.save(updatedAssetMetadata); + // } + // } + + if (currentAsset) { + const asset = this.updateTagInAssetMetadata(currentAsset, tagName, transformer); + debugger; + return asset; + } } /**