Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add allowCustomHomeservers config option #525

Merged
merged 2 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"kde.org",
"matrix.org",
"chat.mozilla.org"
]
],
"allowCustomHomeservers": true
}
12 changes: 7 additions & 5 deletions src/app/templates/auth/Auth.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,29 @@ 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 });
}
}, []);

const handleHsInput = (e) => {
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) => (
Expand All @@ -126,7 +128,7 @@ function Homeserver({ onChange }) {
onClick={() => {
hideMenu();
hsRef.current.value = hsName;
setHs({ selected: hsName, list: hs.list });
setHs({ ...hs, selected: hsName });
}}
>
{hsName}
Expand Down