diff --git a/packages/app/src/components/UserCard/index.jsx b/packages/app/src/components/UserCard/index.jsx index 1401bcb0..24c1e851 100755 --- a/packages/app/src/components/UserCard/index.jsx +++ b/packages/app/src/components/UserCard/index.jsx @@ -10,256 +10,223 @@ import linksDecorators from "@config/linksDecorators" import "./index.less" function processValue(value, decorator) { - if (decorator.hrefResolve) { - if (!String(value).includes(decorator.hrefResolve)) { - return `${decorator.hrefResolve}${value}` - } - } + if (decorator.hrefResolve) { + if (!String(value).includes(decorator.hrefResolve)) { + return `${decorator.hrefResolve}${value}` + } + } - return value + return value } const UserLinkViewer = (props) => { - const { link, decorator } = props + const { link, decorator } = props - return
-
- { - createIconRender(decorator.icon ?? "MdLink") - } -
- -
-

- { - link.value - } -

-
-
+ return ( +
+
+ {createIconRender(decorator.icon ?? "MdLink")} +
+
+

{link.value}

+
+
+ ) } const UserLink = (props) => { - let { index, link } = props + let { index, link } = props - link.key = link.key.toLowerCase() + link.key = link.key.toLowerCase() - const decorator = linksDecorators[link.key] ?? {} + const decorator = linksDecorators[link.key] ?? {} - link.value = processValue(link.value, decorator) + link.value = processValue(link.value, decorator) - const hasHref = String(link.value).includes("://") + const hasHref = String(link.value).includes("://") - const handleOnClick = () => { - if (!hasHref) { - if (app.isMobile) { - app.layout.drawer.open("link_viewer", UserLinkViewer, { - componentProps: { - link: link, - decorator: decorator - } - }) - } - return false - } + const handleOnClick = () => { + if (!hasHref) { + if (app.isMobile) { + app.layout.drawer.open("link_viewer", UserLinkViewer, { + componentProps: { + link: link, + decorator: decorator, + }, + }) + } + return false + } - window.open(link.value, "_blank") - } + window.open(link.value, "_blank") + } - const renderName = () => { - if (decorator.hrefResolve) { - return decorator.label ?? link.value - } + const renderName = () => { + if (decorator.hrefResolve) { + return decorator.label ?? link.value + } - return link.value - } + return link.value + } - return + ) } -export const UserCard = React.forwardRef((props, ref) => { - const [user, setUser] = React.useState(props.user) +export const UserCard = (props) => { + const [user, setUser] = React.useState(props.user) - // TODO: Support API user data fetching + React.useEffect(() => { + setUser(props.user) + }, [props.user]) - return
-
- -
+ // TODO: Support API user data fetching -
-
-

- {user.public_name || user.username} - {user.verified && } -

- - @{user.username} - -
+ return ( +
+
+ +
- { - user.badges?.length > 0 && - } -
+
+
+

+ {user.public_name || user.username} + {user.verified && } +

+ @{user.username} +
-
- - {user.description} - -
+ {user.badges?.length > 0 && } +
- { - user.links && Array.isArray(user.links) && user.links.length > 0 &&
- { - user.links.map((link, index) => { - return - }) - } -
- } -
-}) +
+ {user.description} +
-export const MobileUserCard = React.forwardRef((props, ref) => { - return
-
- { - props.user.cover &&
-
+ {user.links && + Array.isArray(user.links) && + user.links.length > 0 && ( +
+ {user.links.map((link, index) => { + return ( + + ) + })} +
+ )} +
+ ) +} -
-
- -
-
-
- } +export const MobileUserCard = (props, ref) => { + return ( +
+
+ {props.user.cover && ( +
+
- { - !props.user.cover &&
- -
- } +
+
+ +
+
+
+ )} -
-
-

- { - props.user.fullName ?? `@${props.user.username}` - } - { - props.user.verified && - } -

+ {!props.user.cover && ( +
+ +
+ )} - { - props.user.fullName && - @{props.user.username} - - } -
+
+
+

+ {props.user.fullName ?? `@${props.user.username}`} + {props.user.verified && ( + + )} +

-
- { - props.user.badges?.length > 0 && - } -
+ {props.user.fullName && ( + @{props.user.username} + )} +
-
-

- { - props.user.description - } -

-
-
+
+ {props.user.badges?.length > 0 && ( + + )} +
- { - props.user.links - && Array.isArray(props.user.links) - && props.user.links.length > 0 - &&
- { - props.user.links.map((link, index) => { - return - }) - } -
- } -
+
+

{props.user.description}

+
+
-
- { - props.followers && - } + {props.user.links && + Array.isArray(props.user.links) && + props.user.links.length > 0 && ( +
+ {props.user.links.map((link, index) => { + return + })} +
+ )} +
- } - disabled - /> +
+ {props.followers && ( + + )} - } - /> -
-
-}) + } + disabled + /> -export default UserCard \ No newline at end of file + } /> +
+
+ ) +} + +export default UserCard