Edit Window countdown is bold when < 10 seconds left

This commit is contained in:
Benjamin Goering
2017-05-03 17:27:36 -07:00
parent e31961716e
commit ab9c2a89b7
2 changed files with 21 additions and 4 deletions
@@ -68,6 +68,10 @@
flex-shrink: 0;
}
.editWindowAlmostOver {
font-weight: bold;
}
.link {
color: #2376D8;
cursor: pointer;
@@ -134,7 +134,11 @@ export class EditableCommentContent extends React.Component {
}
</span>
: <span>
<Icon name="timer"/> {lang.t('editComment.editWindowTimerPrefix')}<CountdownSeconds until={editableUntil} />
<Icon name="timer"/> {lang.t('editComment.editWindowTimerPrefix')}
<CountdownSeconds
until={editableUntil}
classNameForMsRemaining={(remainingMs) => (remainingMs <= 10 * 1000) ? styles.editWindowAlmostOver : '' }
/>
</span>
}
</span>
@@ -151,7 +155,8 @@ export class EditableCommentContent extends React.Component {
*/
class CountdownSeconds extends React.Component {
static propTypes = {
until: PropTypes.instanceOf(Date).isRequired
until: PropTypes.instanceOf(Date).isRequired,
classNameForMsRemaining: PropTypes.func,
}
constructor(props) {
super(props);
@@ -175,12 +180,20 @@ class CountdownSeconds extends React.Component {
}
render() {
const now = new Date();
const {until} = this.props;
const {until, classNameForMsRemaining} = this.props;
const msRemaining = until - now;
const secRemaining = msRemaining / 1000;
const wholeSecRemaining = Math.floor(secRemaining);
const plural = secRemaining !== 1;
const units = lang.t(plural ? 'editComment.secondsPlural' : 'editComment.second');
return <span>{`${wholeSecRemaining} ${units}`}</span>;
let classFromProp;
if (typeof classNameForMsRemaining === 'function') {
classFromProp = classNameForMsRemaining(msRemaining);
}
return (
<span className={classFromProp}>
{`${wholeSecRemaining} ${units}`}
</span>
);
}
}