added search term ability in PublicChannels component
authorunknown <ajbura@gmail.com>
Sun, 8 Aug 2021 09:15:21 +0000 (14:45 +0530)
committerunknown <ajbura@gmail.com>
Sun, 8 Aug 2021 09:15:21 +0000 (14:45 +0530)
src/app/organisms/public-channels/PublicChannels.jsx
src/app/organisms/pw/Windows.jsx
src/client/action/navigation.js
src/client/state/navigation.js

index 2f02ba0f139344715d432e7afbdf50270bff9b0c..624ea4834ef33888e0fbf2690f66f82139c2bdee 100644 (file)
@@ -84,7 +84,7 @@ TryJoinWithAlias.propTypes = {
   onRequestClose: PropTypes.func.isRequired,
 };
 
-function PublicChannels({ isOpen, onRequestClose }) {
+function PublicChannels({ isOpen, searchTerm, onRequestClose }) {
   const [isSearching, updateIsSearching] = useState(false);
   const [isViewMore, updateIsViewMore] = useState(false);
   const [publicChannels, updatePublicChannels] = useState([]);
@@ -97,7 +97,7 @@ function PublicChannels({ isOpen, onRequestClose }) {
   const userId = initMatrix.matrixClient.getUserId();
 
   async function searchChannels(viewMore) {
-    let inputChannelName = channelNameRef?.current?.value;
+    let inputChannelName = channelNameRef?.current?.value || searchTerm;
     let isInputAlias = false;
     if (typeof inputChannelName === 'string') {
       isInputAlias = inputChannelName[0] === '#' && inputChannelName.indexOf(':') > 1;
@@ -214,7 +214,7 @@ function PublicChannels({ isOpen, onRequestClose }) {
       <div className="public-channels">
         <form className="public-channels__form" onSubmit={(e) => { e.preventDefault(); searchChannels(); }}>
           <div className="public-channels__input-wrapper">
-            <Input forwardRef={channelNameRef} label="Channel name or alias" />
+            <Input value={searchTerm} forwardRef={channelNameRef} label="Channel name or alias" />
             <Input forwardRef={hsRef} value={userId.slice(userId.indexOf(':') + 1)} label="Homeserver" required />
           </div>
           <Button disabled={isSearching} iconSrc={HashSearchIC} variant="primary" type="submit">Search</Button>
@@ -271,8 +271,13 @@ function PublicChannels({ isOpen, onRequestClose }) {
   );
 }
 
+PublicChannels.defaultProps = {
+  searchTerm: undefined,
+};
+
 PublicChannels.propTypes = {
   isOpen: PropTypes.bool.isRequired,
+  searchTerm: PropTypes.string,
   onRequestClose: PropTypes.func.isRequired,
 };
 
index 851ed9a2574e229ecaf1236c30961f8f004bc4e7..8a0afd3d3679f2c93559f61681d94269bb9f5521 100644 (file)
@@ -11,7 +11,9 @@ import Settings from '../settings/Settings';
 
 function Windows() {
   const [isInviteList, changeInviteList] = useState(false);
-  const [isPubilcChannels, changePubilcChannels] = useState(false);
+  const [publicChannels, changePublicChannels] = useState({
+    isOpen: false, searchTerm: undefined,
+  });
   const [isCreateChannel, changeCreateChannel] = useState(false);
   const [inviteUser, changeInviteUser] = useState({
     isOpen: false, roomId: undefined, term: undefined,
@@ -21,8 +23,11 @@ function Windows() {
   function openInviteList() {
     changeInviteList(true);
   }
-  function openPublicChannels() {
-    changePubilcChannels(true);
+  function openPublicChannels(searchTerm) {
+    changePublicChannels({
+      isOpen: true,
+      searchTerm,
+    });
   }
   function openCreateChannel() {
     changeCreateChannel(true);
@@ -60,8 +65,9 @@ function Windows() {
         onRequestClose={() => changeInviteList(false)}
       />
       <PublicChannels
-        isOpen={isPubilcChannels}
-        onRequestClose={() => changePubilcChannels(false)}
+        isOpen={publicChannels.isOpen}
+        searchTerm={publicChannels.searchTerm}
+        onRequestClose={() => changePublicChannels({ isOpen: false, searchTerm: undefined })}
       />
       <CreateChannel
         isOpen={isCreateChannel}
index 4f356c7283a9df58f23ceae3431420c64690575b..79bde0a0a087aa8787ea16bf06b7fe99a4c9a5ac 100644 (file)
@@ -27,9 +27,10 @@ function openInviteList() {
   });
 }
 
-function openPublicChannels() {
+function openPublicChannels(searchTerm) {
   appDispatcher.dispatch({
     type: cons.actions.navigation.OPEN_PUBLIC_CHANNELS,
+    searchTerm,
   });
 }
 
index f8549e08383a78bf648bfa26b4bc73aab61e6672..af89cd9fd902768c0608012a328e901fe416fb6a 100644 (file)
@@ -37,7 +37,7 @@ class Navigation extends EventEmitter {
         this.emit(cons.events.navigation.INVITE_LIST_OPENED);
       },
       [cons.actions.navigation.OPEN_PUBLIC_CHANNELS]: () => {
-        this.emit(cons.events.navigation.PUBLIC_CHANNELS_OPENED);
+        this.emit(cons.events.navigation.PUBLIC_CHANNELS_OPENED, action.searchTerm);
       },
       [cons.actions.navigation.OPEN_CREATE_CHANNEL]: () => {
         this.emit(cons.events.navigation.CREATE_CHANNEL_OPENED);