import React, { useEffect, useState } from 'react';
import moment from 'moment';
import { Card, Icon, Image, Label, Statistic } from 'semantic-ui-react';
import { Link } from 'react-router-dom';
import { Balance } from '@polkadot/types/interfaces';
import { formatBalance } from '@polkadot/util';
import Identicon from '@polkadot/react-identicon';
import { IProfile, MemberId } from '@joystream/types/members';
import { GenericAccountId } from '@polkadot/types';
import { LeadRoleState } from '@joystream/types/content-working-group';
import { WorkerId } from '@joystream/types/working-group';
type BalanceProps = {
balance?: Balance;
}
export function BalanceView (props: BalanceProps) {
return (
Balance: {formatBalance(props.balance)}
);
}
type ProfileProps = {
profile: IProfile;
}
export function HandleView (props: ProfileProps) {
if (typeof props.profile === 'undefined') {
return null;
}
return (
{props.profile.handle.toString()}
);
}
export type GroupMember = {
memberId: MemberId;
roleAccount: GenericAccountId;
profile: IProfile;
title: string;
stake?: Balance;
earned?: Balance;
}
export type GroupLead = {
memberId: MemberId;
workerId?: WorkerId; // In case of "working-group" module
roleAccount: GenericAccountId;
profile: IProfile;
title: string;
stage?: LeadRoleState;
}
type inset = {
inset?: boolean;
}
export function GroupLeadView (props: GroupLead & inset) {
let fluid = false;
if (typeof props.inset !== 'undefined') {
fluid = props.inset;
}
let avatar = ;
if (typeof props.profile.avatar_uri !== 'undefined' && props.profile.avatar_uri.toString() !== '') {
avatar = ;
}
return (
{avatar}
{props.title}
{/*
*/}
);
}
export function GroupMemberView (props: GroupMember & inset) {
let fluid = false;
if (typeof props.inset !== 'undefined') {
fluid = props.inset;
}
let stake = null;
if (typeof props.stake !== 'undefined' && props.stake.toNumber() !== 0) {
stake = (
);
}
let avatar = ;
if (typeof props.profile.avatar_uri !== 'undefined' && props.profile.avatar_uri.toString() !== '') {
avatar = ;
}
let earned = null;
if (typeof props.earned !== 'undefined' &&
props.earned.toNumber() > 0 &&
!fluid) {
earned = (
);
}
return (
{avatar}
{props.title}
{stake}
{earned}
);
}
type CountdownProps = {
end: Date;
}
export function Countdown (props: CountdownProps) {
let interval = -1;
const [days, setDays] = useState(undefined);
const [hours, setHours] = useState(undefined);
const [minutes, setMinutes] = useState(undefined);
const [seconds, setSeconds] = useState(undefined);
const update = () => {
const then = moment(props.end);
const now = moment();
const d = moment.duration(then.diff(now));
setDays(d.days());
setHours(d.hours());
setMinutes(d.minutes());
setSeconds(d.seconds());
};
interval = window.setInterval(update, 1000);
useEffect(() => {
update();
return () => {
clearInterval(interval);
};
}, []);
if (!seconds) {
return null;
}
return (
{days}
Days
{hours}
hours
{minutes}
minutes
{seconds}
seconds
);
}