X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fcomponents%2Fcommon%2FChannelSelect.js;h=a69662f423b34e571255e660d86f8775c21e9219;hb=ac6921da72ff4b0beab9e5f1308788a55aae3ad9;hp=701f196591e1402e4cbd4936de7994b40a1e780f;hpb=e10222af705e3475fcea6e0b17d1c9984a62db26;p=alttp.git diff --git a/resources/js/components/common/ChannelSelect.js b/resources/js/components/common/ChannelSelect.js index 701f196..a69662f 100644 --- a/resources/js/components/common/ChannelSelect.js +++ b/resources/js/components/common/ChannelSelect.js @@ -7,7 +7,14 @@ import { useTranslation } from 'react-i18next'; import Icon from './Icon'; import debounce from '../../helpers/debounce'; -const ChannelSelect = ({ joinable, manageable, onChange, value }) => { +const ChannelSelect = ({ + autoSelect, + joinable, + manageable, + onChange, + readOnly, + value, +}) => { const [resolved, setResolved] = useState(null); const [results, setResults] = useState([]); const [search, setSearch] = useState(''); @@ -47,11 +54,17 @@ const ChannelSelect = ({ joinable, manageable, onChange, value }) => { }); ctrl = null; setResults(response.data); + if (autoSelect && !phrase && response.data.length === 1) { + onChange({ + channel: response.data[0], + target: { value: response.data[0].id }, + }); + } } catch (e) { ctrl = null; console.error(e); } - }, 300), [manageable]); + }, 300), [autoSelect, joinable, manageable]); useEffect(() => { fetch(search); @@ -72,14 +85,16 @@ const ChannelSelect = ({ joinable, manageable, onChange, value }) => { if (value) { return