Add allowCustomHomeservers config option (#525)
authorAsh <ash@ashhhleyyy.dev>
Thu, 12 May 2022 11:43:14 +0000 (12:43 +0100)
committerGitHub <noreply@github.com>
Thu, 12 May 2022 11:43:14 +0000 (17:13 +0530)
* feat: Add allowCustomHomeservers config option

* fix: Do not lock the homeserver input when the selection is changed

config.json
src/app/templates/auth/Auth.jsx

index c8a5ea6fb63fe7d19cbf7ce4401397232481790a..e7f9eea343e4de9a2e5c7182e236414b530a8724 100644 (file)
@@ -7,5 +7,6 @@
     "kde.org",
     "matrix.org",
     "chat.mozilla.org"
-  ]
+  ],
+  "allowCustomHomeservers": true
 }
\ No newline at end of file
index 33d2152f9f3b3bef7058b099c6aa420045a9dd48..1f76476d23484342ba58421d01062fa76f955540 100644 (file)
@@ -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 (
     <>
       <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
           placement="right"
           content={(hideMenu) => (
@@ -126,7 +128,7 @@ function Homeserver({ onChange }) {
                     onClick={() => {
                       hideMenu();
                       hsRef.current.value = hsName;
-                      setHs({ selected: hsName, list: hs.list });
+                      setHs({ ...hs, selected: hsName });
                     }}
                   >
                     {hsName}