From 4ec770da6395d87a97172b8fda1f4842d3b24346 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 8 Aug 2021 10:23:26 +0530 Subject: [PATCH] added search term ability in InviteUser component --- src/app/organisms/invite-user/InviteUser.jsx | 53 +++++++++++--------- src/app/organisms/pw/Windows.jsx | 8 ++- src/client/action/navigation.js | 3 +- src/client/state/navigation.js | 2 +- 4 files changed, 39 insertions(+), 27 deletions(-) diff --git a/src/app/organisms/invite-user/InviteUser.jsx b/src/app/organisms/invite-user/InviteUser.jsx index 251ffdf..0a4a04d 100644 --- a/src/app/organisms/invite-user/InviteUser.jsx +++ b/src/app/organisms/invite-user/InviteUser.jsx @@ -18,7 +18,9 @@ import ChannelTile from '../../molecules/channel-tile/ChannelTile'; import CrossIC from '../../../../public/res/ic/outlined/cross.svg'; import UserIC from '../../../../public/res/ic/outlined/user.svg'; -function InviteUser({ isOpen, roomId, onRequestClose }) { +function InviteUser({ + isOpen, roomId, searchTerm, onRequestClose, +}) { const [isSearching, updateIsSearching] = useState(false); const [searchQuery, updateSearchQuery] = useState({}); const [users, updateUsers] = useState([]); @@ -63,26 +65,8 @@ function InviteUser({ isOpen, roomId, onRequestClose }) { updateRoomIdToUserId(getMapCopy(roomIdToUserId)); } - useEffect(() => () => { - updateIsSearching(false); - updateSearchQuery({}); - updateUsers([]); - updateProcUsers(new Set()); - updateUserProcError(new Map()); - updateCreatedDM(new Map()); - updateRoomIdToUserId(new Map()); - updateInvitedUserIds(new Set()); - }, [isOpen]); - - useEffect(() => { - initMatrix.roomList.on(cons.events.roomList.ROOM_CREATED, onDMCreated); - return () => { - initMatrix.roomList.removeListener(cons.events.roomList.ROOM_CREATED, onDMCreated); - }; - }, [isOpen, procUsers, createdDM, roomIdToUserId]); - - async function searchUser() { - const inputUsername = usernameRef.current.value.trim(); + async function searchUser(username) { + const inputUsername = username.trim(); if (isSearching || inputUsername === '' || inputUsername === searchQuery.username) return; const isInputUserId = inputUsername[0] === '@' && inputUsername.indexOf(':') > 1; updateIsSearching(true); @@ -216,6 +200,27 @@ function InviteUser({ isOpen, roomId, onRequestClose }) { }); } + useEffect(() => { + if (isOpen && typeof searchTerm === 'string') searchUser(searchTerm); + return () => { + updateIsSearching(false); + updateSearchQuery({}); + updateUsers([]); + updateProcUsers(new Set()); + updateUserProcError(new Map()); + updateCreatedDM(new Map()); + updateRoomIdToUserId(new Map()); + updateInvitedUserIds(new Set()); + }; + }, [isOpen, searchTerm]); + + useEffect(() => { + initMatrix.roomList.on(cons.events.roomList.ROOM_CREATED, onDMCreated); + return () => { + initMatrix.roomList.removeListener(cons.events.roomList.ROOM_CREATED, onDMCreated); + }; + }, [isOpen, procUsers, createdDM, roomIdToUserId]); + return (
-
{ e.preventDefault(); searchUser(); }}> - + { e.preventDefault(); searchUser(usernameRef.current.value); }}> +
@@ -258,11 +263,13 @@ function InviteUser({ isOpen, roomId, onRequestClose }) { InviteUser.defaultProps = { roomId: undefined, + searchTerm: undefined, }; InviteUser.propTypes = { isOpen: PropTypes.bool.isRequired, roomId: PropTypes.string, + searchTerm: PropTypes.string, onRequestClose: PropTypes.func.isRequired, }; diff --git a/src/app/organisms/pw/Windows.jsx b/src/app/organisms/pw/Windows.jsx index a6b5b0d..851ed9a 100644 --- a/src/app/organisms/pw/Windows.jsx +++ b/src/app/organisms/pw/Windows.jsx @@ -13,7 +13,9 @@ function Windows() { const [isInviteList, changeInviteList] = useState(false); const [isPubilcChannels, changePubilcChannels] = useState(false); const [isCreateChannel, changeCreateChannel] = useState(false); - const [inviteUser, changeInviteUser] = useState({ isOpen: false, roomId: undefined }); + const [inviteUser, changeInviteUser] = useState({ + isOpen: false, roomId: undefined, term: undefined, + }); const [settings, changeSettings] = useState(false); function openInviteList() { @@ -25,10 +27,11 @@ function Windows() { function openCreateChannel() { changeCreateChannel(true); } - function openInviteUser(roomId) { + function openInviteUser(roomId, searchTerm) { changeInviteUser({ isOpen: true, roomId, + searchTerm, }); } function openSettings() { @@ -67,6 +70,7 @@ function Windows() { changeInviteUser({ isOpen: false, roomId: undefined })} /> { - this.emit(cons.events.navigation.INVITE_USER_OPENED, action.roomId); + this.emit(cons.events.navigation.INVITE_USER_OPENED, action.roomId, action.searchTerm); }, [cons.actions.navigation.OPEN_SETTINGS]: () => { this.emit(cons.events.navigation.SETTINGS_OPENED);