From cd645ca960e994101c7734049be6a3ea51d2ad73 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 2 Oct 2022 09:58:24 -0700 Subject: Fix custom server change --- modern/src/other/ChangeServerPage.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'modern/src') diff --git a/modern/src/other/ChangeServerPage.js b/modern/src/other/ChangeServerPage.js index 70b18993..0343a941 100644 --- a/modern/src/other/ChangeServerPage.js +++ b/modern/src/other/ChangeServerPage.js @@ -1,8 +1,8 @@ -import React, { useState } from 'react'; +import React from 'react'; import ElectricalServicesIcon from '@mui/icons-material/ElectricalServices'; import { makeStyles } from '@mui/styles'; import { - Autocomplete, Button, Container, TextField, + Autocomplete, Container, createFilterOptions, TextField, } from '@mui/material'; import { useTranslation } from '../common/components/LocalizationProvider'; @@ -38,11 +38,9 @@ const ChangeServerPage = () => { const classes = useStyles(); const t = useTranslation(); - const [url, setUrl] = useState(currentServer); - const [loading, setLoading] = useState(false); + const filter = createFilterOptions(); - const handleSubmit = () => { - setLoading(true); + const handleSubmit = (url) => { if (window.webkit && window.webkit.messageHandlers.appInterface) { window.webkit.messageHandlers.appInterface.postMessage(`server|${url}`); } else if (window.appInterface) { @@ -60,10 +58,16 @@ const ChangeServerPage = () => { className={classes.field} options={officialServers} renderInput={(params) => } - value={url} - onChange={(_, value) => setUrl(value)} + value={currentServer} + onChange={(_, value) => handleSubmit(value)} + filterOptions={(options, params) => { + const filtered = filter(options, params); + if (params.inputValue && !filtered.includes(params.inputValue)) { + filtered.push(params.inputValue); + } + return filtered; + }} /> - ); }; -- cgit v1.2.3