Refactor avatar logic and badges (#3086)

This commit is contained in:
Bruce Berrios 2022-06-09 14:25:55 -04:00 committed by GitHub
parent df3980d745
commit 071043f08e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 18 deletions

View file

@ -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 "";
}

View file

@ -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 += `