Merge branch 'master' into ioredis

This commit is contained in:
Wyatt Johnson
2017-08-31 09:24:20 -06:00
committed by GitHub
7 changed files with 28 additions and 40 deletions
@@ -95,8 +95,7 @@ export default class Comment extends React.Component {
this.onClickEdit = this.onClickEdit.bind(this);
this.stopEditing = this.stopEditing.bind(this);
this.state = {
// Whether the comment should be editable (e.g. after a commenter clicking the 'Edit' button on their own comment)
isEditable: commentIsStillEditable(props.comment),
isEditing: false,
replyBoxVisible: false,
loadingState: '',
@@ -295,14 +294,12 @@ export default class Comment extends React.Component {
this.editWindowExpiryTimeout = clearTimeout(this.editWindowExpiryTimeout);
}
// if still in the edit window, set a timeout to re-render once it expires
const msLeftToEdit = editWindowRemainingMs(this.props.comment);
if (msLeftToEdit > 0) {
// if still in the edit window, set a timeout to handle expiration.
if (this.state.isEditable) {
const msLeftToEdit = editWindowRemainingMs(this.props.comment);
this.editWindowExpiryTimeout = setTimeout(() => {
// re-render
this.setState(this.state);
}, msLeftToEdit);
this.setState({isEditable: false});
}, Math.max(msLeftToEdit, 0));
}
}
componentWillUnmount() {
@@ -476,7 +473,7 @@ export default class Comment extends React.Component {
/* User can edit/delete their own comment for a short window after posting */
<span className={cn(styles.topRight)}>
{
commentIsStillEditable(comment) &&
this.state.isEditable &&
<a
className={cn(styles.link, {[styles.active]: this.state.isEditing})}
onClick={this.onClickEdit}>Edit</a>
@@ -1,4 +1,4 @@
import React from 'react';
import React, {Children} from 'react';
import {connect} from 'react-redux';
import PropTypes from 'prop-types';
import omit from 'lodash/omit';
@@ -28,18 +28,13 @@ class IfSlotIsEmpty extends React.Component {
}
render() {
const {className, component: Component = 'div', children} = this.props;
return (
<Component className={className}>
{this.isSlotEmpty() ? children : null}
</Component>
);
const {children} = this.props;
return this.isSlotEmpty() ? Children.only(children) : null;
}
}
IfSlotIsEmpty.propTypes = {
slot: PropTypes.string,
className: PropTypes.string,
};
const mapStateToProps = (state) => ({
@@ -1,4 +1,4 @@
import React from 'react';
import React, {Children} from 'react';
import {connect} from 'react-redux';
import PropTypes from 'prop-types';
import omit from 'lodash/omit';
@@ -28,18 +28,13 @@ class IfSlotIsNotEmpty extends React.Component {
}
render() {
const {className, component: Component = 'div', children} = this.props;
return (
<Component className={className}>
{this.isSlotEmpty() ? null : children}
</Component>
);
const {children} = this.props;
return this.isSlotEmpty() ? null : Children.only(children);
}
}
IfSlotIsNotEmpty.propTypes = {
slot: PropTypes.string,
className: PropTypes.string,
};
const mapStateToProps = (state) => ({
@@ -4,6 +4,7 @@ import {bindActionCreators} from 'redux';
import {sortOrderSelector, sortBySelector} from 'plugin-api/beta/client/selectors/stream';
import {setSort} from 'plugin-api/beta/client/actions/stream';
import hoistStatics from 'recompose/hoistStatics';
import {closeMenu} from 'plugins/talk-plugin-viewing-options/client/actions';
const mapStateToProps = (state) => ({
sortOrder: sortOrderSelector(state),
@@ -13,7 +14,8 @@ const mapStateToProps = (state) => ({
const mapDispatchToProps = (dispatch) =>
bindActionCreators(
{
setSort
setSort,
closeMenu,
},
dispatch
);
@@ -29,6 +31,7 @@ const mapDispatchToProps = (dispatch) =>
export default ({sortBy = 'created_at', sortOrder = 'DESC', label}) => hoistStatics((WrappedComponent) => {
class WithSortOption extends React.Component {
setSort = () => {
this.props.closeMenu();
this.props.setSort({sortBy, sortOrder});
}
+1 -5
View File
@@ -4,11 +4,7 @@
"talk-plugin-respect",
"talk-plugin-offtopic",
"talk-plugin-facebook-auth",
"talk-plugin-featured-comments",
"talk-plugin-sort-newest",
"talk-plugin-sort-oldest",
"talk-plugin-sort-most-liked",
"talk-plugin-sort-most-replied"
"talk-plugin-featured-comments"
],
"client": [
"talk-plugin-respect",
@@ -1,12 +1,12 @@
import React from 'react';
import styles from './Category.css';
import {Slot, IfSlotIsNotEmpty} from 'plugin-api/beta/client/components';
import {Slot} from 'plugin-api/beta/client/components';
const childFactory = (child) => <li className={styles.listItem} key={child.key}>{child}</li>;
const ViewingOptions = ({slot, title, data, asset, root}) => {
return (
<IfSlotIsNotEmpty slot={slot} className={styles.root}>
<div className={styles.root}>
<div className={styles.title}>{title}</div>
<Slot
fill={slot}
@@ -16,7 +16,7 @@ const ViewingOptions = ({slot, title, data, asset, root}) => {
data={data}
queryData={{asset, root}}
/>
</IfSlotIsNotEmpty>
</div>
);
};
@@ -2,6 +2,7 @@ import React from 'react';
import cn from 'classnames';
import styles from './Menu.css';
import {capitalize} from 'plugin-api/beta/client/utils';
import {IfSlotIsNotEmpty} from 'plugin-api/beta/client/components';
import Category from './Category';
import {t} from 'plugin-api/beta/client/services';
@@ -16,11 +17,12 @@ class Menu extends React.Component {
<div className={cn([styles.menu, 'talk-plugin-viewing-options-menu'])}>
{
Object.keys(this.categories).map((category) =>
<Category
key={category}
slot={`viewingOptions${capitalize(category)}`}
title={this.categories[category]}
/>
<IfSlotIsNotEmpty slot={`viewingOptions${capitalize(category)}`} key={category}>
<Category
slot={`viewingOptions${capitalize(category)}`}
title={this.categories[category]}
/>
</IfSlotIsNotEmpty>
)
}
</div>