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,
};
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,
};

View 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}

View file

@ -27,9 +27,10 @@ function openInviteList() {
});
}
function openPublicChannels() {
function openPublicChannels(searchTerm) {
appDispatcher.dispatch({
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);
},
[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);