MemberProfilePreview.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import React from 'react';
  2. import { Image } from 'semantic-ui-react';
  3. import { IdentityIcon } from '@polkadot/react-components';
  4. import { Link } from 'react-router-dom';
  5. import { Text } from '@polkadot/types';
  6. import { AccountId } from '@polkadot/types/interfaces';
  7. import { MemberId, Profile } from '@joystream/types/members';
  8. import styled from 'styled-components';
  9. type ProfileItemProps = {
  10. avatar_uri: string | Text;
  11. root_account: string | AccountId;
  12. handle: string | Text;
  13. link?: boolean;
  14. id?: number | MemberId;
  15. };
  16. const StyledProfilePreview = styled.div`
  17. display: flex;
  18. align-items: center;
  19. & .ui.avatar.image {
  20. margin: 0 !important;
  21. width: 40px !important;
  22. height: 40px !important;
  23. }
  24. `;
  25. const Details = styled.div`
  26. margin-left: 1rem;
  27. display: grid;
  28. grid-row-gap: 0.25rem;
  29. grid-template-columns: 100%;
  30. `;
  31. const DetailsHandle = styled.h4`
  32. margin: 0;
  33. font-weight: bold;
  34. color: #333;
  35. `;
  36. const DetailsID = styled.div`
  37. color: #777;
  38. `;
  39. export default function ProfilePreview (
  40. { id, avatar_uri, root_account, handle, link = false, children }: React.PropsWithChildren<ProfileItemProps>
  41. ) {
  42. const Preview = (
  43. <StyledProfilePreview>
  44. {avatar_uri.toString() ? (
  45. <Image src={avatar_uri.toString()} avatar floated="left" />
  46. ) : (
  47. <IdentityIcon className="image" value={root_account.toString()} size={40} />
  48. )}
  49. <Details>
  50. <DetailsHandle>{handle.toString()}</DetailsHandle>
  51. { id !== undefined && <DetailsID>ID: {id.toString()}</DetailsID> }
  52. { children }
  53. </Details>
  54. </StyledProfilePreview>
  55. );
  56. if (link) {
  57. return <Link to={ `/members/${handle.toString()}` }>{ Preview }</Link>;
  58. }
  59. return Preview;
  60. }
  61. type ProfilePreviewFromStructProps = {
  62. profile: Profile;
  63. link?: boolean;
  64. id?: number | MemberId;
  65. };
  66. export function ProfilePreviewFromStruct (
  67. { profile, link, id, children }: React.PropsWithChildren<ProfilePreviewFromStructProps>
  68. ) {
  69. const { avatar_uri, root_account, handle } = profile;
  70. return (
  71. <ProfilePreview {...{ avatar_uri, root_account, handle, link, id }}>
  72. {children}
  73. </ProfilePreview>
  74. );
  75. }