-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
View user profiles #582
View user profiles #582
Changes from 4 commits
5801eab
1679353
0b7c3b0
4117c7a
6e0077d
38b8e67
aae402f
a52a3cd
994e790
e07a2a6
3d26a1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { Pencil as PencilIcon } from '@styled-icons/boxicons-solid' | ||
import { Link } from 'react-router-dom' | ||
import styled from 'styled-components/macro' | ||
|
||
import { FRUITING_RATINGS, RATINGS } from '../../constants/ratings' | ||
|
@@ -146,7 +147,16 @@ const Review = ({ | |
{!editable && ( | ||
<cite> | ||
Reviewed on {formatISOString(review.created_at)} | ||
{review.author && <> by {review.author}</>} | ||
{review.author && ( | ||
<> | ||
{' by '} | ||
{review.user_id ? ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even undoing all the link styling is an option - then the feature won't be discoverable on mobile for now, and will only be known to be a link on desktop because of pointer cursor, but that's fine, since we don't have much content for the pages yet. |
||
<Link to={`/users/${review.user_id}`}>{review.author}</Link> | ||
) : ( | ||
review.author | ||
)} | ||
</> | ||
)} | ||
{review.observed_on && ( | ||
<> (visited {formatISOString(review.observed_on)})</> | ||
)} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { ArrowBack } from '@styled-icons/boxicons-regular' | ||
import { useEffect, useState } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { useParams } from 'react-router-dom' | ||
import styled from 'styled-components/macro' | ||
|
||
import { getUserById } from '../../utils/api' | ||
import { useAppHistory } from '../../utils/useAppHistory' | ||
import { PageScrollWrapper, PageTemplate } from '../about/PageTemplate' | ||
import BackButton from '../ui/BackButton' | ||
import { LoadingOverlay } from '../ui/LoadingIndicator' | ||
|
||
const StyledNavBack = styled.div` | ||
svg { | ||
height: 20px; | ||
margin-right: 5px; | ||
} | ||
` | ||
const UserProfile = () => { | ||
const { id } = useParams() | ||
const history = useAppHistory() | ||
const { t } = useTranslation() | ||
const [userData, setUserData] = useState({}) | ||
const [isLoading, setIsLoading] = useState(true) | ||
|
||
useEffect(() => { | ||
async function fetchUserData() { | ||
setIsLoading(true) | ||
const data = await getUserById(id) | ||
setUserData(data) | ||
|
||
// Log the fetched data | ||
console.log('Fetched User Data:', data) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's remove this logging statement when the PR is ready to merge |
||
|
||
setIsLoading(false) | ||
} | ||
|
||
fetchUserData() | ||
}, [id]) | ||
|
||
if (isLoading) { | ||
return <LoadingOverlay /> | ||
} | ||
|
||
const { created_at, name, bio } = userData | ||
|
||
return ( | ||
<PageScrollWrapper> | ||
<PageTemplate> | ||
<StyledNavBack> | ||
<BackButton | ||
onClick={(event) => { | ||
event.stopPropagation() | ||
history.goBack() | ||
}} | ||
> | ||
<ArrowBack /> | ||
{t('back')} | ||
</BackButton> | ||
</StyledNavBack> | ||
|
||
<h1>Name: {name}</h1> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good start since it shows the data! Can we iterate on the styling a bit, and try to use fewer words, so there's less need to translate them? My original quick attempt was a but I'm not great at styling pages. Maybe borrow the styling from the import page?
with the rest in |
||
<h3>Joined: {new Date(created_at).toISOString().slice(0, 10)}</h3> | ||
<h3>Bio: {bio}</h3> | ||
</PageTemplate> | ||
</PageScrollWrapper> | ||
) | ||
} | ||
|
||
export default UserProfile |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Route } from 'react-router-dom' | ||
|
||
import UserProfile from './UserProfile' | ||
|
||
const pages = [ | ||
{ | ||
path: ['/users/:id'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of this file, could you put the new route in auth routes, just under /users/sign_in etc. ? It doesn't completely belong there, but it'll help us understand the routing. It needs to be below the more specific routes (otherwise /users/sign_in will try to go to a user profile with id "sign_in", and fail). |
||
component: UserProfile, | ||
}, | ||
] | ||
|
||
const profileRoutes = pages.map((props) => ( | ||
<Route key={props.path[0]} path={props.path} component={props.component} /> | ||
)) | ||
|
||
export default profileRoutes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You only included it in the desktop layout - let's also have the user pages on mobile :). If you put the new route in authRoutes (see other comment), it'll work for both layouts.