mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-09-20 23:36:37 +08:00
Refactor avatar logic and badges (#3086)
This commit is contained in:
parent
df3980d745
commit
071043f08e
|
@ -1,5 +1,5 @@
|
|||
const badges: MonkeyTypes.UserBadge[] = [
|
||||
{
|
||||
const badges: Record<number, MonkeyTypes.UserBadge> = {
|
||||
1: {
|
||||
id: 1,
|
||||
name: "Developer",
|
||||
description: "I made this",
|
||||
|
@ -7,7 +7,7 @@ const badges: MonkeyTypes.UserBadge[] = [
|
|||
color: "white",
|
||||
customStyle: "animation: rgb-bg 10s linear infinite;",
|
||||
},
|
||||
{
|
||||
2: {
|
||||
id: 2,
|
||||
name: "Collaborator",
|
||||
description: "I helped make this",
|
||||
|
@ -15,7 +15,7 @@ const badges: MonkeyTypes.UserBadge[] = [
|
|||
color: "white",
|
||||
customStyle: "animation: rgb-bg 10s linear infinite;",
|
||||
},
|
||||
{
|
||||
3: {
|
||||
id: 3,
|
||||
name: "Server Mod",
|
||||
description: "Discord server moderator",
|
||||
|
@ -23,7 +23,7 @@ const badges: MonkeyTypes.UserBadge[] = [
|
|||
color: "white",
|
||||
customStyle: "animation: rgb-bg 10s linear infinite;",
|
||||
},
|
||||
{
|
||||
4: {
|
||||
id: 4,
|
||||
name: "OG Account",
|
||||
description: "First 100 users on the site",
|
||||
|
@ -31,7 +31,7 @@ const badges: MonkeyTypes.UserBadge[] = [
|
|||
color: "var(--bg-color)",
|
||||
background: "var(--main-color)",
|
||||
},
|
||||
{
|
||||
5: {
|
||||
id: 5,
|
||||
name: "OG Discordian",
|
||||
description: "First 100 Discord server members",
|
||||
|
@ -39,14 +39,10 @@ const badges: MonkeyTypes.UserBadge[] = [
|
|||
color: "var(--bg-color)",
|
||||
background: "var(--main-color)",
|
||||
},
|
||||
];
|
||||
|
||||
export function getById(id: number): MonkeyTypes.UserBadge | undefined {
|
||||
return badges.find((b) => b.id === id);
|
||||
}
|
||||
};
|
||||
|
||||
export function getHTMLById(id: number): string {
|
||||
const badge = getById(id);
|
||||
const badge = badges[id];
|
||||
if (!badge) {
|
||||
return "";
|
||||
}
|
||||
|
|
|
@ -275,15 +275,20 @@ function fillTable(lb: LbKey, prepend?: number): void {
|
|||
let avatar = `<div class="avatarPlaceholder"><i class="fas fa-user-circle"></i></div>`;
|
||||
|
||||
const snap = DB.getSnapshot();
|
||||
if (
|
||||
|
||||
const isCurrentUser =
|
||||
Auth.currentUser &&
|
||||
entry.uid === Auth.currentUser.uid &&
|
||||
snap.discordAvatar &&
|
||||
snap.discordId
|
||||
) {
|
||||
avatar = `<div class="avatar" style="background-image:url(https://cdn.discordapp.com/avatars/${snap.discordId}/${snap.discordAvatar}.png)"></div>`;
|
||||
} else if (entry.discordAvatar && entry.discordId) {
|
||||
avatar = `<div class="avatar" style="background-image:url(https://cdn.discordapp.com/avatars/${entry.discordId}/${entry.discordAvatar}.png)"></div>`;
|
||||
snap.discordId;
|
||||
|
||||
const entryHasAvatar = entry.discordAvatar && entry.discordId;
|
||||
|
||||
const avatarSource = (isCurrentUser && snap) || (entryHasAvatar && entry);
|
||||
|
||||
if (avatarSource) {
|
||||
const avatarUrl = `https://cdn.discordapp.com/avatars/${avatarSource.discordId}/${avatarSource.discordAvatar}.png?size=32`;
|
||||
avatar = `<div class="avatar" style="background-image:url(${avatarUrl})"></div>`;
|
||||
}
|
||||
|
||||
html += `
|
||||
|
|
Loading…
Reference in a new issue