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 tag
This commit is contained in:
Luke Barnard 2017-12-06 11:22:06 +00:00
parent 8178496457
commit 82a95f0793

View File

@ -53,19 +53,24 @@ class TagOrderStore extends Store {
this._setState({allTags: payload.tags});
break;
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;
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.slice(0, tagPrevIx + 1),
...orderedTags.slice(0, newIndex),
payload.tag,
...orderedTags.slice(tagPrevIx + 1),
...orderedTags.slice(newIndex),
];
this._setState({orderedTags});
SettingsStore.setValue("TagOrderStore.orderedTags", null, "account", orderedTags);
}
break;
case 'commit_tags':
SettingsStore.setValue("TagOrderStore.orderedTags", null, "account", this._state.orderedTags);
break;
}
}