mirror of
https://github.com/wassname/talk.git
synced 2026-08-14 12:50:17 +08:00
replaced eslint:recommended with prettier
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import {SET_CONTENT_SLOT, RESET_CONTENT_SLOT, OPEN_MENU, CLOSE_MENU} from './constants';
|
||||
import {
|
||||
SET_CONTENT_SLOT,
|
||||
RESET_CONTENT_SLOT,
|
||||
OPEN_MENU,
|
||||
CLOSE_MENU,
|
||||
} from './constants';
|
||||
|
||||
export const setContentSlot = (slot) => ({
|
||||
export const setContentSlot = slot => ({
|
||||
type: SET_CONTENT_SLOT,
|
||||
slot,
|
||||
});
|
||||
@@ -9,7 +14,7 @@ export const resetContentSlot = () => ({
|
||||
type: RESET_CONTENT_SLOT,
|
||||
});
|
||||
|
||||
export const openMenu = (id) => ({
|
||||
export const openMenu = id => ({
|
||||
type: OPEN_MENU,
|
||||
id,
|
||||
});
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
import React from 'react';
|
||||
import Menu from './Menu';
|
||||
import styles from './AuthorName.css';
|
||||
import {ClickOutside} from 'plugin-api/beta/client/components';
|
||||
import { ClickOutside } from 'plugin-api/beta/client/components';
|
||||
import cn from 'classnames';
|
||||
|
||||
export default ({data, root, asset, comment, contentSlot, menuVisible, toggleMenu, hideMenu}) => {
|
||||
export default ({
|
||||
data,
|
||||
root,
|
||||
asset,
|
||||
comment,
|
||||
contentSlot,
|
||||
menuVisible,
|
||||
toggleMenu,
|
||||
hideMenu,
|
||||
}) => {
|
||||
return (
|
||||
<ClickOutside onClickOutside={hideMenu}>
|
||||
<div className={cn(styles.root, 'talk-plugin-author-menu')}>
|
||||
@@ -12,11 +21,9 @@ export default ({data, root, asset, comment, contentSlot, menuVisible, toggleMen
|
||||
className={cn(styles.button, 'talk-plugin-author-menu-button')}
|
||||
onClick={toggleMenu}
|
||||
>
|
||||
<span className={styles.name}>
|
||||
{comment.user.username}
|
||||
</span>
|
||||
<span className={styles.name}>{comment.user.username}</span>
|
||||
</button>
|
||||
{menuVisible &&
|
||||
{menuVisible && (
|
||||
<Menu
|
||||
data={data}
|
||||
root={root}
|
||||
@@ -24,7 +31,7 @@ export default ({data, root, asset, comment, contentSlot, menuVisible, toggleMen
|
||||
comment={comment}
|
||||
contentSlot={contentSlot}
|
||||
/>
|
||||
}
|
||||
)}
|
||||
</div>
|
||||
</ClickOutside>
|
||||
);
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import React from 'react';
|
||||
import styles from './Menu.css';
|
||||
import {Slot} from 'plugin-api/beta/client/components';
|
||||
import { Slot } from 'plugin-api/beta/client/components';
|
||||
import cn from 'classnames';
|
||||
|
||||
export default ({data, root, asset, comment, contentSlot}) => {
|
||||
export default ({ data, root, asset, comment, contentSlot }) => {
|
||||
if (contentSlot) {
|
||||
return (
|
||||
<div className={cn(styles.menu, 'talk-plugin-author-menu-popup')}>
|
||||
<Slot
|
||||
fill={contentSlot}
|
||||
data={data}
|
||||
queryData={{asset, root, comment}}
|
||||
queryData={{ asset, root, comment }}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
@@ -22,13 +22,13 @@ export default ({data, root, asset, comment, contentSlot}) => {
|
||||
className={cn('talk-plugin-author-menu-infos')}
|
||||
fill={'authorMenuInfos'}
|
||||
data={data}
|
||||
queryData={{asset, root, comment}}
|
||||
queryData={{ asset, root, comment }}
|
||||
/>
|
||||
<Slot
|
||||
className={cn(styles.actions, 'talk-plugin-author-menu-actions')}
|
||||
fill={'authorMenuActions'}
|
||||
data={data}
|
||||
queryData={{asset, root, comment}}
|
||||
queryData={{ asset, root, comment }}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -4,4 +4,3 @@ export const SET_CONTENT_SLOT = `${prefix}_SET_CONTENT_SLOT`;
|
||||
export const RESET_CONTENT_SLOT = `${prefix}_RESET_CONTENT_SLOT`;
|
||||
export const OPEN_MENU = `${prefix}_OPEN_MENU`;
|
||||
export const CLOSE_MENU = `${prefix}_CLOSE_MENU`;
|
||||
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
import React from 'react';
|
||||
import {connect, withFragments} from 'plugin-api/beta/client/hocs';
|
||||
import {bindActionCreators} from 'redux';
|
||||
import { connect, withFragments } from 'plugin-api/beta/client/hocs';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import AuthorName from '../components/AuthorName';
|
||||
import {setContentSlot, resetContentSlot, openMenu, closeMenu} from '../actions';
|
||||
import {compose, gql} from 'react-apollo';
|
||||
import {getSlotFragmentSpreads, getShallowChanges} from 'plugin-api/beta/client/utils';
|
||||
import {
|
||||
setContentSlot,
|
||||
resetContentSlot,
|
||||
openMenu,
|
||||
closeMenu,
|
||||
} from '../actions';
|
||||
import { compose, gql } from 'react-apollo';
|
||||
import {
|
||||
getSlotFragmentSpreads,
|
||||
getShallowChanges,
|
||||
} from 'plugin-api/beta/client/utils';
|
||||
|
||||
class AuthorNameContainer extends React.Component {
|
||||
|
||||
shouldComponentUpdate(nextProps) {
|
||||
|
||||
// Specifically handle `showMenuForComment` if it is the only change.
|
||||
const changes = getShallowChanges(this.props, nextProps);
|
||||
if (changes.length === 1 && changes[0] === 'showMenuForComment') {
|
||||
@@ -32,45 +38,47 @@ class AuthorNameContainer extends React.Component {
|
||||
} else {
|
||||
this.props.openMenu(this.props.comment.id);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
hideMenu = () => {
|
||||
if (this.props.showMenuForComment === this.props.comment.id) {
|
||||
this.props.closeMenu();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
return <AuthorName
|
||||
data={this.props.data}
|
||||
root={this.props.root}
|
||||
asset={this.props.asset}
|
||||
comment={this.props.comment}
|
||||
contentSlot={this.props.contentSlot}
|
||||
menuVisible={this.props.showMenuForComment === this.props.comment.id}
|
||||
toggleMenu={this.toggleMenu}
|
||||
hideMenu={this.hideMenu}
|
||||
/>;
|
||||
return (
|
||||
<AuthorName
|
||||
data={this.props.data}
|
||||
root={this.props.root}
|
||||
asset={this.props.asset}
|
||||
comment={this.props.comment}
|
||||
contentSlot={this.props.contentSlot}
|
||||
menuVisible={this.props.showMenuForComment === this.props.comment.id}
|
||||
toggleMenu={this.toggleMenu}
|
||||
hideMenu={this.hideMenu}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const slots = [
|
||||
'authorMenuInfos',
|
||||
'authorMenuActions',
|
||||
];
|
||||
const slots = ['authorMenuInfos', 'authorMenuActions'];
|
||||
|
||||
const mapStateToProps = ({talkPluginAuthorMenu: state}) => ({
|
||||
const mapStateToProps = ({ talkPluginAuthorMenu: state }) => ({
|
||||
contentSlot: state.contentSlot,
|
||||
showMenuForComment: state.showMenuForComment,
|
||||
});
|
||||
|
||||
const mapDispatchToProps = (dispatch) =>
|
||||
bindActionCreators({
|
||||
setContentSlot,
|
||||
resetContentSlot,
|
||||
openMenu,
|
||||
closeMenu,
|
||||
}, dispatch);
|
||||
const mapDispatchToProps = dispatch =>
|
||||
bindActionCreators(
|
||||
{
|
||||
setContentSlot,
|
||||
resetContentSlot,
|
||||
openMenu,
|
||||
closeMenu,
|
||||
},
|
||||
dispatch
|
||||
);
|
||||
|
||||
const withAuthorNameFragments = withFragments({
|
||||
root: gql`
|
||||
@@ -96,7 +104,7 @@ const withAuthorNameFragments = withFragments({
|
||||
|
||||
const enhance = compose(
|
||||
connect(mapStateToProps, mapDispatchToProps),
|
||||
withAuthorNameFragments,
|
||||
withAuthorNameFragments
|
||||
);
|
||||
|
||||
export default enhance(AuthorNameContainer);
|
||||
|
||||
@@ -5,7 +5,7 @@ import translations from './translations.yml';
|
||||
export default {
|
||||
reducer,
|
||||
slots: {
|
||||
commentAuthorName: [AuthorName]
|
||||
commentAuthorName: [AuthorName],
|
||||
},
|
||||
translations
|
||||
translations,
|
||||
};
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import {SET_CONTENT_SLOT, RESET_CONTENT_SLOT, OPEN_MENU, CLOSE_MENU} from './constants';
|
||||
import {
|
||||
SET_CONTENT_SLOT,
|
||||
RESET_CONTENT_SLOT,
|
||||
OPEN_MENU,
|
||||
CLOSE_MENU,
|
||||
} from './constants';
|
||||
|
||||
const initialState = {
|
||||
contentSlot: null,
|
||||
@@ -7,28 +12,28 @@ const initialState = {
|
||||
|
||||
export default function reducer(state = initialState, action) {
|
||||
switch (action.type) {
|
||||
case SET_CONTENT_SLOT:
|
||||
return {
|
||||
...state,
|
||||
contentSlot: action.slot,
|
||||
};
|
||||
case RESET_CONTENT_SLOT:
|
||||
return {
|
||||
...state,
|
||||
contentSlot: initialState.contentSlot,
|
||||
};
|
||||
case OPEN_MENU:
|
||||
return {
|
||||
...state,
|
||||
showMenuForComment: action.id,
|
||||
};
|
||||
case CLOSE_MENU:
|
||||
return {
|
||||
...state,
|
||||
showMenuForComment: null,
|
||||
contentSlot: null,
|
||||
};
|
||||
default :
|
||||
return state;
|
||||
case SET_CONTENT_SLOT:
|
||||
return {
|
||||
...state,
|
||||
contentSlot: action.slot,
|
||||
};
|
||||
case RESET_CONTENT_SLOT:
|
||||
return {
|
||||
...state,
|
||||
contentSlot: initialState.contentSlot,
|
||||
};
|
||||
case OPEN_MENU:
|
||||
return {
|
||||
...state,
|
||||
showMenuForComment: action.id,
|
||||
};
|
||||
case CLOSE_MENU:
|
||||
return {
|
||||
...state,
|
||||
showMenuForComment: null,
|
||||
contentSlot: null,
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user