1
Fork 0

Properly remove user labels.

This commit is contained in:
Bauke 2023-06-28 15:03:35 +02:00
parent df09098f89
commit 126960ba82
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
2 changed files with 20 additions and 10 deletions

View File

@ -312,8 +312,10 @@ export class UserLabelsFeature extends Component<Props, State> {
value.remove();
}
userLabels.splice(index, 1);
await saveUserLabels(userLabels);
for (const userLabel of userLabels.splice(index, 1)) {
await userLabel.remove();
}
this.props.userLabels = userLabels;
this.hide();
};

View File

@ -30,6 +30,7 @@ type State = {
hasUnsavedChanges: boolean;
newLabelUsername: string;
userLabels: UserLabelsData;
userLabelsToRemove: UserLabelsData;
};
class App extends Component<Props, State> {
@ -40,6 +41,7 @@ class App extends Component<Props, State> {
hasUnsavedChanges: false,
newLabelUsername: "",
userLabels: props.userLabels,
userLabelsToRemove: [],
};
}
@ -99,20 +101,26 @@ class App extends Component<Props, State> {
});
};
removeUserLabel = (targetId: number) => {
const userLabels = this.state.userLabels.filter(
({value: {id}}) => id !== targetId,
);
removeUserLabel = async (targetId: number) => {
const {userLabels, userLabelsToRemove} = this.state;
const index = userLabels.findIndex(({value}) => value.id === targetId);
userLabelsToRemove.push(...userLabels.splice(index, 1));
this.setState({
hasUnsavedChanges: true,
userLabels,
userLabelsToRemove,
});
};
saveUserLabels = () => {
saveUserLabels = async () => {
for (const userLabel of this.state.userLabelsToRemove) {
await userLabel.remove();
}
this.props.userLabels = this.state.userLabels;
void saveUserLabels(this.props.userLabels);
this.setState({hasUnsavedChanges: false});
this.setState({hasUnsavedChanges: false, userLabelsToRemove: []});
};
render() {
@ -155,8 +163,8 @@ class App extends Component<Props, State> {
this.editUserLabel(event, label.id, "priority");
};
const removeHandler = () => {
this.removeUserLabel(label.id);
const removeHandler = async () => {
await this.removeUserLabel(label.id);
};
userLabels.push(