aboutsummaryrefslogtreecommitdiff
path: root/modern/src/common/components/AddressValue.js
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-15 18:49:15 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-15 18:49:15 -0700
commit5154c9be13ad1446b09feaaa843e621555ac7581 (patch)
treeb6af81051fb500cb228476a64f90b1fe376ae5e3 /modern/src/common/components/AddressValue.js
parentc407acaadc5dadbc7db917a11c8294aa7710b2cc (diff)
downloadtrackermap-web-5154c9be13ad1446b09feaaa843e621555ac7581.tar.gz
trackermap-web-5154c9be13ad1446b09feaaa843e621555ac7581.tar.bz2
trackermap-web-5154c9be13ad1446b09feaaa843e621555ac7581.zip
Address for trips and stops
Diffstat (limited to 'modern/src/common/components/AddressValue.js')
-rw-r--r--modern/src/common/components/AddressValue.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/modern/src/common/components/AddressValue.js b/modern/src/common/components/AddressValue.js
new file mode 100644
index 00000000..767f516b
--- /dev/null
+++ b/modern/src/common/components/AddressValue.js
@@ -0,0 +1,31 @@
+import React, { useEffect, useState } from 'react';
+import { Link } from '@mui/material';
+import { useTranslation } from './LocalizationProvider';
+import { useCatch } from '../../reactHelper';
+
+const AddressValue = ({ latitude, longitude, originalAddress }) => {
+ const t = useTranslation();
+
+ const [address, setAddress] = useState();
+
+ useEffect(() => {
+ setAddress(originalAddress);
+ }, [originalAddress]);
+
+ const showAddress = useCatch(async () => {
+ const query = new URLSearchParams({ latitude, longitude });
+ const response = await fetch(`/api/server/geocode?${query.toString()}`);
+ if (response.ok) {
+ setAddress(await response.text());
+ } else {
+ throw Error(await response.text());
+ }
+ });
+
+ if (address) {
+ return address;
+ }
+ return (<Link href="#" onClick={showAddress}>{t('sharedShowAddress')}</Link>);
+};
+
+export default AddressValue;