From 2fc9b215a919960347d17adf18647071c2299d78 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 11 Sep 2022 20:17:40 -0500 Subject: [PATCH] Display custom badges on profiles --- app/soapbox/components/badge.tsx | 37 ++++++++++--------- .../ui/components/profile_info_panel.tsx | 21 ++++++++--- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/app/soapbox/components/badge.tsx b/app/soapbox/components/badge.tsx index 13646bcdb..7ba2d5408 100644 --- a/app/soapbox/components/badge.tsx +++ b/app/soapbox/components/badge.tsx @@ -3,24 +3,27 @@ import React from 'react'; interface IBadge { title: React.ReactNode, - slug: 'patron' | 'donor' | 'admin' | 'moderator' | 'bot' | 'opaque', + slug: string, } - /** Badge to display on a user's profile. */ -const Badge: React.FC = ({ title, slug }) => ( - - {title} - -); +const Badge: React.FC = ({ title, slug }) => { + const fallback = !['patron', 'admin', 'moderator', 'opaque', 'donor', 'badge:donor'].includes(slug); + + return ( + + {title} + + ); +}; export default Badge; diff --git a/app/soapbox/features/ui/components/profile_info_panel.tsx b/app/soapbox/features/ui/components/profile_info_panel.tsx index 2c0a9163b..c6c6d084e 100644 --- a/app/soapbox/features/ui/components/profile_info_panel.tsx +++ b/app/soapbox/features/ui/components/profile_info_panel.tsx @@ -8,6 +8,8 @@ import { Icon, HStack, Stack, Text } from 'soapbox/components/ui'; import VerificationBadge from 'soapbox/components/verification_badge'; import { useSoapboxConfig } from 'soapbox/hooks'; import { isLocal } from 'soapbox/utils/accounts'; +import { badgeToTag, getBadges as getAccountBadges } from 'soapbox/utils/badges'; +import { capitalize } from 'soapbox/utils/strings'; import ProfileFamiliarFollowers from './profile_familiar_followers'; import ProfileStats from './profile_stats'; @@ -52,7 +54,20 @@ const ProfileInfoPanel: React.FC = ({ account, username }) => } }; + const getCustomBadges = (): React.ReactNode[] => { + const badges = getAccountBadges(account); + + return badges.map(badge => ( + + )); + }; + const getBadges = (): React.ReactNode[] => { + const custom = getCustomBadges(); const staffBadge = getStaffBadge(); const isPatron = account.getIn(['patron', 'is_patron']) === true; @@ -66,11 +81,7 @@ const ProfileInfoPanel: React.FC = ({ account, username }) => badges.push(); } - if (account.donor) { - badges.push(); - } - - return badges; + return [...badges, ...custom]; }; const renderBirthday = (): React.ReactNode => {