Open settings on sidebar user profile click
authorAjay Bura <ajbura@gmail.com>
Sun, 19 Dec 2021 14:35:13 +0000 (20:05 +0530)
committerAjay Bura <ajbura@gmail.com>
Sun, 19 Dec 2021 14:35:13 +0000 (20:05 +0530)
Signed-off-by: Ajay Bura <ajbura@gmail.com>
src/app/molecules/popup-window/PopupWindow.scss
src/app/organisms/navigation/SideBar.jsx
src/app/organisms/settings/Settings.jsx
src/app/organisms/settings/Settings.scss

index e3a588b91761d4f1619d85233d19ab7f935eb538..8dcf22002bd2eac13c1f4f31de84d02949df3e8c 100644 (file)
@@ -70,9 +70,6 @@
 
   & .context-menu__item > button {
     border-radius: var(--bo-radius);
-    & .text {
-      color: var(--tc-surface-normal);
-    }
     & .ic-raw {
       @include dir.side(margin, 0, var(--sp-tight));
     }
index 40328d9248b5afd07a96943c875d1aca1a82f36c..8d587e64eff260e8f86682446ecceffc2c1cc115 100644 (file)
@@ -4,7 +4,6 @@ import './SideBar.scss';
 import initMatrix from '../../../client/initMatrix';
 import cons from '../../../client/state/cons';
 import colorMXID from '../../../util/colorMXID';
-import logout from '../../../client/action/logout';
 import {
   selectTab, openInviteList, openSearch, openSettings,
 } from '../../../client/action/navigation';
@@ -13,14 +12,11 @@ import { abbreviateNumber } from '../../../util/common';
 
 import ScrollView from '../../atoms/scroll/ScrollView';
 import SidebarAvatar from '../../molecules/sidebar-avatar/SidebarAvatar';
-import ContextMenu, { MenuItem, MenuHeader, MenuBorder } from '../../atoms/context-menu/ContextMenu';
 
 import HomeIC from '../../../../public/res/ic/outlined/home.svg';
 import UserIC from '../../../../public/res/ic/outlined/user.svg';
 import SearchIC from '../../../../public/res/ic/outlined/search.svg';
 import InviteIC from '../../../../public/res/ic/outlined/invite.svg';
-import SettingsIC from '../../../../public/res/ic/outlined/settings.svg';
-import PowerIC from '../../../../public/res/ic/outlined/power.svg';
 
 function ProfileAvatarMenu() {
   const mx = initMatrix.matrixClient;
@@ -48,31 +44,12 @@ function ProfileAvatarMenu() {
   }, []);
 
   return (
-    <ContextMenu
-      content={(hideMenu) => (
-        <>
-          <MenuHeader>{mx.getUserId()}</MenuHeader>
-          {/* <MenuItem iconSrc={UserIC} onClick={() => ''}>Profile</MenuItem> */}
-          {/* <MenuItem iconSrc={BellIC} onClick={() => ''}>Notification settings</MenuItem> */}
-          <MenuItem
-            iconSrc={SettingsIC}
-            onClick={() => { hideMenu(); openSettings(); }}
-          >
-            Settings
-          </MenuItem>
-          <MenuBorder />
-          <MenuItem iconSrc={PowerIC} variant="danger" onClick={logout}>Logout</MenuItem>
-        </>
-      )}
-      render={(toggleMenu) => (
-        <SidebarAvatar
-          onClick={toggleMenu}
-          tooltip={profile.displayName}
-          imageSrc={profile.avatarUrl !== null ? mx.mxcUrlToHttp(profile.avatarUrl, 42, 42, 'crop') : null}
-          bgColor={colorMXID(mx.getUserId())}
-          text={profile.displayName}
-        />
-      )}
+    <SidebarAvatar
+      onClick={openSettings}
+      tooltip={profile.displayName}
+      imageSrc={profile.avatarUrl !== null ? mx.mxcUrlToHttp(profile.avatarUrl, 42, 42, 'crop') : null}
+      bgColor={colorMXID(mx.getUserId())}
+      text={profile.displayName}
     />
   );
 }
index 7a075d8c5aef66a3af2adbf2e0a0680999d75c86..e31af8f39f79cda711b04dffd51a3538305b87b8 100644 (file)
@@ -6,6 +6,7 @@ import initMatrix from '../../../client/initMatrix';
 import cons from '../../../client/state/cons';
 import settings from '../../../client/state/settings';
 import { toggleMarkdown, toggleMembershipEvents, toggleNickAvatarEvents } from '../../../client/action/settings';
+import logout from '../../../client/action/logout';
 
 import Text from '../../atoms/text/Text';
 import IconButton from '../../atoms/button/IconButton';
@@ -24,6 +25,7 @@ import SettingsIC from '../../../../public/res/ic/outlined/settings.svg';
 import SunIC from '../../../../public/res/ic/outlined/sun.svg';
 import LockIC from '../../../../public/res/ic/outlined/lock.svg';
 import InfoIC from '../../../../public/res/ic/outlined/info.svg';
+import PowerIC from '../../../../public/res/ic/outlined/power.svg';
 import CrossIC from '../../../../public/res/ic/outlined/cross.svg';
 
 import CinnySVG from '../../../../public/res/svg/cinny.svg';
@@ -177,6 +179,10 @@ function Settings({ isOpen, onRequestClose }) {
   }];
   const [selectedSection, setSelectedSection] = useState(settingSections[0]);
 
+  const handleLogout = () => {
+    if (confirm('Confirm logout')) logout();
+  };
+
   return (
     <PopupWindow
       className="settings-window"
@@ -184,18 +190,29 @@ function Settings({ isOpen, onRequestClose }) {
       onRequestClose={onRequestClose}
       title="Settings"
       contentTitle={selectedSection.name}
-      drawer={
-        settingSections.map((section) => (
+      drawer={(
+        <>
+          {
+            settingSections.map((section) => (
+              <PWContentSelector
+                key={section.name}
+                selected={selectedSection.name === section.name}
+                onClick={() => setSelectedSection(section)}
+                iconSrc={section.iconSrc}
+              >
+                {section.name}
+              </PWContentSelector>
+            ))
+          }
           <PWContentSelector
-            key={section.name}
-            selected={selectedSection.name === section.name}
-            onClick={() => setSelectedSection(section)}
-            iconSrc={section.iconSrc}
+            variant="danger"
+            onClick={handleLogout}
+            iconSrc={PowerIC}
           >
-            {section.name}
+            Logout
           </PWContentSelector>
-        ))
-      }
+        </>
+      )}
       contentOptions={<IconButton src={CrossIC} onClick={onRequestClose} tooltip="Close" />}
     >
       {selectedSection.render()}
index d1435d46c157ba0cd98e4b5563f87b4b1f8f4922..c3ec157c15b57ba8f1ca399e38951ce858488cc5 100644 (file)
@@ -1,6 +1,16 @@
+@use '../../partials/flex';
 @use '../../partials/dir';
 
 .settings-window {
+  & .pw__drawer__content {
+    @extend .cp-fx__column;
+    min-height: 100%;
+    padding-bottom: var(--sp-extra-tight);
+
+    & > .pw-content-selector:last-child {
+      margin-top: auto;
+    }
+  }
   & .pw__content-container {
     min-height: 100%;
   }