From 243da7cc05acc600dbc49ee443fe5d0c01b28ae5 Mon Sep 17 00:00:00 2001 From: Saumya Pandey Date: Thu, 4 Mar 2021 03:57:25 +0530 Subject: [PATCH] Add move action and update orderedData --- app/stores/CollectionsStore.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/stores/CollectionsStore.js b/app/stores/CollectionsStore.js index 6f9c786a50..b09167be7a 100644 --- a/app/stores/CollectionsStore.js +++ b/app/stores/CollectionsStore.js @@ -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 { @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 { }); }; + @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 { const result = await super.update(params);