From bfd4e28d019c914e9d4ec2d76f2bd355d2679d62 Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Wed, 2 Apr 2025 01:51:53 +0000 Subject: [PATCH] support for only icon --- .../app/src/components/UserPreview/index.jsx | 128 +++++++++--------- 1 file changed, 65 insertions(+), 63 deletions(-) diff --git a/packages/app/src/components/UserPreview/index.jsx b/packages/app/src/components/UserPreview/index.jsx index 098986ec..da00f0c4 100755 --- a/packages/app/src/components/UserPreview/index.jsx +++ b/packages/app/src/components/UserPreview/index.jsx @@ -9,74 +9,76 @@ import User from "@models/user" import "./index.less" -export default (props) => { - let [userData, setUserData] = React.useState(props.user) +const UserPreview = (props) => { + let [userData, setUserData] = React.useState(props.user) - const fetchUser = async () => { - if (!props.user_id && !props.username) { - console.error("Cannot fetch user data without user_id or username") - return false - } + const fetchUser = async () => { + if (!props.user_id && !props.username) { + console.error("Cannot fetch user data without user_id or username") + return false + } - const data = await User.data({ - user_id: props.user_id, - username: props.username - }).catch((err) => { - console.error(err) - app.message.error("Failed to fetch user data") - return null - }) + const data = await User.data({ + user_id: props.user_id, + username: props.username, + }).catch((err) => { + console.error(err) + app.message.error("Failed to fetch user data") + return null + }) - if (data) { - setUserData(data) - } - } + if (data) { + setUserData(data) + } + } - const handleOnClick = async () => { - if (typeof props.onClick !== "function") { - console.warn("UserPreview: onClick is not a function, executing default action") - return app.navigation.goToAccount(userData.username) - } + const handleOnClick = async () => { + if (typeof props.onClick !== "function") { + console.warn( + "UserPreview: onClick is not a function, executing default action", + ) + return app.navigation.goToAccount(userData.username) + } - return await props.onClick(userData) - } + return await props.onClick(userData) + } - React.useEffect(() => { - if (typeof userData === "undefined") { - fetchUser() - } - }, []) + React.useEffect(() => { + if (typeof userData === "undefined") { + fetchUser() + } + }, []) - if (!userData) { - return
- -
- } + if (!userData) { + return ( +
+ +
+ ) + } - return
-
- Avatar -
-
-

- {userData.fullName ?? userData.username} - {userData.verified && } -

- - @{userData.username} - -
-
-} \ No newline at end of file + return ( +
+
+ Avatar +
+ {!props.onlyIcon && ( +
+

+ {userData.fullName ?? userData.username} + {userData.verified && } +

+ @{userData.username} +
+ )} +
+ ) +} + +export default UserPreview