Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
✨ Support gravatars (#2091)
Luke Vellabadcf9eadcb8
diff --git a/apps/web/src/components/optimized-avatar-image.tsx b/apps/web/src/components/optimized-avatar-image.tsxindex d11789565..9d05fbf40 100644--- a/apps/web/src/components/optimized-avatar-image.tsx+++ b/apps/web/src/components/optimized-avatar-image.tsx@@ -4,31 +4,64 @@ import { Avatar, AvatarFallback, AvatarImage } from "@rallly/ui/avatar";import Image from "next/image";import React from "react";+async function getGravatarUrl(email: string): Promise<string | null> {+ if (typeof crypto === "undefined" || !crypto.subtle) {+ return null;+ }++ const normalizedEmail = email.trim().toLowerCase();+ const encoder = new TextEncoder();+ const data = encoder.encode(normalizedEmail);+ const hashBuffer = await crypto.subtle.digest("SHA-256", data);+ const hashArray = Array.from(new Uint8Array(hashBuffer));+ const hashHex = hashArray+ .map((b) => b.toString(16).padStart(2, "0"))+ .join("");+ return `https://0.gravatar.com/avatar/${hashHex}?d=404&s=128`;+}+export function OptimizedAvatarImage({size = "md",className,src,name,+ email,}: {size: "sm" | "md" | "lg" | "xl";src?: string;name: string;className?: string;+ email?: string;}) {const [isLoaded, setLoaded] = React.useState(false);+ const [gravatarUrl, setGravatarUrl] = React.useState<string | null>(null);++ React.useEffect(() => {+ if (!src && email) {+ getGravatarUrl(email)+ .then(setGravatarUrl)+ .catch(() => {+ setGravatarUrl(null);+ });+ }+ }, [src, email]);+const initials = name.split(" ").slice(0, 2).map((word) => word[0]).join("");++ const imageSrc = src || gravatarUrl;+return (<Avatar className={cn("rounded-full", className)} size={size}>- {src ? (- src.startsWith("https") || src.startsWith("data:") ? (- <AvatarImage src={src} alt={name} />+ {imageSrc ? (+ imageSrc.startsWith("https") || imageSrc.startsWith("data:") ? (+ <AvatarImage src={imageSrc} alt={name} />) : (<Image- src={`/api/storage/${src}`}+ src={`/api/storage/${imageSrc}`}width={128}height={128}alt={name}@@ -39,7 +72,7 @@ export function OptimizedAvatarImage({/>)) : null}- {!src || !isLoaded ? (+ {!imageSrc || !isLoaded ? (<AvatarFallback seed={name} className={cn("shrink-0")}>{initials}</AvatarFallback>diff --git a/apps/web/src/components/poll/desktop-poll/participant-row-form.tsx b/apps/web/src/components/poll/desktop-poll/participant-row-form.tsxindex 00c857d1b..f12706281 100644--- a/apps/web/src/components/poll/desktop-poll/participant-row-form.tsx+++ b/apps/web/src/components/poll/desktop-poll/participant-row-form.tsx@@ -24,6 +24,7 @@ import { toggleVote, VoteSelector } from "../vote-selector";export interface ParticipantRowFormProps {name?: string;className?: string;+ email?: string;isYou?: boolean;isNew?: boolean;onCancel?: () => void;@@ -31,6 +32,7 @@ export interface ParticipantRowFormProps {const ParticipantRowForm = ({name,+ email,isNew,className,}: ParticipantRowFormProps) => {@@ -62,7 +64,11 @@ const ParticipantRowForm = ({<div className="flex items-center justify-between gap-x-2.5"><Participant>{name ? (- <OptimizedAvatarImage name={participantName} size="sm" />+ <OptimizedAvatarImage+ name={participantName}+ size="sm"+ email={email}+ />) : (<YouAvatar />)}diff --git a/apps/web/src/components/poll/desktop-poll/participant-row.tsx b/apps/web/src/components/poll/desktop-poll/participant-row.tsxindex 68f47f5bf..9e1a1c3a0 100644--- a/apps/web/src/components/poll/desktop-poll/participant-row.tsx+++ b/apps/web/src/components/poll/desktop-poll/participant-row.tsx@@ -34,12 +34,13 @@ export interface ParticipantRowProps {export const ParticipantRowView: React.FunctionComponent<{name: string;+ email?: string;action?: React.ReactNode;votes: Array<VoteType | undefined>;className?: string;isYou?: boolean;participantId: string;-}> = ({ name, action, votes, className, isYou, participantId }) => {+}> = ({ name, email, action, votes, className, isYou, participantId }) => {return (<trdata-testid="participant-row"@@ -52,7 +53,7 @@ export const ParticipantRowView: React.FunctionComponent<{><div className="flex max-w-full items-center justify-between gap-x-1"><Participant>- <OptimizedAvatarImage size="sm" name={name} />+ <OptimizedAvatarImage size="sm" name={name} email={email} /><ParticipantName>{name}</ParticipantName></Participant><div className="flex items-center gap-x-2">@@ -104,6 +105,7 @@ const ParticipantRow: React.FunctionComponent<ParticipantRowProps> = ({<ParticipantRowFormclassName={className}name={participant.name}+ email={participant.email}isYou={isYou}onCancel={() => onChangeEditMode?.(false)}/>@@ -114,6 +116,7 @@ const ParticipantRow: React.FunctionComponent<ParticipantRowProps> = ({<ParticipantRowViewclassName={className}name={participant.name}+ email={participant.email}votes={optionIds.map((optionId) => {return getVote(participant.id, optionId);})}diff --git a/apps/web/src/components/poll/mobile-poll/poll-option.tsx b/apps/web/src/components/poll/mobile-poll/poll-option.tsxindex 7d672bbdf..e16d3f88d 100644--- a/apps/web/src/components/poll/mobile-poll/poll-option.tsx+++ b/apps/web/src/components/poll/mobile-poll/poll-option.tsx@@ -51,11 +51,15 @@ const PollOptionVoteSummary: React.FunctionComponent<{ optionId: string }> = ({) : (<div className="grid grid-cols-2 gap-2"><div className="col-span-1 space-y-2.5">- {participantsWhoVotedYes.map(({ name }, i) => (+ {participantsWhoVotedYes.map(({ name, email }, i) => (// biome-ignore lint/suspicious/noArrayIndexKey: Fix this later<div key={i} className="flex"><div className="relative mr-2.5 flex size-5 items-center justify-center">- <OptimizedAvatarImage size="sm" name={name} />+ <OptimizedAvatarImage+ size="sm"+ name={name}+ email={email ?? undefined}+ /><VoteIcontype="yes"size="sm"@@ -65,11 +69,15 @@ const PollOptionVoteSummary: React.FunctionComponent<{ optionId: string }> = ({<div className="truncate text-sm">{name}</div></div>))}- {participantsWhoVotedIfNeedBe.map(({ name }, i) => (+ {participantsWhoVotedIfNeedBe.map(({ name, email }, i) => (// biome-ignore lint/suspicious/noArrayIndexKey: Fix this later<div key={i} className="flex"><div className="relative mr-2.5 flex size-5 items-center justify-center">- <OptimizedAvatarImage size="sm" name={name} />+ <OptimizedAvatarImage+ size="sm"+ name={name}+ email={email ?? undefined}+ /><VoteIcontype="ifNeedBe"size="sm"@@ -81,11 +89,15 @@ const PollOptionVoteSummary: React.FunctionComponent<{ optionId: string }> = ({))}</div><div className="col-span-1 space-y-2.5">- {participantsWhoVotedNo.map(({ name }, i) => (+ {participantsWhoVotedNo.map(({ name, email }, i) => (// biome-ignore lint/suspicious/noArrayIndexKey: Fix this later<div key={i} className="flex"><div className="relative mr-2.5 flex size-5 items-center justify-center">- <OptimizedAvatarImage size="sm" name={name} />+ <OptimizedAvatarImage+ size="sm"+ name={name}+ email={email ?? undefined}+ /><VoteIcontype="no"size="sm"