-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: sync My Location dropdown with CODAP state, sync Lat/Long betwe…
…en tabs, refactor app state related to location and lat/long [PT-188059223] [PT-188071551]
- Loading branch information
Showing
12 changed files
with
172 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...grasp-seasons/components/city-select.scss → ...rasp-seasons/components/my-locations.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.city-select { | ||
.my-locations { | ||
display: flex; | ||
flex-direction: column; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React, { Component } from "react"; | ||
import t, { Language } from "../translation/translate"; | ||
import { ILocation } from "../../types"; | ||
import { locationsEqual } from "../../utils/daylight-utils"; | ||
|
||
import "./my-locations.scss"; | ||
|
||
interface IProps { | ||
lang: Language; | ||
lat: number; | ||
long: number; | ||
onLocationChange: (lat: number, long: number, name: string) => void; | ||
locations: ILocation[]; | ||
} | ||
|
||
export default class MyLocations extends Component<IProps> { | ||
constructor(props: IProps) { | ||
super(props); | ||
this.selectChange = this.selectChange.bind(this); | ||
} | ||
|
||
selectChange(event: any) { | ||
const { onLocationChange, locations } = this.props; | ||
const location = locations[event.target.value]; | ||
if (location.latitude && location.longitude) { | ||
onLocationChange(location.latitude, location.longitude, location.name); | ||
} | ||
} | ||
|
||
getOptions() { | ||
const { locations } = this.props; | ||
const options = this.selectedCity === "" ? [ | ||
<option key="unsaved" value="" disabled={true}>Custom Location (unsaved)</option> | ||
] : []; | ||
for (let i = 0; i < locations.length; i++) { | ||
const loc = locations[i]; | ||
options.push(<option key={i} value={i}>{ loc.name }</option>); | ||
} | ||
return options; | ||
} | ||
|
||
get selectedCity() { | ||
const { lat, long, locations } = this.props; | ||
const currentLocation: ILocation = { latitude: lat, longitude: long, name: "" }; | ||
for (let i = 0; i < locations.length; i++) { | ||
if (locationsEqual(currentLocation, locations[i])) { | ||
return i; | ||
} | ||
} | ||
return ""; // custom location | ||
} | ||
|
||
render() { | ||
return ( | ||
<div className="my-locations"> | ||
<label>{ t("~MY_LOCATIONS", this.props.lang) }</label> | ||
<select className="form-control" value={this.selectedCity} onChange={this.selectChange}> | ||
{ this.getOptions() } | ||
</select> | ||
</div> | ||
); | ||
} | ||
} |
Oops, something went wrong.