Skip to content

Commit dbb9688

Browse files
committed
Send point location with gps location
1 parent 4eaf364 commit dbb9688

File tree

2 files changed

+43
-14
lines changed

2 files changed

+43
-14
lines changed

src/components/organisms/LocationApproveWindow.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ const LocationApprove: FC<IProps> = ({ isOpen, onClose, news, newFlashTitle }) =
5858
const { userStore } = store;
5959
const [shouldApprove, setApproveStatus] = useState(true);
6060
const [locationChanged, setLocationChanged] = useState(false);
61-
const [newStreetLoc, setNewStreetLoc] = useState<IStreetData|null>(null);
62-
const [newGpsLoc, setNewGpsLoc] = useState<IGpsData|null>(null);
61+
const [newStreetLoc, setNewStreetLoc] = useState<IStreetData|undefined>(undefined);
62+
const [newGpsLoc, setNewGpsLoc] = useState<IGpsData|undefined>(undefined);
63+
const [newPointLoc, setNewPointLoc] = useState<IPoint|undefined>(undefined);
6364
const [locationToDisplay, setLocationToDisplay] = useState(news.curr_cbs_location_text);
6465
// Unauthorized user shouldn't be able to open the window in the first place
6566
const userInfo = userStore.userInfo && userStore.userInfo.data && userStore.userInfo.data.firstName ?
@@ -68,14 +69,23 @@ const LocationApprove: FC<IProps> = ({ isOpen, onClose, news, newFlashTitle }) =
6869
function handleApproveButton () {
6970
if (shouldApprove && locationChanged) {
7071
if (newStreetLoc) {
71-
updateNews(news.id, locationQualificationOptions.MANUAL, newStreetLoc, null);
72+
updateNews({
73+
newsId: news.id,
74+
newLocationQualification: locationQualificationOptions.MANUAL,
75+
streetLocation: newStreetLoc,
76+
});
7277
} else {
73-
updateNews(news.id, locationQualificationOptions.MANUAL, null, newGpsLoc);
78+
updateNews({
79+
newsId: news.id,
80+
newLocationQualification: locationQualificationOptions.MANUAL,
81+
gpsLocation: newGpsLoc,
82+
pointLocation: newPointLoc,
83+
});
7484
}
7585
} else if (shouldApprove) {
76-
updateNews(news.id, locationQualificationOptions.VERIFIED, null, null);
86+
updateNews({newsId: news.id, newLocationQualification: locationQualificationOptions.VERIFIED});
7787
} else {
78-
updateNews(news.id, locationQualificationOptions.REJECTED, null, null);
88+
updateNews({newsId: news.id, newLocationQualification: locationQualificationOptions.REJECTED});
7989
}
8090
onCloseInitValues();
8191
window.location.reload();
@@ -94,13 +104,14 @@ const LocationApprove: FC<IProps> = ({ isOpen, onClose, news, newFlashTitle }) =
94104

95105
const onMapLocationChange = useCallback(
96106
(location: IPoint) => {
97-
setLocationChanged(true);
107+
setNewPointLoc(location);
98108
store.fetchGpsLocation(location);
99109
if (store.gpsLocationData) {
100110
setNewGpsLoc(store.gpsLocationData);
101111
setLocationToDisplay(t('mapDialog.road') + " " + store.gpsLocationData.road1 + " - " +
102112
store.gpsLocationData.road_segment_name);
103113
}
114+
setLocationChanged(true);
104115
},
105116
[t, store],
106117
);

src/services/news.data.service.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import axios from 'axios';
22
import { INewsFlash } from 'models/NewFlash';
33
import { IGpsData, IStreetData } from "models/WidgetData";
4+
import {IPoint} from "../models/Point";
45

56
const errorNews: INewsFlash = {
67
lat: -1,
@@ -68,16 +69,33 @@ function onErrorFetchNewsFlash() {
6869
return errorArr;
6970
}
7071

71-
export function updateNews(newsId: number, newLocationQualification: any,
72-
streetLocation: IStreetData | null, gpsLocation: IGpsData | null) {
72+
interface IUpdateNews {
73+
newsId: number,
74+
newLocationQualification: any,
75+
streetLocation?: IStreetData,
76+
gpsLocation?: IGpsData,
77+
pointLocation?: IPoint,
78+
}
79+
80+
export function updateNews({
81+
newsId,
82+
newLocationQualification,
83+
streetLocation,
84+
gpsLocation,
85+
pointLocation,
86+
} : IUpdateNews) {
7387
const data = [];
74-
data.push(`newsflash_location_qualification=${newLocationQualification}`)
88+
data.push(`newsflash_location_qualification=${newLocationQualification}`);
89+
if (pointLocation) {
90+
data.push(`lat=${pointLocation.latitude}`);
91+
data.push(`lng=${pointLocation.longitude}`);
92+
}
7593
if (gpsLocation) {
76-
data.push(`road_segment_id=${gpsLocation.road_segment_id}`)
77-
data.push(`road1=${gpsLocation.road1}`)
94+
data.push(`road_segment_id=${gpsLocation.road_segment_id}`);
95+
data.push(`road1=${gpsLocation.road1}`);
7896
} else if (streetLocation) {
79-
data.push(`yishuv_name=${streetLocation.city.yishuv_name}`)
80-
data.push(`street1_hebrew=${streetLocation.street.street_hebrew}`)
97+
data.push(`yishuv_name=${streetLocation.city.yishuv_name}`);
98+
data.push(`street1_hebrew=${streetLocation.street.street_hebrew}`);
8199
}
82100
const url = `${NEWS_FLASH_API}/${newsId}?${data.join('&')}`;
83101
axios

0 commit comments

Comments
 (0)