mirror of
https://github.com/wassname/talk.git
synced 2026-09-09 11:38:08 +08:00
try to request a list of assets and fail
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import coralApi from '../helpers/response';
|
||||
import addItem from './items';
|
||||
|
||||
export const FETCH_MULTIPLE_ASSETS = 'FETCH_MULTIPLE_ASSETS';
|
||||
export const RECEIVE_MULTIPLE_ASSETS = 'RECEIVE_MULTIPLE_ASSETS';
|
||||
export const FAILURE_MULTIPLE_ASSSETS = 'FAILURE_MULTIPLE_ASSSETS';
|
||||
|
||||
export const fetchMulitpleAssets = ids => {
|
||||
return dispatch => {
|
||||
dispatch({type: FETCH_MULTIPLE_ASSETS});
|
||||
|
||||
coralApi(`/asset/multi?ids=${encodeURIComponent(ids.join(','))}`)
|
||||
.then(assets => {
|
||||
dispatch({type: RECEIVE_MULTIPLE_ASSETS, assets});
|
||||
console.log('assets!', assets);
|
||||
})
|
||||
.catch(error => dispatch({type: FAILURE_MULTIPLE_ASSSETS, error}));
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
.assetURL {
|
||||
|
||||
}
|
||||
|
||||
.commentBody {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import React, {PropTypes} from 'react';
|
||||
|
||||
import styles from './Comment.css';
|
||||
|
||||
const Comment = props => {
|
||||
return (
|
||||
<div>
|
||||
<p><a className={styles.assetURL} href={props.comment.asset_id}>{props.comment.asset_id}</a></p>
|
||||
<p className={styles.commentBody}>{props.comment.body}</p>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Comment.propTypes = {
|
||||
comment: PropTypes.object.isRequired
|
||||
};
|
||||
|
||||
export default Comment;
|
||||
@@ -1,14 +1,14 @@
|
||||
import React, {PropTypes} from 'react';
|
||||
|
||||
import Comment from './Comment';
|
||||
import styles from './CommentHistory.css';
|
||||
|
||||
const CommentHistory = props => {
|
||||
return (
|
||||
<div className={styles.header}>
|
||||
<h1>Comment History</h1>
|
||||
<h2>All Comments</h2>
|
||||
{props.comments.map((comment, i) => {
|
||||
console.log('a comment', comment);
|
||||
return <p key={i}>{comment.body}</p>;
|
||||
return <Comment key={i} comment={comment} />;
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -2,6 +2,7 @@ import React, {Component} from 'react';
|
||||
import {connect} from 'react-redux';
|
||||
|
||||
import {saveBio, fetchCommentsByUserId} from 'coral-framework/actions/user';
|
||||
import {fetchMulitpleAssets} from 'coral-framework/actions/assets';
|
||||
|
||||
import BioContainer from './BioContainer';
|
||||
import NotLoggedIn from '../components/NotLoggedIn';
|
||||
@@ -22,8 +23,13 @@ class SignInContainer extends Component {
|
||||
|
||||
componentWillMount () {
|
||||
// Fetch commentHistory
|
||||
console.log('userData', this.props.userData);
|
||||
this.props.fetchCommentsByUserId(this.props.userData.id);
|
||||
this.props.fetchCommentsByUserId(this.props.userData.id)
|
||||
.then(() => {
|
||||
const assetIds = this.props.user.myComments
|
||||
.map(id => this.props.items.comments[id])
|
||||
.map(comment => comment.asset_id);
|
||||
this.props.fetchMulitpleAssets(assetIds);
|
||||
});
|
||||
}
|
||||
|
||||
handleTabChange(tab) {
|
||||
@@ -60,7 +66,8 @@ const mapStateToProps = state => ({
|
||||
|
||||
const mapDispatchToProps = dispatch => ({
|
||||
saveBio: (user_id, formData) => dispatch(saveBio(user_id, formData)),
|
||||
fetchCommentsByUserId: userId => dispatch(fetchCommentsByUserId(userId))
|
||||
fetchCommentsByUserId: userId => dispatch(fetchCommentsByUserId(userId)),
|
||||
fetchMulitpleAssets: assetIds => dispatch(fetchMulitpleAssets(assetIds))
|
||||
});
|
||||
|
||||
export default connect(
|
||||
|
||||
@@ -152,6 +152,16 @@ AssetSchema.statics.search = (value) => value.length === 0 ? Asset.find({}) : As
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Finds multiple assets with matching ids
|
||||
* @param {Array} ids an array of Strings of asset_id
|
||||
* @return {Promise} resolves to list of Assets
|
||||
*/
|
||||
AssetSchema.statics.findMultipleById = function (ids) {
|
||||
const query = ids.map(id => ({id}));
|
||||
return Asset.find(query);
|
||||
};
|
||||
|
||||
const Asset = mongoose.model('Asset', AssetSchema);
|
||||
|
||||
module.exports = Asset;
|
||||
|
||||
@@ -58,6 +58,20 @@ router.get('/:asset_id', (req, res, next) => {
|
||||
});
|
||||
});
|
||||
|
||||
// get multiple assets with a comma-separated list of asset ids
|
||||
router.get('/multi', (req, res, next) => {
|
||||
const assetIds = req.query.ids.split(',');
|
||||
|
||||
Asset.findMultipleById(assetIds)
|
||||
.then(assets => {
|
||||
res.json(assets);
|
||||
})
|
||||
.catch(error => {
|
||||
error.status = 500;
|
||||
next(error);
|
||||
});
|
||||
});
|
||||
|
||||
// Adds the asset id to the queue to be scraped.
|
||||
router.post('/:asset_id/scrape', (req, res, next) => {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user