import React, { useEffect, useState } from 'react'
import moment from 'moment'
import { Header, 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 { Actor } from '@joystream/types/lib/roles';
import { IProfile, MemberId } from '@joystream/types/lib/members';
import { Text, GenericAccountId } from '@polkadot/types';
import { LeadRoleState } from '@joystream/types/lib/content-working-group';
type ActorProps = {
actor: Actor
}
type BalanceProps = {
balance?: Balance
}
export function BalanceView(props: BalanceProps) {
return (
Balance: {formatBalance(props.balance)}
)
}
type MemoProps = ActorProps & {
memo?: Text
}
export function MemoView(props: MemoProps) {
if (typeof props.memo === "undefined") {
return null
}
return (
Memo: {props.memo.toString()}
{' view full memo'}
)
}
type ProfileProps = {
profile: IProfile
}
export function HandleView(props: ProfileProps) {
if (typeof props.profile === "undefined") {
return null
}
return (
{props.profile.handle.toString()}
)
}
type MemberProps = ActorProps & BalanceProps & ProfileProps
export function MemberView(props: MemberProps) {
let avatar =
if (typeof props.profile.avatar_uri !== "undefined" && props.profile.avatar_uri.toString() != "") {
avatar =
}
return (
)
}
type ActorDetailsProps = MemoProps & BalanceProps
export function ActorDetailsView(props: ActorDetailsProps) {
return (
{props.actor.account.toString()}
)
}
export type GroupMember = {
memberId: MemberId
roleAccount: GenericAccountId
profile: IProfile
title: string
stake?: Balance
earned?: Balance
}
export type GroupLead = {
memberId: MemberId
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: number = -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
)
}