mirror of
https://github.com/wassname/talk.git
synced 2026-07-01 18:05:06 +08:00
list comments out
This commit is contained in:
@@ -6,9 +6,6 @@ import {UPDATE_CONFIG} from '../constants/config';
|
||||
* Action name constants
|
||||
*/
|
||||
|
||||
export const REQUEST_COMMENTS_BY_USER = 'REQUEST_COMMENTS_BY_USER';
|
||||
export const RECEIVE_COMMENTS_BY_USER = 'RECEIVE_COMMENTS_BY_USER';
|
||||
export const FAILURE_COMMENTS_BY_USER = 'FAILURE_COMMENTS_BY_USER';
|
||||
export const ADD_ITEM = 'ADD_ITEM';
|
||||
export const UPDATE_ITEM = 'UPDATE_ITEM';
|
||||
export const APPEND_ITEM_ARRAY = 'APPEND_ITEM_ARRAY';
|
||||
@@ -82,34 +79,6 @@ export const appendItemArray = (id, property, value, add_to_front, item_type) =>
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* Get a list of comments by a single user
|
||||
*
|
||||
* @param {string} user_id
|
||||
* @returns Promise
|
||||
*/
|
||||
export const fetchCommentsByUserId = userId => {
|
||||
return (dispatch) => {
|
||||
dispatch({type: REQUEST_COMMENTS_BY_USER});
|
||||
return coralApi(`/comments/user/${userId}`)
|
||||
.then(comments => {
|
||||
dispatch({type: RECEIVE_COMMENTS_BY_USER, comments});
|
||||
|
||||
console.log('comments?', comments);
|
||||
|
||||
comments.forEach(comment => {
|
||||
dispatch(addItem(comment, 'comments'));
|
||||
});
|
||||
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('FAILURE_COMMENTS_BY_USER', error);
|
||||
dispatch({type: FAILURE_COMMENTS_BY_USER, error});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
* Get Items from Query
|
||||
* Gets a set of items from a predefined query
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as actions from '../constants/user';
|
||||
import {addNotification} from '../actions/notification';
|
||||
import {addItem} from '../actions/items';
|
||||
import coralApi from '../helpers/response';
|
||||
|
||||
import I18n from 'coral-framework/modules/i18n/i18n';
|
||||
@@ -19,3 +20,29 @@ export const saveBio = (user_id, formData) => dispatch => {
|
||||
})
|
||||
.catch(error => dispatch(saveBioFailure(error)));
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* Get a list of comments by a single user
|
||||
*
|
||||
* @param {string} user_id
|
||||
* @returns Promise
|
||||
*/
|
||||
export const fetchCommentsByUserId = userId => {
|
||||
return (dispatch) => {
|
||||
dispatch({type: actions.REQUEST_COMMENTS_BY_USER});
|
||||
return coralApi(`/comments/user/${userId}`)
|
||||
.then(comments => {
|
||||
comments.forEach(comment => {
|
||||
dispatch(addItem(comment, 'comments'));
|
||||
});
|
||||
|
||||
dispatch({type: actions.RECEIVE_COMMENTS_BY_USER, comments: comments.map(comment => comment.id)});
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error.stack);
|
||||
console.error('FAILURE_COMMENTS_BY_USER', error);
|
||||
dispatch({type: actions.FAILURE_COMMENTS_BY_USER, error});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
export const SAVE_BIO_REQUEST = 'SAVE_BIO_REQUEST';
|
||||
export const SAVE_BIO_SUCCESS = 'SAVE_BIO_SUCCESS';
|
||||
export const SAVE_BIO_FAILURE = 'SAVE_BIO_FAILURE';
|
||||
export const REQUEST_COMMENTS_BY_USER = 'REQUEST_COMMENTS_BY_USER';
|
||||
export const RECEIVE_COMMENTS_BY_USER = 'RECEIVE_COMMENTS_BY_USER';
|
||||
export const FAILURE_COMMENTS_BY_USER = 'FAILURE_COMMENTS_BY_USER';
|
||||
|
||||
@@ -17,7 +17,6 @@ export default (state = initialState, action) => {
|
||||
return state.setIn([action.item_type, action.id, action.property], fromJS(action.value));
|
||||
case actions.APPEND_ITEM_ARRAY:
|
||||
return state.updateIn([action.item_type, action.id, action.property], (prop) => {
|
||||
console.log(action, prop);
|
||||
if (action.add_to_front) {
|
||||
return prop ? prop.unshift(fromJS(action.value)) : fromJS([action.value]);
|
||||
} else {
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import {Map} from 'immutable';
|
||||
import {Map, fromJS} from 'immutable';
|
||||
import * as authActions from '../constants/auth';
|
||||
import * as actions from '../constants/user';
|
||||
|
||||
const initialState = Map({
|
||||
displayName: '',
|
||||
profiles: [],
|
||||
settings: {}
|
||||
settings: {},
|
||||
myComments: []
|
||||
});
|
||||
|
||||
const purge = user => {
|
||||
@@ -30,6 +31,8 @@ export default function user (state = initialState, action) {
|
||||
case actions.SAVE_BIO_SUCCESS:
|
||||
return state
|
||||
.set('settings', action.settings);
|
||||
case actions.RECEIVE_COMMENTS_BY_USER:
|
||||
return state.set('myComments', fromJS(action.comments));
|
||||
default :
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -1,24 +1,21 @@
|
||||
import React from 'react';
|
||||
import {connect} from 'react-redux';
|
||||
import React, {PropTypes} from 'react';
|
||||
|
||||
import styles from './CommentHistory.css';
|
||||
|
||||
class CommentHistory extends React.Component {
|
||||
render () {
|
||||
return (
|
||||
<div className={styles.header}>
|
||||
<h1>Comment History</h1>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const mapStateToProps = state => {
|
||||
return {
|
||||
config: state.config.toJS(),
|
||||
items: state.items.toJS(),
|
||||
auth: state.auth.toJS()
|
||||
};
|
||||
const CommentHistory = props => {
|
||||
return (
|
||||
<div className={styles.header}>
|
||||
<h1>Comment History</h1>
|
||||
{props.comments.map((comment, i) => {
|
||||
console.log('a comment', comment);
|
||||
return <p key={i}>{comment.body}</p>;
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps)(CommentHistory);
|
||||
CommentHistory.propTypes = {
|
||||
comments: PropTypes.arrayOf(PropTypes.object).isRequired
|
||||
};
|
||||
|
||||
export default CommentHistory;
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
import React from 'react';
|
||||
import styles from './CommentHistory.css';
|
||||
|
||||
export default ({comments = []}) => (
|
||||
<div className={styles.header}>
|
||||
<h1>Comments</h1>
|
||||
<ul>
|
||||
{comments.map(() => (
|
||||
<li>
|
||||
{/* Comment Data*/}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, {Component} from 'react';
|
||||
import {connect} from 'react-redux';
|
||||
|
||||
import {saveBio} from 'coral-framework/actions/user';
|
||||
import {saveBio, fetchCommentsByUserId} from 'coral-framework/actions/user';
|
||||
|
||||
import BioContainer from './BioContainer';
|
||||
import NotLoggedIn from '../components/NotLoggedIn';
|
||||
@@ -10,8 +10,6 @@ import CommentHistory from 'coral-plugin-history/CommentHistory';
|
||||
import SettingsHeader from '../components/SettingsHeader';
|
||||
import RestrictedContent from 'coral-framework/components/RestrictedContent';
|
||||
|
||||
import {fetchCommentsByUserId} from 'coral-framework/actions/items';
|
||||
|
||||
class SignInContainer extends Component {
|
||||
constructor (props) {
|
||||
super(props);
|
||||
@@ -35,7 +33,7 @@ class SignInContainer extends Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const {loggedIn, userData, showSignInDialog} = this.props;
|
||||
const {loggedIn, userData, showSignInDialog, items, user} = this.props;
|
||||
const {activeTab} = this.state;
|
||||
return (
|
||||
<RestrictedContent restricted={!loggedIn} restrictedComp={<NotLoggedIn showSignInDialog={showSignInDialog} />}>
|
||||
@@ -45,7 +43,7 @@ class SignInContainer extends Component {
|
||||
<Tab>Profile Settings</Tab>
|
||||
</TabBar>
|
||||
<TabContent show={activeTab === 0}>
|
||||
<CommentHistory {...this.props}/>
|
||||
<CommentHistory comments={user.myComments.map(id => items.comments[id])} />
|
||||
</TabContent>
|
||||
<TabContent show={activeTab === 1}>
|
||||
<BioContainer bio={userData.settings.bio} handleSave={this.handleSave} {...this.props} />
|
||||
@@ -55,7 +53,9 @@ class SignInContainer extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
const mapStateToProps = () => ({
|
||||
const mapStateToProps = state => ({
|
||||
items: state.items.toJS(),
|
||||
user: state.user.toJS()
|
||||
});
|
||||
|
||||
const mapDispatchToProps = dispatch => ({
|
||||
|
||||
Reference in New Issue
Block a user