From c08b0e654b84514c15eb04307adfb38db96e3e89 Mon Sep 17 00:00:00 2001 From: Ash Date: Thu, 12 May 2022 12:43:14 +0100 Subject: [PATCH] Add allowCustomHomeservers config option (#525) * feat: Add allowCustomHomeservers config option * fix: Do not lock the homeserver input when the selection is changed --- config.json | 3 ++- src/app/templates/auth/Auth.jsx | 12 +++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/config.json b/config.json index c8a5ea6..e7f9eea 100644 --- a/config.json +++ b/config.json @@ -7,5 +7,6 @@ "kde.org", "matrix.org", "chat.mozilla.org" - ] + ], + "allowCustomHomeservers": true } \ No newline at end of file diff --git a/src/app/templates/auth/Auth.jsx b/src/app/templates/auth/Auth.jsx index 33d2152..1f76476 100644 --- a/src/app/templates/auth/Auth.jsx +++ b/src/app/templates/auth/Auth.jsx @@ -93,12 +93,13 @@ function Homeserver({ onChange }) { const result = await (await fetch(configFileUrl, { method: 'GET' })).json(); const selectedHs = result?.defaultHomeserver; const hsList = result?.homeserverList; + const allowCustom = result?.allowCustomHomeservers ?? true; if (!hsList?.length > 0 || selectedHs < 0 || selectedHs >= hsList?.length) { throw new Error(); } - setHs({ selected: hsList[selectedHs], list: hsList }); + setHs({ selected: hsList[selectedHs], list: hsList, allowCustom: allowCustom }); } 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; setProcess({ isLoading: false }); debounce._(async () => { - setHs({ selected: value.trim(), list: hs.list }); + setHs({ ...hs, selected: value.trim() }); }, 700)(); }; return ( <>
- + ( @@ -126,7 +128,7 @@ function Homeserver({ onChange }) { onClick={() => { hideMenu(); hsRef.current.value = hsName; - setHs({ selected: hsName, list: hs.list }); + setHs({ ...hs, selected: hsName }); }} > {hsName}