From a7a5b08ad8ee724abefc5be837f5a92240c67562 Mon Sep 17 00:00:00 2001 From: Ajay Bura Date: Tue, 8 Mar 2022 16:29:52 +0530 Subject: [PATCH] Add function to move space shortcut Signed-off-by: Ajay Bura --- src/client/action/accountData.js | 8 ++++++++ src/client/state/AccountData.js | 11 +++++++++++ src/client/state/cons.js | 1 + 3 files changed, 20 insertions(+) diff --git a/src/client/action/accountData.js b/src/client/action/accountData.js index cb7a9b4..1fb49fb 100644 --- a/src/client/action/accountData.js +++ b/src/client/action/accountData.js @@ -18,6 +18,14 @@ export function deleteSpaceShortcut(roomId) { }); } +export function moveSpaceShortcut(roomId, toIndex) { + appDispatcher.dispatch({ + type: cons.actions.accountData.MOVE_SPACE_SHORTCUTS, + roomId, + toIndex, + }); +} + export function categorizeSpace(roomId) { appDispatcher.dispatch({ type: cons.actions.accountData.CATEGORIZE_SPACE, diff --git a/src/client/state/AccountData.js b/src/client/state/AccountData.js index 8ac6ae0..6fc811a 100644 --- a/src/client/state/AccountData.js +++ b/src/client/state/AccountData.js @@ -89,6 +89,17 @@ class AccountData extends EventEmitter { this._updateSpaceShortcutData([...this.spaceShortcut]); this.emit(cons.events.accountData.SPACE_SHORTCUT_UPDATED, action.roomId); }, + [cons.actions.accountData.MOVE_SPACE_SHORTCUTS]: () => { + const { roomId, toIndex } = action; + if (!this.spaceShortcut.has(roomId)) return; + this.spaceShortcut.delete(roomId); + const ssList = [...this.spaceShortcut]; + if (toIndex >= ssList.length) ssList.push(roomId); + else ssList.splice(toIndex, 0, roomId); + this.spaceShortcut = new Set(ssList); + this._updateSpaceShortcutData(ssList); + this.emit(cons.events.accountData.SPACE_SHORTCUT_UPDATED, roomId); + }, [cons.actions.accountData.CATEGORIZE_SPACE]: () => { if (this.categorizedSpaces.has(action.roomId)) return; this.categorizedSpaces.add(action.roomId); diff --git a/src/client/state/cons.js b/src/client/state/cons.js index 141cb1f..e00e652 100644 --- a/src/client/state/cons.js +++ b/src/client/state/cons.js @@ -56,6 +56,7 @@ const cons = { accountData: { CREATE_SPACE_SHORTCUT: 'CREATE_SPACE_SHORTCUT', DELETE_SPACE_SHORTCUT: 'DELETE_SPACE_SHORTCUT', + MOVE_SPACE_SHORTCUTS: 'MOVE_SPACE_SHORTCUTS', CATEGORIZE_SPACE: 'CATEGORIZE_SPACE', UNCATEGORIZE_SPACE: 'UNCATEGORIZE_SPACE', },