-
-
Notifications
You must be signed in to change notification settings - Fork 944
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started adding app-wide unit selector logic
- Loading branch information
Showing
4 changed files
with
117 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { _ } from '../classes/gettext'; | ||
|
||
const units = { | ||
acres: { | ||
factor: 0.00024711, | ||
label: _('Acres'), | ||
abbr: 'ac' | ||
}, | ||
feet: { | ||
factor: 3.2808, | ||
label: _('Feet'), | ||
abbr: 'ft' | ||
}, | ||
hectares: { | ||
factor: 0.0001, | ||
label: _('Hectares'), | ||
abbr: 'ha' | ||
}, | ||
meters: { | ||
factor: 1, | ||
label: _('Meters'), | ||
abbr: 'm' | ||
}, | ||
kilometers: { | ||
factor: 0.001, | ||
label: _('Kilometers'), | ||
abbr: 'km' | ||
}, | ||
centimeters: { | ||
factor: 100, | ||
label: _('Centimeters'), | ||
abbr: 'cm' | ||
}, | ||
miles: { | ||
factor: 3.2808 / 5280, | ||
label: _('Miles'), | ||
abbr: 'mi' | ||
}, | ||
sqfeet: { | ||
factor: 10.7639, | ||
label: _('Square Feet'), | ||
abbr: 'ft²' | ||
}, | ||
sqmeters: { | ||
factor: 1, | ||
label: _('Square Meters'), | ||
abbr: 'm²' | ||
}, | ||
sqmiles: { | ||
factor: 0.000000386102, | ||
label: _('Square Miles'), | ||
abbr: 'mi²' | ||
} | ||
}; | ||
|
||
const systems = { | ||
metric: { | ||
length: [units.kilometers, units.meters, units.centimeters], | ||
area: [units.sqmeters] | ||
} | ||
|
||
// TODO | ||
} | ||
|
||
export default { | ||
// to be used on individual strings | ||
|
||
}; | ||
|
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,30 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
class UnitSelector extends React.Component { | ||
static propTypes = { | ||
} | ||
|
||
constructor(props){ | ||
super(props); | ||
|
||
this.state = { | ||
system: window.getPreferredUnitSystem() | ||
} | ||
} | ||
|
||
handleChange = e => { | ||
this.setState({system: e.target.value}); | ||
window.setPreferredUnitSystem(e.target.value); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<select value={this.state.system} onChange={this.handleChange}> | ||
<option value="metric" key={}></option> | ||
</select> | ||
); | ||
} | ||
} | ||
|
||
export default UnitSelector; |
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,10 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import UnitSelector from '../UnitSelector'; | ||
|
||
describe('<UnitSelector />', () => { | ||
it('renders without exploding', () => { | ||
const wrapper = shallow(<UnitSelector />); | ||
expect(wrapper.exists()).toBe(true); | ||
}) | ||
}); |
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