elements.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import React, { useEffect, useState } from 'react';
  2. import moment from 'moment';
  3. import { Card, Icon, Image, Label, Statistic } from 'semantic-ui-react';
  4. import { Link } from 'react-router-dom';
  5. import { Balance } from '@polkadot/types/interfaces';
  6. import { formatBalance } from '@polkadot/util';
  7. import Identicon from '@polkadot/react-identicon';
  8. import { IProfile, MemberId } from '@joystream/types/members';
  9. import { GenericAccountId } from '@polkadot/types';
  10. import { LeadRoleState } from '@joystream/types/content-working-group';
  11. import { WorkerId } from '@joystream/types/working-group';
  12. type BalanceProps = {
  13. balance?: Balance;
  14. }
  15. export function BalanceView (props: BalanceProps) {
  16. return (
  17. <div className="balance">
  18. <span>Balance:</span> {formatBalance(props.balance)}
  19. </div>
  20. );
  21. }
  22. type ProfileProps = {
  23. profile: IProfile;
  24. }
  25. export function HandleView (props: ProfileProps) {
  26. if (typeof props.profile === 'undefined') {
  27. return null;
  28. }
  29. return (
  30. <Link to={`/members/${props.profile.handle.toString()}`}>{props.profile.handle.toString()}</Link>
  31. );
  32. }
  33. export type GroupMember = {
  34. memberId: MemberId;
  35. roleAccount: GenericAccountId;
  36. profile: IProfile;
  37. title: string;
  38. stake?: Balance;
  39. earned?: Balance;
  40. }
  41. export type GroupLead = {
  42. memberId: MemberId;
  43. workerId?: WorkerId; // In case of "working-group" module
  44. roleAccount: GenericAccountId;
  45. profile: IProfile;
  46. title: string;
  47. stage?: LeadRoleState;
  48. }
  49. type inset = {
  50. inset?: boolean;
  51. }
  52. export function GroupLeadView (props: GroupLead & inset) {
  53. let fluid = false;
  54. if (typeof props.inset !== 'undefined') {
  55. fluid = props.inset;
  56. }
  57. let avatar = <Identicon value={props.roleAccount.toString()} size={50} />;
  58. if (typeof props.profile.avatar_uri !== 'undefined' && props.profile.avatar_uri.toString() !== '') {
  59. avatar = <Image src={props.profile.avatar_uri.toString()} circular className='avatar' />;
  60. }
  61. return (
  62. <Card color='grey' className="staked-card" fluid={fluid}>
  63. <Card.Content>
  64. <Image floated='right'>
  65. {avatar}
  66. </Image>
  67. <Card.Header><HandleView profile={props.profile} /></Card.Header>
  68. <Card.Meta>{props.title}</Card.Meta>
  69. <Card.Description>
  70. <Label color='teal' ribbon={fluid}>
  71. <Icon name="shield" />
  72. { props.title }
  73. <Label.Detail>{/* ... */}</Label.Detail>
  74. </Label>
  75. </Card.Description>
  76. </Card.Content>
  77. {/* <Card.Content extra>
  78. <Label>Something about <Label.Detail> the lead </Label.Detail></Label>
  79. </Card.Content> */}
  80. </Card>
  81. );
  82. }
  83. export function GroupMemberView (props: GroupMember & inset) {
  84. let fluid = false;
  85. if (typeof props.inset !== 'undefined') {
  86. fluid = props.inset;
  87. }
  88. let stake = null;
  89. if (typeof props.stake !== 'undefined' && props.stake.toNumber() !== 0) {
  90. stake = (
  91. <Label color='green' ribbon={fluid}>
  92. <Icon name="shield" />
  93. Staked
  94. <Label.Detail>{formatBalance(props.stake)}</Label.Detail>
  95. </Label>
  96. );
  97. }
  98. let avatar = <Identicon value={props.roleAccount.toString()} size={50} />;
  99. if (typeof props.profile.avatar_uri !== 'undefined' && props.profile.avatar_uri.toString() !== '') {
  100. avatar = <Image src={props.profile.avatar_uri.toString()} circular className='avatar' />;
  101. }
  102. let earned = null;
  103. if (typeof props.earned !== 'undefined' &&
  104. props.earned.toNumber() > 0 &&
  105. !fluid) {
  106. earned = (
  107. <Card.Content extra>
  108. <Label>Earned <Label.Detail>{formatBalance(props.earned)}</Label.Detail></Label>
  109. </Card.Content>
  110. );
  111. }
  112. return (
  113. <Card color='grey' className="staked-card" fluid={fluid}>
  114. <Card.Content>
  115. <Image floated='right'>
  116. {avatar}
  117. </Image>
  118. <Card.Header><HandleView profile={props.profile} /></Card.Header>
  119. <Card.Meta>{props.title}</Card.Meta>
  120. <Card.Description>
  121. {stake}
  122. </Card.Description>
  123. </Card.Content>
  124. {earned}
  125. </Card>
  126. );
  127. }
  128. type CountdownProps = {
  129. end: Date;
  130. }
  131. export function Countdown (props: CountdownProps) {
  132. let interval = -1;
  133. const [days, setDays] = useState<number | undefined>(undefined);
  134. const [hours, setHours] = useState<number | undefined>(undefined);
  135. const [minutes, setMinutes] = useState<number | undefined>(undefined);
  136. const [seconds, setSeconds] = useState<number | undefined>(undefined);
  137. const update = () => {
  138. const then = moment(props.end);
  139. const now = moment();
  140. const d = moment.duration(then.diff(now));
  141. setDays(d.days());
  142. setHours(d.hours());
  143. setMinutes(d.minutes());
  144. setSeconds(d.seconds());
  145. };
  146. interval = window.setInterval(update, 1000);
  147. useEffect(() => {
  148. update();
  149. return () => {
  150. clearInterval(interval);
  151. };
  152. }, []);
  153. if (!seconds) {
  154. return null;
  155. }
  156. return (
  157. <div className='countdown wrapper'>
  158. <Statistic size="tiny">
  159. <Statistic.Value>{days}</Statistic.Value>
  160. <Statistic.Label>Days</Statistic.Label>
  161. </Statistic>
  162. <Statistic size="tiny">
  163. <Statistic.Value>{hours}</Statistic.Value>
  164. <Statistic.Label>hours</Statistic.Label>
  165. </Statistic>
  166. <Statistic size="tiny">
  167. <Statistic.Value>{minutes}</Statistic.Value>
  168. <Statistic.Label>minutes</Statistic.Label>
  169. </Statistic>
  170. <Statistic size="tiny">
  171. <Statistic.Value>{seconds}</Statistic.Value>
  172. <Statistic.Label>seconds</Statistic.Label>
  173. </Statistic>
  174. </div>
  175. );
  176. }