-
Notifications
You must be signed in to change notification settings - Fork 4
Search for meee - User pages and avatars #162
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
45bec2f
feat(users): add Hackweek profile histories
NinjaLikesCheez f6b9cf4
feat(users): cache avatars and surface project awards
NinjaLikesCheez 0d8863a
fix(users): align profile ownership and avatar caching
NinjaLikesCheez 98ed52c
fix(users): validate backfilled avatar streams
NinjaLikesCheez 1680bc3
chore(users): sync profile search with master
HazAT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import {useEffect, useState} from 'react'; | ||
|
|
||
| export function UserAvatar({ | ||
| user, | ||
| className = '', | ||
| }: { | ||
| user: {id: string; displayName: string; avatarUrl?: string | null}; | ||
| className?: string; | ||
| }) { | ||
| const [failed, setFailed] = useState(false); | ||
|
|
||
| useEffect(() => setFailed(false), [user.id, user.avatarUrl]); | ||
|
|
||
| const classes = `userAvatar${className ? ` ${className}` : ''}`; | ||
| if (!user.avatarUrl || failed) { | ||
| return ( | ||
| <span className={`${classes} userAvatar--fallback`} aria-hidden="true"> | ||
| {initials(user.displayName)} | ||
| </span> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <img | ||
| className={classes} | ||
| src={`/api/users/${encodeURIComponent(user.id)}/avatar`} | ||
| alt="" | ||
| loading="lazy" | ||
| decoding="async" | ||
| width={64} | ||
| height={64} | ||
| onError={() => setFailed(true)} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| function initials(value: string) { | ||
| return value | ||
| .split(/\s+/) | ||
| .slice(0, 2) | ||
| .map((part) => part[0]) | ||
| .join('') | ||
| .toUpperCase(); | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import {Link, useParams} from 'wouter'; | ||
|
|
||
| import {PageState, QueryState} from '../components/AppLayout'; | ||
| import {ProjectCard} from '../components/ProjectCard'; | ||
| import {UserAvatar} from '../components/UserAvatar'; | ||
| import {useUserProfile} from '../queries/projects'; | ||
|
|
||
| export function UserPage() { | ||
| const {userId} = useParams<{userId: string}>(); | ||
| const profile = useUserProfile(userId); | ||
|
|
||
| return ( | ||
| <QueryState loading={profile.isLoading} error={profile.error}> | ||
| {profile.data && ( | ||
| <main className="userPage"> | ||
| <header className="userHero"> | ||
| <Link className="backLink" href="/years"> | ||
| ← hackweek archive | ||
| </Link> | ||
| <div className="userIdentity"> | ||
| <UserAvatar user={profile.data.user} /> | ||
| <div> | ||
| <p className="kicker">Hackweek maker</p> | ||
| <h1>{profile.data.user.displayName}</h1> | ||
| <a href={`mailto:${profile.data.user.email}`}> | ||
| {profile.data.user.email} | ||
| </a> | ||
| </div> | ||
| </div> | ||
| <dl className="userHighlights" aria-label="Hackweek highlights"> | ||
| <Highlight | ||
| value={profile.data.highlights.hackweekCount} | ||
| label="Hackweeks" | ||
| /> | ||
| <Highlight value={profile.data.highlights.projectCount} label="Projects" /> | ||
| <Highlight value={profile.data.highlights.ideaCount} label="Ideas opened" /> | ||
| <Highlight value={profile.data.highlights.awardCount} label="Awards" /> | ||
| </dl> | ||
| </header> | ||
|
|
||
| {profile.data.awards.length > 0 && ( | ||
| <section className="userAwards" aria-labelledby="user-awards-title"> | ||
| <header> | ||
| <p className="kicker">Highlights</p> | ||
| <h2 id="user-awards-title">award shelf</h2> | ||
| </header> | ||
| <div> | ||
| {profile.data.awards.map((award) => ( | ||
| <Link | ||
| key={award.id} | ||
| href={`/years/${award.yearId}/projects/${award.projectId}`} | ||
| > | ||
| <span>{award.yearId}</span> | ||
| <strong>{award.name || award.categoryName}</strong> | ||
| <small>{award.projectName}</small> | ||
| </Link> | ||
| ))} | ||
| </div> | ||
| </section> | ||
| )} | ||
|
|
||
| {!profile.data.years.length ? ( | ||
| <PageState | ||
| title="No Hackweek history yet" | ||
| detail={`${profile.data.user.displayName} has not joined or opened a project yet.`} | ||
| /> | ||
| ) : ( | ||
| <div className="userTimeline"> | ||
| {profile.data.years.map((year) => ( | ||
| <section | ||
| className="userYear" | ||
| aria-labelledby={`user-year-${year.yearId}`} | ||
| key={year.yearId} | ||
| > | ||
| <header> | ||
| <div> | ||
| <p className="kicker">Hackweek</p> | ||
| <h2 id={`user-year-${year.yearId}`}>{year.yearId}</h2> | ||
| </div> | ||
| <Link href={`/years/${year.yearId}/projects`}>view year →</Link> | ||
| </header> | ||
| <div className="projectGrid"> | ||
| {year.projects.map((project) => ( | ||
| <ProjectCard project={project} key={project.id} /> | ||
| ))} | ||
| </div> | ||
| </section> | ||
| ))} | ||
| </div> | ||
| )} | ||
| </main> | ||
| )} | ||
| </QueryState> | ||
| ); | ||
| } | ||
|
|
||
| function Highlight({value, label}: {value: number; label: string}) { | ||
| return ( | ||
| <div> | ||
| <dt>{label}</dt> | ||
| <dd>{value}</dd> | ||
| </div> | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.