Skip to content

Commit

Permalink
Rename tag function in editor page
Browse files Browse the repository at this point in the history
  • Loading branch information
tbarlow12 authored and wbreza committed Apr 29, 2019
1 parent 996a555 commit 5b4610b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 42 deletions.
54 changes: 13 additions & 41 deletions src/react/components/pages/editorPage/editorPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -309,36 +309,23 @@ export default class EditorPage extends React.Component<IEditorPageProps, IEdito
}

private onTagRenamed = async (tagName: string, newTagName: string): Promise<void> => {
const { project } = this.state;
const { project, selectedAsset } = this.state;
const newProject = {
...project,
tags: project.tags.map((t) => (t.name === tagName) ? {...t, name: newTagName} : t),
};

const assetService = new AssetService(newProject);
const asset = await assetService.renameTag(project.assets, tagName, newTagName, selectedAsset);
this.setState({
project: {
...project,
tags: project.tags.map((t) => (t.name === tagName) ? {...t, name: newTagName} : t),
}
project: newProject,
selectedAsset: asset || selectedAsset,
}, async () => {
await this.props.actions.saveProject(project);
await this.props.actions.saveProject(newProject);
if (this.canvas.current) {
this.canvas.current.updateCanvasToolsRegions();
this.canvas.current.updateCanvasToolsRegions(asset);
}
});

// 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 => {
Expand All @@ -350,7 +337,7 @@ export default class EditorPage extends React.Component<IEditorPageProps, IEdito
const newProject = {
...project,
tags: project.tags.filter((t) => t.name !== tagName),
}
};

const assetService = new AssetService(newProject);
const asset = await assetService.deleteTag(project.assets, tagName, selectedAsset);
Expand All @@ -363,21 +350,6 @@ export default class EditorPage extends React.Component<IEditorPageProps, IEdito
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 => {
Expand Down
2 changes: 1 addition & 1 deletion src/services/assetService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ describe("Asset Service", () => {

beforeAll(() => {
registerMixins();
})
});

it("Deletes tag from assets", async () => {
const tag1 = "tag1";
Expand Down

0 comments on commit 5b4610b

Please sign in to comment.