aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/components/UserInfo.js
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2019-02-26 16:22:13 +0300
committerGravatar Vitaly Takmazov2023-01-13 10:37:54 +0300
commit695672f750ec9702c75a5020c90acba7b036380d (patch)
tree0cc4e5f386c531e485a232922ec61c8603f8274b /vnext/src/components/UserInfo.js
parentf507e0639cb29ccf74926177e7230255f07648fb (diff)
UserLink component
Diffstat (limited to 'vnext/src/components/UserInfo.js')
-rw-r--r--vnext/src/components/UserInfo.js29
1 files changed, 28 insertions, 1 deletions
diff --git a/vnext/src/components/UserInfo.js b/vnext/src/components/UserInfo.js
index c76ef0c7..0a601834 100644
--- a/vnext/src/components/UserInfo.js
+++ b/vnext/src/components/UserInfo.js
@@ -4,7 +4,7 @@ import { Link } from 'react-router-dom';
import { UserType } from './Types';
-import { info } from '../api';
+import { info, fetchUserUri } from '../api';
import Avatar from './Avatar';
import Icon from './Icon';
@@ -65,8 +65,35 @@ export default function UserInfo(props) {
);
}
+export function UserLink(props) {
+ const [user, setUser] = useState(props.user);
+ useEffect(() => {
+ setUser(props.user);
+ isMounted = true;
+ if (!user.uid && user.uri) {
+ fetchUserUri(user.uri).then(response => {
+ if (isMounted) {
+ setUser(response.data);
+ }
+ });
+ return () => {
+ isMounted = false;
+ };
+ }
+ }, [props.user]);
+ return (
+ user.uid ?
+ <Link key={user.uid} to={`/${user.uname}/`}>{user.uname}</Link>
+ : <a href={user.uri}>{user.uname}</a>
+ )
+}
+
UserInfo.propTypes = {
user: PropTypes.string.isRequired,
onUpdate: PropTypes.func,
children: PropTypes.node
};
+
+UserLink.propTypes = {
+ user: UserType.isRequired
+}