Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send point location with gps location #1178

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions src/components/organisms/LocationApproveWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ const LocationApprove: FC<IProps> = ({ isOpen, onClose, news, newFlashTitle }) =
const { userStore } = store;
const [shouldApprove, setApproveStatus] = useState(true);
const [locationChanged, setLocationChanged] = useState(false);
const [newStreetLoc, setNewStreetLoc] = useState<IStreetData|null>(null);
const [newGpsLoc, setNewGpsLoc] = useState<IGpsData|null>(null);
const [newStreetLoc, setNewStreetLoc] = useState<IStreetData|undefined>(undefined);
const [newGpsLoc, setNewGpsLoc] = useState<IGpsData|undefined>(undefined);
const [newPointLoc, setNewPointLoc] = useState<IPoint|undefined>(undefined);
const [locationToDisplay, setLocationToDisplay] = useState(news.curr_cbs_location_text);
// Unauthorized user shouldn't be able to open the window in the first place
const userInfo = userStore.userInfo && userStore.userInfo.data && userStore.userInfo.data.firstName ?
Expand All @@ -68,14 +69,23 @@ const LocationApprove: FC<IProps> = ({ isOpen, onClose, news, newFlashTitle }) =
function handleApproveButton () {
if (shouldApprove && locationChanged) {
if (newStreetLoc) {
updateNews(news.id, locationQualificationOptions.MANUAL, newStreetLoc, null);
updateNews({
newsId: news.id,
newLocationQualification: locationQualificationOptions.MANUAL,
streetLocation: newStreetLoc,
});
} else {
updateNews(news.id, locationQualificationOptions.MANUAL, null, newGpsLoc);
updateNews({
newsId: news.id,
newLocationQualification: locationQualificationOptions.MANUAL,
gpsLocation: newGpsLoc,
pointLocation: newPointLoc,
});
}
} else if (shouldApprove) {
updateNews(news.id, locationQualificationOptions.VERIFIED, null, null);
updateNews({newsId: news.id, newLocationQualification: locationQualificationOptions.VERIFIED});
} else {
updateNews(news.id, locationQualificationOptions.REJECTED, null, null);
updateNews({newsId: news.id, newLocationQualification: locationQualificationOptions.REJECTED});
}
onCloseInitValues();
window.location.reload();
Expand All @@ -94,13 +104,14 @@ const LocationApprove: FC<IProps> = ({ isOpen, onClose, news, newFlashTitle }) =

const onMapLocationChange = useCallback(
(location: IPoint) => {
setLocationChanged(true);
setNewPointLoc(location);
store.fetchGpsLocation(location);
if (store.gpsLocationData) {
setNewGpsLoc(store.gpsLocationData);
setLocationToDisplay(t('mapDialog.road') + " " + store.gpsLocationData.road1 + " - " +
store.gpsLocationData.road_segment_name);
}
setLocationChanged(true);
},
[t, store],
);
Expand Down
32 changes: 25 additions & 7 deletions src/services/news.data.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import axios from 'axios';
import { INewsFlash } from 'models/NewFlash';
import { IGpsData, IStreetData } from "models/WidgetData";
import {IPoint} from "../models/Point";

const errorNews: INewsFlash = {
lat: -1,
Expand Down Expand Up @@ -68,16 +69,33 @@ function onErrorFetchNewsFlash() {
return errorArr;
}

export function updateNews(newsId: number, newLocationQualification: any,
streetLocation: IStreetData | null, gpsLocation: IGpsData | null) {
interface IUpdateNews {
newsId: number,
newLocationQualification: any,
streetLocation?: IStreetData,
gpsLocation?: IGpsData,
pointLocation?: IPoint,
}

export function updateNews({
newsId,
newLocationQualification,
streetLocation,
gpsLocation,
pointLocation,
} : IUpdateNews) {
const data = [];
data.push(`newsflash_location_qualification=${newLocationQualification}`)
data.push(`newsflash_location_qualification=${newLocationQualification}`);
if (pointLocation) {
data.push(`lat=${pointLocation.latitude}`);
data.push(`lng=${pointLocation.longitude}`);
}
if (gpsLocation) {
data.push(`road_segment_id=${gpsLocation.road_segment_id}`)
data.push(`road1=${gpsLocation.road1}`)
data.push(`road_segment_id=${gpsLocation.road_segment_id}`);
data.push(`road1=${gpsLocation.road1}`);
} else if (streetLocation) {
data.push(`yishuv_name=${streetLocation.city.yishuv_name}`)
data.push(`street1_hebrew=${streetLocation.street.street_hebrew}`)
data.push(`yishuv_name=${streetLocation.city.yishuv_name}`);
data.push(`street1_hebrew=${streetLocation.street.street_hebrew}`);
}
const url = `${NEWS_FLASH_API}/${newsId}?${data.join('&')}`;
axios
Expand Down
Loading