more chance to see picture on user card

This commit is contained in:
Primakov Alexandr Alexandrovich 2025-03-28 21:58:16 +03:00
parent 99dff44fd1
commit 23e8b81aa7

View File

@ -1,4 +1,4 @@
import React from 'react'
import React, { useMemo } from 'react'
import { sha256 } from 'js-sha256'
import { useState, useEffect, useRef } from 'react'
import { Box, useColorMode, Text } from '@chakra-ui/react'
@ -19,7 +19,7 @@ const REACTION_EMOJIS = {
clap: '👏'
}
export function getGravatarURL(email, user) {
export function getGravatarURL(email) {
if (!email) return void 0
const address = String(email).trim().toLowerCase()
const hash = sha256(address)
@ -50,6 +50,8 @@ export const UserCard = ({
const [showReaction, setShowReaction] = useState(false);
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
const randomGravatarPath = useMemo(() => Math.random() * 1000, [])
// Обрабатываем изменение реакции
useEffect(() => {
if (reaction) {
@ -83,7 +85,7 @@ export const UserCard = ({
position="relative"
>
<Avatar
src={imageError ? getGravatarURL(student.email, null) : (student.picture || getGravatarURL(student.email, null))}
src={imageError ? getGravatarURL(student.email || randomGravatarPath) : (student.picture || getGravatarURL(student.email))}
onError={() => {
if (!imageError && student.picture) {
setImageError(true);