more chance to see picture on user card
This commit is contained in:
parent
99dff44fd1
commit
23e8b81aa7
@ -1,4 +1,4 @@
|
|||||||
import React from 'react'
|
import React, { useMemo } from 'react'
|
||||||
import { sha256 } from 'js-sha256'
|
import { sha256 } from 'js-sha256'
|
||||||
import { useState, useEffect, useRef } from 'react'
|
import { useState, useEffect, useRef } from 'react'
|
||||||
import { Box, useColorMode, Text } from '@chakra-ui/react'
|
import { Box, useColorMode, Text } from '@chakra-ui/react'
|
||||||
@ -19,7 +19,7 @@ const REACTION_EMOJIS = {
|
|||||||
clap: '👏'
|
clap: '👏'
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getGravatarURL(email, user) {
|
export function getGravatarURL(email) {
|
||||||
if (!email) return void 0
|
if (!email) return void 0
|
||||||
const address = String(email).trim().toLowerCase()
|
const address = String(email).trim().toLowerCase()
|
||||||
const hash = sha256(address)
|
const hash = sha256(address)
|
||||||
@ -50,6 +50,8 @@ export const UserCard = ({
|
|||||||
const [showReaction, setShowReaction] = useState(false);
|
const [showReaction, setShowReaction] = useState(false);
|
||||||
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
|
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
|
||||||
|
|
||||||
|
const randomGravatarPath = useMemo(() => Math.random() * 1000, [])
|
||||||
|
|
||||||
// Обрабатываем изменение реакции
|
// Обрабатываем изменение реакции
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (reaction) {
|
if (reaction) {
|
||||||
@ -83,7 +85,7 @@ export const UserCard = ({
|
|||||||
position="relative"
|
position="relative"
|
||||||
>
|
>
|
||||||
<Avatar
|
<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={() => {
|
onError={() => {
|
||||||
if (!imageError && student.picture) {
|
if (!imageError && student.picture) {
|
||||||
setImageError(true);
|
setImageError(true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user