added search term ability in PublicChannels component

This commit is contained in:
unknown 2021-08-08 14:45:21 +05:30
parent 6586f933ff
commit e1a0acdf4a
4 changed files with 22 additions and 10 deletions

View file

@ -84,7 +84,7 @@ TryJoinWithAlias.propTypes = {
onRequestClose: PropTypes.func.isRequired, onRequestClose: PropTypes.func.isRequired,
}; };
function PublicChannels({ isOpen, onRequestClose }) { function PublicChannels({ isOpen, searchTerm, onRequestClose }) {
const [isSearching, updateIsSearching] = useState(false); const [isSearching, updateIsSearching] = useState(false);
const [isViewMore, updateIsViewMore] = useState(false); const [isViewMore, updateIsViewMore] = useState(false);
const [publicChannels, updatePublicChannels] = useState([]); const [publicChannels, updatePublicChannels] = useState([]);
@ -97,7 +97,7 @@ function PublicChannels({ isOpen, onRequestClose }) {
const userId = initMatrix.matrixClient.getUserId(); const userId = initMatrix.matrixClient.getUserId();
async function searchChannels(viewMore) { async function searchChannels(viewMore) {
let inputChannelName = channelNameRef?.current?.value; let inputChannelName = channelNameRef?.current?.value || searchTerm;
let isInputAlias = false; let isInputAlias = false;
if (typeof inputChannelName === 'string') { if (typeof inputChannelName === 'string') {
isInputAlias = inputChannelName[0] === '#' && inputChannelName.indexOf(':') > 1; isInputAlias = inputChannelName[0] === '#' && inputChannelName.indexOf(':') > 1;
@ -214,7 +214,7 @@ function PublicChannels({ isOpen, onRequestClose }) {
<div className="public-channels"> <div className="public-channels">
<form className="public-channels__form" onSubmit={(e) => { e.preventDefault(); searchChannels(); }}> <form className="public-channels__form" onSubmit={(e) => { e.preventDefault(); searchChannels(); }}>
<div className="public-channels__input-wrapper"> <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 /> <Input forwardRef={hsRef} value={userId.slice(userId.indexOf(':') + 1)} label="Homeserver" required />
</div> </div>
<Button disabled={isSearching} iconSrc={HashSearchIC} variant="primary" type="submit">Search</Button> <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 = { PublicChannels.propTypes = {
isOpen: PropTypes.bool.isRequired, isOpen: PropTypes.bool.isRequired,
searchTerm: PropTypes.string,
onRequestClose: PropTypes.func.isRequired, onRequestClose: PropTypes.func.isRequired,
}; };

View file

@ -11,7 +11,9 @@ import Settings from '../settings/Settings';
function Windows() { function Windows() {
const [isInviteList, changeInviteList] = useState(false); const [isInviteList, changeInviteList] = useState(false);
const [isPubilcChannels, changePubilcChannels] = useState(false); const [publicChannels, changePublicChannels] = useState({
isOpen: false, searchTerm: undefined,
});
const [isCreateChannel, changeCreateChannel] = useState(false); const [isCreateChannel, changeCreateChannel] = useState(false);
const [inviteUser, changeInviteUser] = useState({ const [inviteUser, changeInviteUser] = useState({
isOpen: false, roomId: undefined, term: undefined, isOpen: false, roomId: undefined, term: undefined,
@ -21,8 +23,11 @@ function Windows() {
function openInviteList() { function openInviteList() {
changeInviteList(true); changeInviteList(true);
} }
function openPublicChannels() { function openPublicChannels(searchTerm) {
changePubilcChannels(true); changePublicChannels({
isOpen: true,
searchTerm,
});
} }
function openCreateChannel() { function openCreateChannel() {
changeCreateChannel(true); changeCreateChannel(true);
@ -60,8 +65,9 @@ function Windows() {
onRequestClose={() => changeInviteList(false)} onRequestClose={() => changeInviteList(false)}
/> />
<PublicChannels <PublicChannels
isOpen={isPubilcChannels} isOpen={publicChannels.isOpen}
onRequestClose={() => changePubilcChannels(false)} searchTerm={publicChannels.searchTerm}
onRequestClose={() => changePublicChannels({ isOpen: false, searchTerm: undefined })}
/> />
<CreateChannel <CreateChannel
isOpen={isCreateChannel} isOpen={isCreateChannel}

View file

@ -27,9 +27,10 @@ function openInviteList() {
}); });
} }
function openPublicChannels() { function openPublicChannels(searchTerm) {
appDispatcher.dispatch({ appDispatcher.dispatch({
type: cons.actions.navigation.OPEN_PUBLIC_CHANNELS, type: cons.actions.navigation.OPEN_PUBLIC_CHANNELS,
searchTerm,
}); });
} }

View file

@ -37,7 +37,7 @@ class Navigation extends EventEmitter {
this.emit(cons.events.navigation.INVITE_LIST_OPENED); this.emit(cons.events.navigation.INVITE_LIST_OPENED);
}, },
[cons.actions.navigation.OPEN_PUBLIC_CHANNELS]: () => { [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]: () => { [cons.actions.navigation.OPEN_CREATE_CHANNEL]: () => {
this.emit(cons.events.navigation.CREATE_CHANNEL_OPENED); this.emit(cons.events.navigation.CREATE_CHANNEL_OPENED);