Add globe icons in search
authorAjay Bura <ajbura@gmail.com>
Wed, 5 Jan 2022 12:17:41 +0000 (17:47 +0530)
committerAjay Bura <ajbura@gmail.com>
Wed, 5 Jan 2022 12:17:41 +0000 (17:47 +0530)
Signed-off-by: Ajay Bura <ajbura@gmail.com>
src/app/organisms/navigation/Selector.jsx
src/app/organisms/search/Search.jsx

index b54f1a6124bdf6c8b1bd1a961aff2e6b04af470e..80a035743c92254dc07a4749feb65175d3c6e2e7 100644 (file)
@@ -49,11 +49,11 @@ function Selector({
     };
   }, []);
 
-  const joinRuleToIconSrc = {
+  const joinRuleToIconSrc = (joinRule) => ({
     restricted: () => (room.isSpaceRoom() ? SpaceIC : HashIC),
     invite: () => (room.isSpaceRoom() ? SpaceLockIC : HashLockIC),
     public: () => (room.isSpaceRoom() ? SpaceGlobeIC : HashGlobeIC),
-  };
+  }[joinRule]?.() || null);
 
   if (room.isSpaceRoom()) {
     return (
@@ -61,7 +61,7 @@ function Selector({
         key={roomId}
         name={room.name}
         roomId={roomId}
-        iconSrc={joinRuleToIconSrc[room.getJoinRule()]?.() || null}
+        iconSrc={joinRuleToIconSrc(room.getJoinRule())}
         isUnread={noti.hasNoti(roomId)}
         notificationCount={abbreviateNumber(noti.getTotalNoti(roomId))}
         isAlert={noti.getHighlightNoti(roomId) !== 0}
@@ -90,7 +90,7 @@ function Selector({
       name={room.name}
       roomId={roomId}
       imageSrc={isDM ? imageSrc : null}
-      iconSrc={isDM ? null : joinRuleToIconSrc[room.getJoinRule()]?.() || null}
+      iconSrc={isDM ? null : joinRuleToIconSrc(room.getJoinRule())}
       isSelected={isSelected}
       isUnread={noti.hasNoti(roomId)}
       notificationCount={abbreviateNumber(noti.getTotalNoti(roomId))}
index b03c8016186844299816f58ee33b60577bbd4c3f..2a707424a7149681080a372959f0b3cf368fcde7 100644 (file)
@@ -17,8 +17,10 @@ import RoomSelector from '../../molecules/room-selector/RoomSelector';
 
 import SearchIC from '../../../../public/res/ic/outlined/search.svg';
 import HashIC from '../../../../public/res/ic/outlined/hash.svg';
+import HashGlobeIC from '../../../../public/res/ic/outlined/hash-globe.svg';
 import HashLockIC from '../../../../public/res/ic/outlined/hash-lock.svg';
 import SpaceIC from '../../../../public/res/ic/outlined/space.svg';
+import SpaceGlobeIC from '../../../../public/res/ic/outlined/space-globe.svg';
 import SpaceLockIC from '../../../../public/res/ic/outlined/space-lock.svg';
 import CrossIC from '../../../../public/res/ic/outlined/cross.svg';
 
@@ -176,12 +178,18 @@ function Search() {
 
   const notifs = initMatrix.notifications;
   const renderRoomSelector = (item) => {
-    const isPrivate = item.room.getJoinRule() === 'invite';
     let imageSrc = null;
     let iconSrc = null;
-    if (item.type === 'room') iconSrc = isPrivate ? HashLockIC : HashIC;
-    if (item.type === 'space') iconSrc = isPrivate ? SpaceLockIC : SpaceIC;
-    if (item.type === 'direct') imageSrc = item.room.getAvatarFallbackMember()?.getAvatarUrl(mx.baseUrl, 24, 24, 'crop') || null;
+    if (item.type === 'direct') {
+      imageSrc = item.room.getAvatarFallbackMember()?.getAvatarUrl(mx.baseUrl, 24, 24, 'crop') || null;
+    } else {
+      const joinRuleToIconSrc = (joinRule) => ({
+        restricted: () => (item.type === 'space' ? SpaceIC : HashIC),
+        invite: () => (item.type === 'space' ? SpaceLockIC : HashLockIC),
+        public: () => (item.type === 'space' ? SpaceGlobeIC : HashGlobeIC),
+      }[joinRule]?.() || null);
+      iconSrc = joinRuleToIconSrc(item.room.getJoinRule());
+    }
 
     const isUnread = notifs.hasNoti(item.roomId);
     const noti = notifs.getNoti(item.roomId);