Simplify order_tag in TagOrderStore
such that: - it takes a targetTag to be replaced instead the previous tag to insert after - it optionally displaces the targetTag before or after the inserted tagpull/21833/head
parent
8178496457
commit
82a95f0793
|
@ -53,19 +53,24 @@ class TagOrderStore extends Store {
|
||||||
this._setState({allTags: payload.tags});
|
this._setState({allTags: payload.tags});
|
||||||
break;
|
break;
|
||||||
case 'order_tag': {
|
case 'order_tag': {
|
||||||
// Puts payload.tag below payload.prevTag in the orderedTags state
|
if (!payload.tag || !payload.targetTag || payload.tag === payload.targetTag) break;
|
||||||
|
|
||||||
|
// Puts payload.tag at payload.targetTag, placing the targetTag before or after the tag
|
||||||
const tags = SettingsStore.getValue("TagOrderStore.orderedTags") || this._state.allTags;
|
const tags = SettingsStore.getValue("TagOrderStore.orderedTags") || this._state.allTags;
|
||||||
|
|
||||||
let orderedTags = tags.filter((t) => t !== payload.tag);
|
let orderedTags = tags.filter((t) => t !== payload.tag);
|
||||||
const tagPrevIx = orderedTags.indexOf(payload.prevTag);
|
const newIndex = orderedTags.indexOf(payload.targetTag) + (payload.after ? 1 : 0);
|
||||||
orderedTags = [
|
orderedTags = [
|
||||||
...orderedTags.slice(0, tagPrevIx + 1),
|
...orderedTags.slice(0, newIndex),
|
||||||
payload.tag,
|
payload.tag,
|
||||||
...orderedTags.slice(tagPrevIx + 1),
|
...orderedTags.slice(newIndex),
|
||||||
];
|
];
|
||||||
this._setState({orderedTags});
|
this._setState({orderedTags});
|
||||||
SettingsStore.setValue("TagOrderStore.orderedTags", null, "account", orderedTags);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'commit_tags':
|
||||||
|
SettingsStore.setValue("TagOrderStore.orderedTags", null, "account", this._state.orderedTags);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue