diff --git a/client/coral-framework/actions/assets.js b/client/coral-framework/actions/assets.js index 226f1b2b9..5de9a86d5 100644 --- a/client/coral-framework/actions/assets.js +++ b/client/coral-framework/actions/assets.js @@ -1,5 +1,5 @@ import coralApi from '../helpers/response'; -import addItem from './items'; +import {addItem} from './items'; export const FETCH_MULTIPLE_ASSETS = 'FETCH_MULTIPLE_ASSETS'; export const RECEIVE_MULTIPLE_ASSETS = 'RECEIVE_MULTIPLE_ASSETS'; @@ -9,10 +9,10 @@ export const fetchMulitpleAssets = ids => { return dispatch => { dispatch({type: FETCH_MULTIPLE_ASSETS}); - coralApi(`/asset/multi?ids=${encodeURIComponent(ids.join(','))}`) + coralApi(`/assets/multi?ids=${encodeURIComponent(ids.join(','))}`) .then(assets => { - dispatch({type: RECEIVE_MULTIPLE_ASSETS, assets}); - console.log('assets!', assets); + assets.forEach(asset => dispatch(addItem(asset, 'assets'))); + dispatch({type: RECEIVE_MULTIPLE_ASSETS, assets: assets.map(asset => asset.id)}); }) .catch(error => dispatch({type: FAILURE_MULTIPLE_ASSSETS, error})); }; diff --git a/client/coral-framework/reducers/items.js b/client/coral-framework/reducers/items.js index 93388c1ab..268557809 100644 --- a/client/coral-framework/reducers/items.js +++ b/client/coral-framework/reducers/items.js @@ -6,6 +6,7 @@ import * as actions from '../actions/items'; const initialState = fromJS({ comments: {}, users: {}, + assets: {}, actions: {} }); diff --git a/client/coral-framework/reducers/user.js b/client/coral-framework/reducers/user.js index c7badf458..c4d061b42 100644 --- a/client/coral-framework/reducers/user.js +++ b/client/coral-framework/reducers/user.js @@ -1,12 +1,14 @@ import {Map, fromJS} from 'immutable'; import * as authActions from '../constants/auth'; import * as actions from '../constants/user'; +import * as assetActions from '../actions/assets'; const initialState = Map({ displayName: '', profiles: [], settings: {}, - myComments: [] + myComments: [], + myAssets: [] // the assets from which myComments (above) originated }); const purge = user => { @@ -33,6 +35,8 @@ export default function user (state = initialState, action) { .set('settings', action.settings); case actions.RECEIVE_COMMENTS_BY_USER: return state.set('myComments', fromJS(action.comments)); + case assetActions.RECEIVE_MULTIPLE_ASSETS: + return state.set('myAssets', fromJS(action.assets)); default : return state; } diff --git a/client/coral-plugin-history/Comment.js b/client/coral-plugin-history/Comment.js index a14320ecd..c7a1f5336 100644 --- a/client/coral-plugin-history/Comment.js +++ b/client/coral-plugin-history/Comment.js @@ -5,14 +5,19 @@ import styles from './Comment.css'; const Comment = props => { return (
-

{props.comment.asset_id}

+

{props.asset.url}

{props.comment.body}

); }; Comment.propTypes = { - comment: PropTypes.object.isRequired + comment: PropTypes.shape({ + body: PropTypes.string + }).isRequired, + asset: PropTypes.shape({ + url: PropTypes.string + }).isRequired }; export default Comment; diff --git a/client/coral-plugin-history/CommentHistory.js b/client/coral-plugin-history/CommentHistory.js index cdeaaf3cd..b937e87e9 100644 --- a/client/coral-plugin-history/CommentHistory.js +++ b/client/coral-plugin-history/CommentHistory.js @@ -7,15 +7,19 @@ const CommentHistory = props => {

All Comments

{props.comments.map((comment, i) => { - console.log('a comment', comment); - return ; + const asset = props.assets.find(asset => asset.id === comment.asset_id); + return ; })}
); }; CommentHistory.propTypes = { - comments: PropTypes.arrayOf(PropTypes.object).isRequired + comments: PropTypes.arrayOf(PropTypes.object).isRequired, + assets: PropTypes.arrayOf(PropTypes.object).isRequired }; export default CommentHistory; diff --git a/client/coral-settings/containers/SettingsContainer.js b/client/coral-settings/containers/SettingsContainer.js index 0c63cc77d..9d535d595 100644 --- a/client/coral-settings/containers/SettingsContainer.js +++ b/client/coral-settings/containers/SettingsContainer.js @@ -49,7 +49,13 @@ class SignInContainer extends Component { Profile Settings - items.comments[id])} /> + { + user.myComments.length && user.myAssets.length + ? items.comments[id])} + assets={user.myAssets.map(id => items.assets[id])} /> + :

Loading comment history...

+ }
diff --git a/routes/api/assets/index.js b/routes/api/assets/index.js index 5229afe97..20fbf1630 100644 --- a/routes/api/assets/index.js +++ b/routes/api/assets/index.js @@ -40,6 +40,20 @@ router.get('/', (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); + }); +}); + // Get an asset by id. router.get('/:asset_id', (req, res, next) => { @@ -58,20 +72,6 @@ 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) => {