Merge pull request #404 from sharetribe/profile-image-added-to-listing-relations

profileImage to listing and tx relationships added
This commit is contained in:
Vesa Luusua 2017-09-15 11:31:55 +03:00 committed by GitHub
commit f4a3dcad5e
8 changed files with 38 additions and 14 deletions

View file

@ -12,8 +12,6 @@ const Avatar = props => {
const avatarUser = ensureUser(user);
const { displayName, abbreviatedName } = avatarUser.attributes.profile;
// TODO this is a temporary avatar fix for currentUser's profile data.
// Avatar images should be included to all user's attributes in the future.
if (avatarUser.profileImage && avatarUser.profileImage.id) {
return (
<div className={classes} title={displayName}>
@ -21,7 +19,10 @@ const Avatar = props => {
rootClassName={css.avatarImage}
alt={displayName}
image={avatarUser.profileImage}
nameSet={[{ name: 'square-xlarge', size: '1x' }, { name: 'square-xlarge2x', size: '2x' }]}
nameSet={[
{ name: 'square-xlarge2x', size: '1x' },
{ name: 'square-xlarge4x', size: '2x' },
]}
/>
</div>
);

View file

@ -90,7 +90,13 @@ export const loadData = (params, search) =>
const apiQueryParams = {
only: onlyFilter,
include: ['provider', 'customer', 'booking'],
include: [
'provider',
'provider.profileImage',
'customer',
'customer.profileImage',
'booking',
],
page,
per_page: INBOX_PAGE_SIZE,
};

View file

@ -45,7 +45,7 @@ export const showListing = listingId =>
dispatch(showListingRequest(listingId));
dispatch(fetchCurrentUser());
return sdk.listings
.show({ id: listingId, include: ['author', 'images'] })
.show({ id: listingId, include: ['author', 'author.profileImage', 'images'] })
.then(data => {
dispatch(addMarketplaceEntities(data));
return data;

View file

@ -52,7 +52,7 @@ describe('ListingPage', () => {
return showListing(id)(dispatch, null, sdk).then(data => {
expect(data).toEqual(response);
expect(show.mock.calls).toEqual([[{ id, include: ['author', 'images'] }]]);
expect(show.mock.calls).toEqual([[{ id, include: ['author', 'author.profileImage', 'images'] }]]);
expect(dispatch.mock.calls).toEqual([
[showListingRequest(id)],
[expect.anything()], // fetchCurrentUser() call
@ -76,7 +76,7 @@ describe('ListingPage', () => {
},
e => {
expect(e).toEqual(error);
expect(show.mock.calls).toEqual([[{ id, include: ['author', 'images'] }]]);
expect(show.mock.calls).toEqual([[{ id, include: ['author', 'author.profileImage', 'images'] }]]);
expect(dispatch.mock.calls).toEqual([
[showListingRequest(id)],
[expect.anything()], // fetchCurrentUser() call

View file

@ -57,7 +57,10 @@ export const fetchOrder = id =>
txResponse = response;
const listingId = listingRelationship(response).id;
return sdk.listings.show({ id: listingId, include: ['author', 'images'] });
return sdk.listings.show({
id: listingId,
include: ['author', 'author.profileImage', 'images'],
});
})
.then(response => {
dispatch(addMarketplaceEntities(txResponse));

View file

@ -133,8 +133,7 @@ export const updateProfile = actionPayload => {
.then(response => {
dispatch(updateProfileSuccess(response));
// Temporary denormalization for profileImage
// Profile image will be included to users
// Include profile image to denormalized user entity
const currentUserId = response.data.data.id;
const entities = updatedEntities({}, response.data);
const denormalised = denormalisedEntities(entities, 'current-user', [currentUserId]);

View file

@ -91,11 +91,27 @@ export const fetchSale = id =>
let txResponse = null;
return sdk.transactions
.show({ id, include: ['customer', 'provider', 'listing', 'booking'] }, { expand: true })
.show(
{
id,
include: [
'customer',
'customer.profileImage',
'provider',
'provider.profileImage',
'listing',
'booking',
],
},
{ expand: true }
)
.then(response => {
txResponse = response;
const listingId = listingRelationship(response).id;
return sdk.listings.show({ id: listingId, include: ['author', 'images'] });
return sdk.listings.show({
id: listingId,
include: ['author', 'author.profileImage', 'images'],
});
})
.then(response => {
dispatch(addMarketplaceEntities(txResponse));

View file

@ -321,8 +321,7 @@ export const fetchCurrentUser = () =>
return sdk.currentUser
.show({ include: ['profileImage'] })
.then(response => {
// Temporary denormalization for profileImage
// Profile image will be included to users
// Include profile image to denormalized user entity
const currentUserId = response.data.data.id;
const entities = updatedEntities({}, response.data);
const denormalised = denormalisedEntities(entities, 'current-user', [currentUserId]);