Skip to content

Commit

Permalink
Merge pull request #281 from appfolio/fixReactWarnings
Browse files Browse the repository at this point in the history
Fix react warnings
  • Loading branch information
gthomas-appfolio authored Aug 14, 2017
2 parents 3c7fa99 + 41b7336 commit a356ec0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/components/Notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ export default class Notes extends React.Component {
</Col>
</Row>
{children ||
notes.map(note =>
notes.map((note, i) =>
<Note
note={note}
key={i}
onCancel={onCancel}
onChange={onChange}
onDelete={onDelete}
Expand Down
37 changes: 30 additions & 7 deletions src/components/datemonth/DateMonth.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,42 @@ export default class DateMonth extends React.Component {
document.removeEventListener('keydown', this.escListener);
}

setMonth(month) {
setMonth = month => () => {
this.setState({ month });
}

setYear(year) {
setYear = year => () => {
this.setState({ year });
}

render() {
const { props, state } = this;
renderMonths = () => MONTHS.map(month => (
<Label
selected={this.state.month === month}
label={month}
key={month}
onClick={this.setMonth(month)}
/>
));

renderYears = () => {
const now = new Date();
const end = state.year + (now.getFullYear() - state.year) % 10 + 1;
const { year: currentYear } = this.state;
const end = currentYear + (now.getFullYear() - currentYear) % 10 + 1;
const start = end - 10;
const YEARS = range(start, end);
return YEARS.map(year => (
<Label
selected={currentYear === year}
label={year}
key={year}
onClick={this.setYear(year)}
/>
));
}

render() {
const { props, state } = this;
const now = new Date();
const canAdvanceYear = now.getFullYear() - state.year > 9;

const open = () => this.setState({
Expand Down Expand Up @@ -157,12 +179,13 @@ export default class DateMonth extends React.Component {
<Dropdown
className={styles.picker}
isOpen={state.open}
toggle={toggle}
>
<DropdownMenu>
<Row className="no-gutters">
<Col xs="6" className={styles.month}>
<ul className="p-1 m-0">
{MONTHS.map(month => <Label selected={state.month === month} label={month} onClick={() => this.setMonth(month)} />)}
{this.renderMonths()}
</ul>
</Col>

Expand All @@ -176,7 +199,7 @@ export default class DateMonth extends React.Component {
</Button>
</ButtonGroup>
<ul className="p-1 m-0">
{YEARS.map(year => <Label selected={state.year === year} label={year} onClick={() => this.setYear(year)} />)}
{this.renderYears()}
</ul>
</Col>
</Row>
Expand Down

0 comments on commit a356ec0

Please sign in to comment.