Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new User profile component. Refactored user avatar. Added list …
…of user's books.
- Loading branch information
Showing
6 changed files
with
105 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,23 @@ | |||
import React, { Fragment } from 'react'; | |||
|
|||
const Books = ({ books }) => ( | |||
<Fragment> | |||
{books.map((book) => | |||
<div key={book.id} className="flex border-b border-solid border-grey-light"> | |||
<div className="w-3/4 p-4"> | |||
<h3>{book.title}</h3> | |||
<p className="text-grey-darker"> | |||
{[...Array(book.averageRating).keys()].map((s) => | |||
<span key={s}>★</span> | |||
)} | |||
</p> | |||
</div> | |||
<div className="w-1/4 p-4"> | |||
<img src={book.coverUrl} className="w-full" alt={book.title} /> | |||
</div> | |||
</div> | |||
)} | |||
</Fragment> | |||
); | |||
|
|||
export default Books; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,49 @@ | |||
import React, { Fragment } from 'react'; | |||
import { Query } from 'react-apollo'; | |||
import gql from 'graphql-tag'; | |||
import UserAvatar from './UserAvatar'; | |||
import Books from './Books'; | |||
|
|||
const USER_QUERY = gql` | |||
query User($id: ID!) { | |||
user(id: $id) { | |||
books { | |||
id | |||
title | |||
coverUrl | |||
averageRating | |||
} | |||
} | |||
} | |||
`; | |||
|
|||
const Users = ({ user, selectUser }) => ( | |||
<Query query={USER_QUERY} variables={{ id: user.id }}> | |||
{({ loading, error, data }) => { | |||
if (loading) return <div>Fetching..</div> | |||
if (error) return <div>Error!</div> | |||
|
|||
return ( | |||
<Fragment> | |||
<div className="flex my-4"> | |||
<button | |||
className="bg-grey-light hover:bg-grey text-grey-darkest font-bold py-2 px-4 rounded" | |||
onClick={selectUser.bind(this, null)}> | |||
Back | |||
</button> | |||
</div> | |||
<div className="flex mb-4"> | |||
<div className="my-4 w-1/4 rounded overflow-hidden"> | |||
<UserAvatar user={user} /> | |||
</div> | |||
<div className="my-4 px-4 w-3/4"> | |||
<Books books={data.user.books} /> | |||
</div> | |||
</div> | |||
</Fragment> | |||
) | |||
}} | |||
</Query> | |||
); | |||
|
|||
export default Users; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,15 @@ | |||
import React, { Fragment } from 'react'; | |||
import Gravatar from 'react-gravatar'; | |||
|
|||
const UserAvatar = ({ user }) => ( | |||
<Fragment> | |||
<Gravatar email={user.email} size={150} className="w-full" /> | |||
<div className="px-6 py-4"> | |||
<div className="font-bold text-xl mb-2">{user.name}</div> | |||
<p className="text-grey-darker text-sm">{user.email}</p> | |||
<p className="text-grey-darker text-base">{user.booksCount} books</p> | |||
</div> | |||
</Fragment> | |||
) | |||
|
|||
export default UserAvatar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters