Skip to content

Commit

Permalink
fix(classroom): show fallback avatar if the user's failed (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrious committed Mar 15, 2021
1 parent 6502433 commit e594ac0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions desktop/renderer-app/src/components/ChatPanel/ChatUser.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { observer } from "mobx-react-lite";
import React from "react";
import React, { useState } from "react";
import { User } from "../../stores/ClassRoomStore";
import { generateAvatar } from "../../utils/generateAvatar";
import "./ChatUser.less";

export type { User } from "../../stores/ClassRoomStore";
Expand All @@ -25,14 +26,20 @@ export const ChatUser = observer<ChatUserProps>(function ChatUser({
onAcceptRaiseHand,
onEndSpeaking,
}) {
const [isAvatarLoadFailed, setAvatarLoadFailed] = useState(false);
/** is current user the room owner */
const isCreator = ownerUUID === userUUID;
/** is this chat user element belongs to the current user */
const isCurrentUser = userUUID === user.userUUID;

return (
<div className="chat-user">
<img className="chat-user-avatar" src={user.avatar} alt={`User ${user.name}`} />
<img
className="chat-user-avatar"
src={isAvatarLoadFailed ? generateAvatar(userUUID) : user.avatar}
onError={() => setAvatarLoadFailed(true)}
alt={`User ${user.name}`}
/>
<span className="chat-user-name">{user.name}</span>
{ownerUUID === user.userUUID ? (
<span className="chat-user-status is-teacher">(老师)</span>
Expand Down

0 comments on commit e594ac0

Please sign in to comment.