From 06cea95ec9463f1c010187973f401a68cce7b68d Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Wed, 13 Jan 2021 02:59:52 -0500 Subject: [TMA-556] Temporary Fix for Re-ordering Categories (#178) * done * moved icon placement and added correct asset * new icons * moved things around resolved a bug * Deleting existing predefined moment categories * Revert "Deleting existing predefined moment categories" This reverts commit f5f4464b5392902208ec548de1c189f4639261a5. * Hit backend Co-authored-by: Shravya Ramesh Co-authored-by: Ashm Walia Co-authored-by: Ashm Walia <40498934+ashmgarv@users.noreply.github.com> --- src/utils/common.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/utils/common.ts') diff --git a/src/utils/common.ts b/src/utils/common.ts index f13181c1..dbe8f270 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -48,6 +48,22 @@ export const getDateAge: ( } }; +export const moveCategory: ( + categories: string[], + category: string, + moveUp: boolean, +) => string[] = (categories, category, moveUp) => { + const i = categories.indexOf(category); + const swapTarget = moveUp ? i - 1 : i + 1; + if ((moveUp && i === 0) || (!moveUp && i > categories.length)) { + return categories; + } + const tmp = categories[i]; + categories[i] = categories[swapTarget]; + categories[swapTarget] = tmp; + return categories; +}; + export const checkImageUploadStatus = (statusMap: object) => { for (let [key, value] of Object.entries(statusMap)) { if (value != 'Success') { -- cgit v1.2.3-70-g09d2