Add function to move space shortcut
authorAjay Bura <ajbura@gmail.com>
Tue, 8 Mar 2022 10:59:52 +0000 (16:29 +0530)
committerAjay Bura <ajbura@gmail.com>
Tue, 8 Mar 2022 10:59:52 +0000 (16:29 +0530)
Signed-off-by: Ajay Bura <ajbura@gmail.com>
src/client/action/accountData.js
src/client/state/AccountData.js
src/client/state/cons.js

index cb7a9b4695451d85224d66ab67656869e0c07a60..1fb49fbfe1c102aea0f2ab63af6e4965c039c8c7 100644 (file)
@@ -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,
index 8ac6ae008279fb03a85f50dd1c98df518da8dbbc..6fc811a3910ee6e0e446c4d13fb21ed86981459d 100644 (file)
@@ -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);
index 141cb1fc24cb135fd44f05d2e12a7e1fc41f8692..e00e6521d3f01fd6814a1de6711047d20e19eb96 100644 (file)
@@ -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',
     },