modify avatar url..
This commit is contained in:
@@ -179,7 +179,7 @@ export function InstructorChatPanel({ session, open, initialThreadId = null, ini
|
|||||||
) : threads.length > 0 ? (
|
) : threads.length > 0 ? (
|
||||||
<div className="space-y-2.5">
|
<div className="space-y-2.5">
|
||||||
{threads.map((thread) => (
|
{threads.map((thread) => (
|
||||||
<ThreadCard key={thread.id} accessToken={session.accessToken} thread={thread} onOpen={() => handleOpenThread(thread.id)} />
|
<ThreadCard key={thread.id} thread={thread} onOpen={() => handleOpenThread(thread.id)} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
@@ -192,7 +192,7 @@ export function InstructorChatPanel({ session, open, initialThreadId = null, ini
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ThreadCard({ accessToken, thread, onOpen }: { accessToken: string; thread: InstructorChatThread; onOpen: () => void }) {
|
function ThreadCard({ thread, onOpen }: { thread: InstructorChatThread; onOpen: () => void }) {
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -201,7 +201,7 @@ function ThreadCard({ accessToken, thread, onOpen }: { accessToken: string; thre
|
|||||||
onClick={onOpen}
|
onClick={onOpen}
|
||||||
>
|
>
|
||||||
<div className="flex items-start gap-3">
|
<div className="flex items-start gap-3">
|
||||||
<StudentAvatar accessToken={accessToken} thread={thread} />
|
<StudentAvatar thread={thread} />
|
||||||
<div className="min-w-0 flex-1">
|
<div className="min-w-0 flex-1">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<p className="truncate text-[14px] font-black text-[#111827]">{thread.studentName}</p>
|
<p className="truncate text-[14px] font-black text-[#111827]">{thread.studentName}</p>
|
||||||
@@ -222,43 +222,17 @@ function ThreadCard({ accessToken, thread, onOpen }: { accessToken: string; thre
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function StudentAvatar({ accessToken, thread }: { accessToken: string; thread: InstructorChatThread }) {
|
function StudentAvatar({ thread }: { thread: InstructorChatThread }) {
|
||||||
const [avatarSource, setAvatarSource] = useState<string | null>(null);
|
const [avatarFailed, setAvatarFailed] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!thread.studentAvatarUrl) {
|
setAvatarFailed(false);
|
||||||
setAvatarSource(null);
|
}, [thread.studentAvatarUrl]);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let revoked = false;
|
|
||||||
let objectUrl: string | null = null;
|
|
||||||
|
|
||||||
fetch(thread.studentAvatarUrl, {
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${accessToken}`,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.then((response) => (response.ok ? response.blob() : null))
|
|
||||||
.then((blob) => {
|
|
||||||
if (!blob || revoked) return;
|
|
||||||
objectUrl = URL.createObjectURL(blob);
|
|
||||||
setAvatarSource(objectUrl);
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
if (!revoked) setAvatarSource(null);
|
|
||||||
});
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
revoked = true;
|
|
||||||
if (objectUrl) URL.revokeObjectURL(objectUrl);
|
|
||||||
};
|
|
||||||
}, [accessToken, thread.studentAvatarUrl]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className="grid h-10 w-10 shrink-0 place-items-center overflow-hidden rounded-full bg-[#eef2ff] text-[#4f46e5] transition group-hover:bg-[#4f46e5] group-hover:text-white">
|
<span className="grid h-10 w-10 shrink-0 place-items-center overflow-hidden rounded-full bg-[#eef2ff] text-[#4f46e5] transition group-hover:bg-[#4f46e5] group-hover:text-white">
|
||||||
{avatarSource ? (
|
{thread.studentAvatarUrl && !avatarFailed ? (
|
||||||
<img className="h-full w-full object-cover" src={avatarSource} alt="" />
|
<img className="h-full w-full object-cover" src={thread.studentAvatarUrl} alt="" onError={() => setAvatarFailed(true)} />
|
||||||
) : (
|
) : (
|
||||||
<UserRound size={18} aria-hidden="true" />
|
<UserRound size={18} aria-hidden="true" />
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user