From 202528bce30af17e5308a2198829de7c011ca286 Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Sat, 22 Apr 2023 23:07:28 +0000 Subject: [PATCH] display user links on `UserCard` --- packages/app/constants/userLinksDecorators.js | 55 +++++++++++++ .../app/src/components/UserCard/index.jsx | 81 ++++++++++++++++++- .../app/src/components/UserCard/index.less | 48 +++++++++++ 3 files changed, 182 insertions(+), 2 deletions(-) create mode 100644 packages/app/constants/userLinksDecorators.js diff --git a/packages/app/constants/userLinksDecorators.js b/packages/app/constants/userLinksDecorators.js new file mode 100644 index 00000000..4704c766 --- /dev/null +++ b/packages/app/constants/userLinksDecorators.js @@ -0,0 +1,55 @@ +export default { + "github": { + icon: "SiGithub", + label: "GitHub", + hrefResolve: "https://github.com/" + }, + "twitter": { + icon: "SiTwitter", + label: "Twitter", + hrefResolve: "https://twitter.com/" + }, + "instagram": { + icon: "SiInstagram", + label: "Instagram", + hrefResolve: "https://instagram.com/" + }, + "facebook": { + icon: "SiFacebook", + label: "Facebook", + hrefResolve: "https://facebook.com/" + }, + "youtube": { + icon: "SiYoutube", + label: "YouTube", + hrefResolve: "https://youtube.com/channel/" + }, + "twitch": { + icon: "SiTwitch", + label: "Twitch", + hrefResolve: "https://twitch.tv/" + }, + "linkedin": { + icon: "SiLinkedin", + label: "LinkedIn", + hrefResolve: "https://linkedin.com/in/" + }, + "reddit": { + icon: "SiReddit", + label: "Reddit", + hrefResolve: "https://reddit.com/u/" + }, + "vrchat": { + icon: "VrChat", + label: "VRChat", + hrefResolve: "https://vrchat.com/home/user/" + }, + "discord": { + icon: "SiDiscord", + label: "Discord", + }, + "custom": { + icon: "MdLink", + label: "Custom", + } +} \ No newline at end of file diff --git a/packages/app/src/components/UserCard/index.jsx b/packages/app/src/components/UserCard/index.jsx index a499aec6..4081d35a 100755 --- a/packages/app/src/components/UserCard/index.jsx +++ b/packages/app/src/components/UserCard/index.jsx @@ -1,11 +1,68 @@ import React from "react" import * as antd from "antd" -import { Icons } from "components/Icons" +import { Icons, createIconRender } from "components/Icons" import { Image, UserBadges } from "components" +import linksDecorators from "schemas/userLinksDecorators" + import "./index.less" +function processValue(value, decorator) { + if (decorator.hrefResolve) { + if (!String(value).includes(decorator.hrefResolve)) { + return `${decorator.hrefResolve}${value}` + } + } + + return value +} + +const UserLink = (props) => { + let { index, link } = props + + link.key = link.key.toLowerCase() + + const decorator = linksDecorators[link.key] ?? {} + + link.value = processValue(link.value, decorator) + + const hasHref = String(link.value).includes("://") + + const handleOnClick = () => { + if (!hasHref) { + return false + } + + window.open(link.value, "_blank") + } + + const renderName = () => { + if (decorator.hrefResolve) { + return decorator.label ?? link.value + } + + return link.value + } + + return +} + export default React.forwardRef((props, ref) => { const [user, setUser] = React.useState(props.user) @@ -36,7 +93,11 @@ export default React.forwardRef((props, ref) => { { user.roles.includes("admin") && - + } { @@ -45,6 +106,12 @@ export default React.forwardRef((props, ref) => { } + { + user.roles.includes("internal_dev") && + + + + } @@ -59,5 +126,15 @@ export default React.forwardRef((props, ref) => { + + { + user.links && Array.isArray(user.links) && user.links.length > 0 &&
+ { + user.links.map((link, index) => { + return + }) + } +
+ } }) \ No newline at end of file diff --git a/packages/app/src/components/UserCard/index.less b/packages/app/src/components/UserCard/index.less index 7eec4422..bdbaf428 100755 --- a/packages/app/src/components/UserCard/index.less +++ b/packages/app/src/components/UserCard/index.less @@ -120,4 +120,52 @@ margin-bottom: 5px; } } + + .userLinks { + display: flex; + flex-direction: column; + + margin-top: 20px; + + gap: 10px; + + .userLink { + display: flex; + flex-direction: row; + + align-items: center; + + width: fit-content; + + gap: 5px; + + transition: all 0.3s ease-in-out; + + &.clickable { + cursor: pointer; + + &:hover { + + svg, + p { + color: var(--app-color); + } + } + } + + svg { + font-size: 1rem; + margin-right: 0 !important; + color: var(--text-color); + } + + p { + font-size: 0.8rem; + font-family: "Space grotesk", sans-serif; + font-weight: 600; + + user-select: text; + } + } + } } \ No newline at end of file