Skip to content

Commit

Permalink
Merge pull request #1290 from GW2Treasures/feature/gravatar
Browse files Browse the repository at this point in the history
Add experimental gravatar image in admin user list
  • Loading branch information
darthmaim authored Jan 9, 2025
2 parents 01c0fba + b9eb6d8 commit 21cbb0c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion apps/web/app/admin/users/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ensureUserIsAdmin } from '../admin';
import { Tip } from '@gw2treasures/ui/components/Tip/Tip';
import { ProviderIcon } from '@/components/Provider/Provider';
import { FlexRow } from '@gw2treasures/ui/components/Layout/FlexRow';
import { Gravatar } from '@/components/User/Gravatar';

function getUsers() {
return db.user.findMany({
Expand All @@ -35,7 +36,7 @@ export default async function AdminUserPage() {

<Users.Table>
<Users.Column id="id" title="Id" hidden>{({ id }) => <Code inline borderless>{id}</Code>}</Users.Column>
<Users.Column id="name" title="Username" sortBy="name">{({ name }) => name}</Users.Column>
<Users.Column id="name" title="Username" sortBy="name">{({ name, defaultEmail }) => <FlexRow><Gravatar email={defaultEmail?.email}/>{name}</FlexRow>}</Users.Column>
<Users.Column id="providers" title="Providers" sortBy="name">
{({ providers }) => (
<FlexRow wrap>
Expand Down
19 changes: 19 additions & 0 deletions apps/web/components/User/Gravatar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-disable @next/next/no-img-element */
import { createHash } from 'node:crypto';
import { FC } from 'react';

interface GravatarProps {
email?: string
}

export const Gravatar: FC<GravatarProps> = ({ email }) => {
if(!email) {
return null;
}

const hash = createHash('sha256').update(email.trim().toLocaleLowerCase()).digest('hex');

return (
<img src={`https://gravatar.com/avatar/${hash}?s=48`} alt="" width={24} height={24} style={{ borderRadius: 2 }}/>
);
};

0 comments on commit 21cbb0c

Please sign in to comment.