diff options
author | Anton Tananaev <anton@traccar.org> | 2022-10-02 09:58:24 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-10-02 09:58:24 -0700 |
commit | cd645ca960e994101c7734049be6a3ea51d2ad73 (patch) | |
tree | 089fa5bd4c5033770e8c07b03c4ed39cfeb4c35a /modern/src | |
parent | dd0e4ccb41690e2311bf62aa2f792e941f3685dc (diff) | |
download | trackermap-web-cd645ca960e994101c7734049be6a3ea51d2ad73.tar.gz trackermap-web-cd645ca960e994101c7734049be6a3ea51d2ad73.tar.bz2 trackermap-web-cd645ca960e994101c7734049be6a3ea51d2ad73.zip |
Fix custom server change
Diffstat (limited to 'modern/src')
-rw-r--r-- | modern/src/other/ChangeServerPage.js | 22 |
1 files changed, 13 insertions, 9 deletions
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) => <TextField {...params} label={t('settingsServer')} />} - 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; + }} /> - <Button variant="outlined" color="secondary" onClick={handleSubmit} disabled={loading}>{t('sharedSave')}</Button> </Container> ); }; |