Add move action and update orderedData

This commit is contained in:
Saumya Pandey committed 2021-03-04 03:57:25 +05:30
1 parent 3027ae767d
commit 243da7cc05
1 file changed
+12 -1
+12 -1
View File
@@ -1,4 +1,5 @@
// @flow
import invariant from "invariant";
import { concat, filter, last } from "lodash";
import { computed, action } from "mobx";
import naturalSort from "shared/utils/naturalSort";
@@ -34,7 +35,7 @@ export default class CollectionsStore extends BaseStore<Collection> {
@computed
get orderedData(): Collection[] {
return filter(
naturalSort(Array.from(this.data.values()), "name"),
naturalSort(Array.from(this.data.values()), "index"),
(d) => !d.deletedAt
);
}
@@ -95,6 +96,16 @@ export default class CollectionsStore extends BaseStore<Collection> {
});
};
@action
move = async (collectionId: string, index: string) => {
const res = await client.post("/collections.move", {
id: collectionId,
index,
});
invariant(res && res.success, "Collection could not be moved");
this.addPolicies(res.policies);
};
async update(params: Object): Promise<Collection> {
const result = await super.update(params);