Skip to content

Commit

Permalink
feat: use dicebear api for default avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
FranGuam committed Jan 13, 2025
1 parent 2f70d03 commit 35a31d3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/app/ContestSite/ArenaPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ const ArenaPage: React.FC<ContestProps> = ({ mode, user }) => {
const firstImage = imageFiles[0];
return getAvatarUrl(firstImage.Key);
} else {
return "/UserOutlined.png";
return `https://api.dicebear.com/9.x/thumbs/svg?scale=80&backgroundType=gradientLinear&seed=${userId}`;
}
} catch (error) {
console.error("Failed to load avatar:", error);
return "/UserOutlined.png";
return `https://api.dicebear.com/9.x/thumbs/svg?scale=80&backgroundType=gradientLinear&seed=${userId}`;
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/app/ShareSite/CoursePage/DiscussDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ const DiscussDrawer: React.FC<CourseProps> = ({
const imageFiles = files.filter((file) =>
/\.(jpe?g|png)$/i.test(file.Key),
);
let avatarUrl = "/UserOutlined.png";
let avatarUrl = `https://api.dicebear.com/9.x/thumbs/svg?scale=80&backgroundType=gradientLinear&seed=${userId}`;
if (imageFiles.length > 0) {
const firstImage = imageFiles[0];
avatarUrl = await getAvatarUrl(firstImage.Key);
Expand All @@ -302,7 +302,7 @@ const DiscussDrawer: React.FC<CourseProps> = ({
return avatarUrl;
} catch (error) {
console.error("Failed to load avatar:", error);
return "/UserOutlined.png";
return `https://api.dicebear.com/9.x/thumbs/svg?scale=80&backgroundType=gradientLinear&seed=${userId}`;
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/app/UserSite/ProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const ProfilePage: React.FC<UserProps> = ({ mode, user, setUser }) => {
message.error("加载头像失败");
});
} else {
setImageUrl("/UserOutlined.png"); // 替换为实际的默认头像 URL
setImageUrl(`https://api.dicebear.com/9.x/thumbs/svg?scale=80&backgroundType=gradientLinear&seed=${user.uuid}`); // 替换为实际的默认头像 URL
}
})
.catch((error) => {
Expand Down
4 changes: 2 additions & 2 deletions src/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const App: React.FC = () => {
const firstImage = imageFiles[0];
return getAvatarUrl(firstImage.Key);
} else {
setImageUrl("/UserOutlined.png"); // 替换为默认头像 URL
setImageUrl(`https://api.dicebear.com/9.x/thumbs/svg?scale=80&backgroundType=gradientLinear&seed=${user.uuid}`); // 替换为默认头像 URL
return null;
}
})
Expand Down Expand Up @@ -501,7 +501,7 @@ const App: React.FC = () => {
const firstImage = imageFiles[0];
return getAvatarUrl(firstImage.Key);
} else {
setImageUrl("/UserOutlined.png"); // 替换为默认头像 URL
setImageUrl(`https://api.dicebear.com/9.x/thumbs/svg?scale=80&backgroundType=gradientLinear&seed=${user.uuid}`); // 替换为默认头像 URL
return null;
}
})
Expand Down

0 comments on commit 35a31d3

Please sign in to comment.