All components - update correctly on both prop create and update

This commit is contained in:
2018-03-23 00:39:49 +05:30
parent 1ffb373d2b
commit 508c034276
4 changed files with 44 additions and 10 deletions
+8 -1
View File
@@ -9,9 +9,16 @@ export class ClosedReason extends React.Component<ObjectWithHoliday, {}> {
constructor(props: ObjectWithHoliday) { constructor(props: ObjectWithHoliday) {
super(props); super(props);
this.holiday = props.holiday; this.updateFromProps(props);
} }
componentWillUpdate(nextProps: ObjectWithHoliday, nextState: {}) {
this.updateFromProps(nextProps);
}
updateFromProps(props: ObjectWithHoliday) {
this.holiday = props.holiday;
}
render() { render() {
return ( return (
<div className="ClosedReason"> <div className="ClosedReason">
@@ -19,6 +19,14 @@ export class NextOpenCloseMini extends React.Component<NextOpenCloseMiniProps, {
constructor(props: NextOpenCloseMiniProps) { constructor(props: NextOpenCloseMiniProps) {
super(props); super(props);
this.updateFromProps(props);
}
componentWillUpdate(nextProps: NextOpenCloseMiniProps, nextState: {}) {
this.updateFromProps(nextProps);
}
updateFromProps(props: NextOpenCloseMiniProps) {
this.xDay = props.xDay; this.xDay = props.xDay;
this.openOrClose = props.openOrClose; this.openOrClose = props.openOrClose;
this.allHolidays = props.allHolidays; this.allHolidays = props.allHolidays;
+8
View File
@@ -21,6 +21,14 @@ export class OpenXDay extends React.Component<OpenXDayProps, {}> {
constructor(props: OpenXDayProps) { constructor(props: OpenXDayProps) {
super(props); super(props);
this.updateFromProps(props);
}
componentWillUpdate(nextProps: OpenXDayProps, nextState: {}) {
this.updateFromProps(nextProps);
}
updateFromProps(props: OpenXDayProps) {
this.question = props.question; this.question = props.question;
this.xDay = props.xDay; this.xDay = props.xDay;
this.allHolidays = props.allHolidays; this.allHolidays = props.allHolidays;
+11
View File
@@ -1,6 +1,7 @@
import * as React from 'react'; import * as React from 'react';
import * as moment from 'moment-timezone'; import * as moment from 'moment-timezone';
import * as classnames from 'classnames'; import * as classnames from 'classnames';
import { Link } from 'react-router-dom';
import "./Component.css"; import "./Component.css";
import { HolidayList } from '../../Data'; import { HolidayList } from '../../Data';
import { Utils, HolidayAnswer } from "../../Utils"; import { Utils, HolidayAnswer } from "../../Utils";
@@ -20,6 +21,14 @@ export class OpenXDayMini extends React.Component<OpenXDayMiniProps, {}> {
constructor(props: OpenXDayMiniProps) { constructor(props: OpenXDayMiniProps) {
super(props); super(props);
this.updateFromProps(props);
}
componentWillUpdate(nextProps: OpenXDayMiniProps, nextState: {}) {
this.updateFromProps(nextProps);
}
updateFromProps(props: OpenXDayMiniProps) {
this.xDay = props.xDay; this.xDay = props.xDay;
this.dateDescription = props.dateDescription; this.dateDescription = props.dateDescription;
this.allHolidays = props.allHolidays; this.allHolidays = props.allHolidays;
@@ -32,6 +41,7 @@ export class OpenXDayMini extends React.Component<OpenXDayMiniProps, {}> {
return ( return (
<div className={"OpenXDayMini"} > <div className={"OpenXDayMini"} >
<Link to={`./${this.xDay.format("YYYY-MM-DD")}`}>
<div className="OpenXDayMini-inner"> <div className="OpenXDayMini-inner">
<div className={classnames([textColorClass, "openOrCloseText"])}> <div className={classnames([textColorClass, "openOrCloseText"])}>
{this.answer.open ? "Open" : "Closed"} {this.answer.open ? "Open" : "Closed"}
@@ -40,6 +50,7 @@ export class OpenXDayMini extends React.Component<OpenXDayMiniProps, {}> {
{this.dateDescription} {this.dateDescription}
</div> </div>
</div> </div>
</Link>
</div> </div>
); );
} }