aboutsummaryrefslogtreecommitdiff
path: root/modern/src/other
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-19 07:21:51 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-19 07:21:51 -0700
commit15a72336f2f38d6175e90d01973515b5573f3ed8 (patch)
treea76b92f2bb3bd79d8f366ba20dff969067863658 /modern/src/other
parent588f32a9e427a9a115deafd7eea2e71b01f25c62 (diff)
downloadtrackermap-web-15a72336f2f38d6175e90d01973515b5573f3ed8.tar.gz
trackermap-web-15a72336f2f38d6175e90d01973515b5573f3ed8.tar.bz2
trackermap-web-15a72336f2f38d6175e90d01973515b5573f3ed8.zip
Implement change server
Diffstat (limited to 'modern/src/other')
-rw-r--r--modern/src/other/ChangeServerPage.js66
1 files changed, 66 insertions, 0 deletions
diff --git a/modern/src/other/ChangeServerPage.js b/modern/src/other/ChangeServerPage.js
new file mode 100644
index 00000000..1862ecbd
--- /dev/null
+++ b/modern/src/other/ChangeServerPage.js
@@ -0,0 +1,66 @@
+import React, { useState } from 'react';
+import ElectricalServicesIcon from '@mui/icons-material/ElectricalServices';
+import { makeStyles } from '@mui/styles';
+import { Autocomplete, Button, Container, TextField } from '@mui/material';
+import { useTranslation } from '../common/components/LocalizationProvider';
+
+const currentServer = `${window.location.protocol}//${window.location.host}`;
+
+const officialServers = [
+ currentServer,
+ 'https://demo.traccar.org',
+ 'https://demo2.traccar.org',
+ 'https://demo3.traccar.org',
+ 'https://demo4.traccar.org',
+ 'https://server.traccar.org',
+ 'http://localhost:8082',
+];
+
+const useStyles = makeStyles((theme) => ({
+ icon: {
+ textAlign: 'center',
+ fontSize: '128px',
+ color: theme.palette.colors.neutral,
+ },
+ container: {
+ textAlign: 'center',
+ padding: theme.spacing(5, 3),
+ },
+ field: {
+ margin: theme.spacing(3, 0),
+ },
+}));
+
+const ChangeServerPage = () => {
+ const classes = useStyles();
+ const t = useTranslation();
+
+ const [url, setUrl] = useState(currentServer);
+
+ const handleSubmit = () => {
+ if (window.webkit && window.webkit.messageHandlers.appInterface) {
+ window.webkit.messageHandlers.appInterface.postMessage(`server|${url}`);
+ } else if (window.appInterface) {
+ window.appInterface.postMessage(`server|${url}`);
+ } else {
+ window.location.replace(url);
+ }
+ };
+
+ return (
+ <Container maxWidth="xs" className={classes.container}>
+ <ElectricalServicesIcon className={classes.icon} />
+ <Autocomplete
+ freeSolo
+ className={classes.field}
+ options={officialServers}
+ renderInput={(params) => <TextField {...params} label={t('settingsServer')} />}
+ value={url}
+ onChange={(_, value) => setUrl(value)}
+ />
+ <Button variant="outlined" color="secondary" onClick={handleSubmit}>{t('sharedSave')}</Button>
+ </Container>
+ );
+};
+
+export default ChangeServerPage;