2020-03-30 19:50:27 +00:00
|
|
|
import React, { useState } from 'react';
|
|
|
|
import { Text } from 'react-native';
|
|
|
|
|
2022-04-07 14:10:03 +00:00
|
|
|
import { themes } from '../../lib/constants';
|
2022-03-08 14:24:21 +00:00
|
|
|
import { MultiSelect } from '../../containers/UIKit/MultiSelect';
|
|
|
|
import { ISearchLocal } from '../../definitions';
|
|
|
|
import I18n from '../../i18n';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { getAvatarURL } from '../../lib/methods/helpers/getAvatarUrl';
|
2021-09-15 19:58:14 +00:00
|
|
|
import { ICreateDiscussionViewSelectChannel } from './interfaces';
|
2022-03-08 14:24:21 +00:00
|
|
|
import styles from './styles';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { localSearch } from '../../lib/methods';
|
|
|
|
import { getRoomAvatar, getRoomTitle, debounce } from '../../lib/methods/helpers';
|
2020-03-30 19:50:27 +00:00
|
|
|
|
2021-09-15 19:58:14 +00:00
|
|
|
const SelectChannel = ({
|
|
|
|
server,
|
|
|
|
token,
|
|
|
|
userId,
|
|
|
|
onChannelSelect,
|
|
|
|
initial,
|
|
|
|
blockUnauthenticatedAccess,
|
|
|
|
serverVersion,
|
|
|
|
theme
|
2022-05-02 22:48:29 +00:00
|
|
|
}: ICreateDiscussionViewSelectChannel): React.ReactElement => {
|
2022-03-08 14:24:21 +00:00
|
|
|
const [channels, setChannels] = useState<ISearchLocal[]>([]);
|
2020-03-30 19:50:27 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const getChannels = debounce(async (keyword = '') => {
|
2020-03-30 19:50:27 +00:00
|
|
|
try {
|
2022-04-28 20:37:25 +00:00
|
|
|
const res = await localSearch({ text: keyword });
|
2020-03-30 19:50:27 +00:00
|
|
|
setChannels(res);
|
|
|
|
} catch {
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
}, 300);
|
|
|
|
|
2022-05-02 22:48:29 +00:00
|
|
|
const getAvatar = (item: ISearchLocal) =>
|
2022-06-06 14:17:51 +00:00
|
|
|
getAvatarURL({
|
2022-04-28 20:37:25 +00:00
|
|
|
text: getRoomAvatar(item),
|
2021-09-13 20:41:05 +00:00
|
|
|
type: item.t,
|
2022-06-06 15:33:36 +00:00
|
|
|
userId,
|
|
|
|
token,
|
2021-09-13 20:41:05 +00:00
|
|
|
server,
|
|
|
|
avatarETag: item.avatarETag,
|
|
|
|
rid: item.rid,
|
|
|
|
blockUnauthenticatedAccess,
|
|
|
|
serverVersion
|
|
|
|
});
|
2020-03-30 19:50:27 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2020-04-01 12:07:03 +00:00
|
|
|
<Text style={[styles.label, { color: themes[theme].titleText }]}>{I18n.t('Parent_channel_or_group')}</Text>
|
2020-03-30 19:50:27 +00:00
|
|
|
<MultiSelect
|
|
|
|
inputStyle={styles.inputStyle}
|
|
|
|
onChange={onChannelSelect}
|
|
|
|
onSearch={getChannels}
|
|
|
|
value={initial && [initial]}
|
2022-03-29 20:06:50 +00:00
|
|
|
disabled={!!initial}
|
2020-03-30 19:50:27 +00:00
|
|
|
options={channels.map(channel => ({
|
2022-04-08 22:53:48 +00:00
|
|
|
value: channel,
|
2022-04-28 20:37:25 +00:00
|
|
|
text: { text: getRoomTitle(channel) },
|
2020-10-30 13:51:04 +00:00
|
|
|
imageUrl: getAvatar(channel)
|
2020-03-30 19:50:27 +00:00
|
|
|
}))}
|
|
|
|
onClose={() => setChannels([])}
|
2021-09-13 20:41:05 +00:00
|
|
|
placeholder={{ text: `${I18n.t('Select_a_Channel')}...` }}
|
2020-03-30 19:50:27 +00:00
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default SelectChannel;
|