Add allowCustomHomeservers config option (#525)

* feat: Add allowCustomHomeservers config option

* fix: Do not lock the homeserver input when the selection is changed
This commit is contained in:
Ash 2022-05-12 12:43:14 +01:00 committed by GitHub
parent b3cb48319a
commit c08b0e654b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View file

@ -7,5 +7,6 @@
"kde.org", "kde.org",
"matrix.org", "matrix.org",
"chat.mozilla.org" "chat.mozilla.org"
] ],
"allowCustomHomeservers": true
} }

View file

@ -93,12 +93,13 @@ function Homeserver({ onChange }) {
const result = await (await fetch(configFileUrl, { method: 'GET' })).json(); const result = await (await fetch(configFileUrl, { method: 'GET' })).json();
const selectedHs = result?.defaultHomeserver; const selectedHs = result?.defaultHomeserver;
const hsList = result?.homeserverList; const hsList = result?.homeserverList;
const allowCustom = result?.allowCustomHomeservers ?? true;
if (!hsList?.length > 0 || selectedHs < 0 || selectedHs >= hsList?.length) { if (!hsList?.length > 0 || selectedHs < 0 || selectedHs >= hsList?.length) {
throw new Error(); throw new Error();
} }
setHs({ selected: hsList[selectedHs], list: hsList }); setHs({ selected: hsList[selectedHs], list: hsList, allowCustom: allowCustom });
} catch { } catch {
setHs({ selected: 'matrix.org', list: ['matrix.org'] }); setHs({ selected: 'matrix.org', list: ['matrix.org'], allowCustom: true });
} }
}, []); }, []);
@ -106,14 +107,15 @@ function Homeserver({ onChange }) {
const { value } = e.target; const { value } = e.target;
setProcess({ isLoading: false }); setProcess({ isLoading: false });
debounce._(async () => { debounce._(async () => {
setHs({ selected: value.trim(), list: hs.list }); setHs({ ...hs, selected: value.trim() });
}, 700)(); }, 700)();
}; };
return ( return (
<> <>
<div className="homeserver-form"> <div className="homeserver-form">
<Input name="homeserver" onChange={handleHsInput} value={hs?.selected} forwardRef={hsRef} label="Homeserver" /> <Input name="homeserver" onChange={handleHsInput} value={hs?.selected} forwardRef={hsRef} label="Homeserver"
disabled={hs === null || !hs.allowCustom} />
<ContextMenu <ContextMenu
placement="right" placement="right"
content={(hideMenu) => ( content={(hideMenu) => (
@ -126,7 +128,7 @@ function Homeserver({ onChange }) {
onClick={() => { onClick={() => {
hideMenu(); hideMenu();
hsRef.current.value = hsName; hsRef.current.value = hsName;
setHs({ selected: hsName, list: hs.list }); setHs({ ...hs, selected: hsName });
}} }}
> >
{hsName} {hsName}