u
This commit is contained in:
@@ -416,14 +416,12 @@ export default class CategoryTree extends PureComponent {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
if (this.props.categories === undefined || this.props.rootCategoryId === undefined) {
|
||||
this._unsub = categoryAutomat.subscribe((s) => {
|
||||
this.setState({
|
||||
categories: this.props.categories ?? s.categories,
|
||||
rootCategoryId: this.props.rootCategoryId ?? s.rootCategoryId,
|
||||
});
|
||||
this._unsub = categoryAutomat.subscribe((s) => {
|
||||
this.setState({
|
||||
categories: s.categories,
|
||||
rootCategoryId: s.rootCategoryId ?? this.props.rootCategoryId,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
@@ -463,7 +461,14 @@ export default class CategoryTree extends PureComponent {
|
||||
name,
|
||||
});
|
||||
enqueueSnackbar(`Kategorie „${name}“ angelegt.`, { variant: 'success' });
|
||||
this.setState({ addDialogOpen: false });
|
||||
const nextCategories = categoryAutomat.state.categories ?? {
|
||||
...(this.state.categories || {}),
|
||||
[String(created.id)]: created,
|
||||
};
|
||||
this.setState({
|
||||
addDialogOpen: false,
|
||||
categories: nextCategories,
|
||||
});
|
||||
this.props.onSelect?.(created.id, created);
|
||||
} catch (err) {
|
||||
notifyError(err);
|
||||
@@ -489,12 +494,19 @@ export default class CategoryTree extends PureComponent {
|
||||
if (!name || !renameNode) return;
|
||||
this.setState({ isSubmitting: true });
|
||||
try {
|
||||
await categoryAutomat.actions.renameCategory({
|
||||
const updated = await categoryAutomat.actions.renameCategory({
|
||||
categoryId: renameNode.id,
|
||||
name,
|
||||
});
|
||||
enqueueSnackbar(`Kategorie in „${name}“ umbenannt.`, { variant: 'success' });
|
||||
this.setState({ renameDialogOpen: false });
|
||||
const nextCategories = categoryAutomat.state.categories ?? {
|
||||
...(this.state.categories || {}),
|
||||
[String(updated.id)]: updated,
|
||||
};
|
||||
this.setState({
|
||||
renameDialogOpen: false,
|
||||
categories: nextCategories,
|
||||
});
|
||||
} catch (err) {
|
||||
notifyError(err);
|
||||
} finally {
|
||||
@@ -524,7 +536,10 @@ export default class CategoryTree extends PureComponent {
|
||||
if (this.props.selectedId != null && String(this.props.selectedId) === String(deleteNode.id)) {
|
||||
this.props.onSelect?.(deleteNode.parentId ?? rootCategoryId);
|
||||
}
|
||||
this.setState({ deleteDialogOpen: false });
|
||||
this.setState({
|
||||
deleteDialogOpen: false,
|
||||
categories: categoryAutomat.state.categories,
|
||||
});
|
||||
} catch (err) {
|
||||
notifyError(err);
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user