2019-08-12 12:06:10 +07:00
|
|
|
import React, { FC, Fragment } from 'react';
|
2019-02-03 17:23:33 +07:00
|
|
|
import Add from '@material-ui/icons/Add';
|
2019-03-28 05:39:06 +07:00
|
|
|
|
2019-08-12 12:06:10 +07:00
|
|
|
import { DetailContext } from '../../pages/version/Version';
|
|
|
|
import { AvatarTooltip } from '../AvatarTooltip';
|
2019-03-28 05:39:06 +07:00
|
|
|
import { Details, Heading, Content, Fab } from './styles';
|
2019-08-12 12:06:10 +07:00
|
|
|
|
|
|
|
export type DevelopersType = 'contributors' | 'maintainers';
|
2019-02-03 17:23:33 +07:00
|
|
|
|
|
|
|
interface Props {
|
2019-08-12 12:06:10 +07:00
|
|
|
type: DevelopersType;
|
|
|
|
visibleMax?: number;
|
2019-06-25 05:54:32 +07:00
|
|
|
}
|
2019-02-03 17:23:33 +07:00
|
|
|
|
2019-08-12 12:06:10 +07:00
|
|
|
export const VISIBLE_MAX = 6;
|
|
|
|
|
|
|
|
const Developers: FC<Props> = ({ type, visibleMax }) => {
|
|
|
|
const [visibleDevs, setVisibleDevs] = React.useState<number>(visibleMax || VISIBLE_MAX);
|
|
|
|
const { packageMeta } = React.useContext(DetailContext);
|
|
|
|
|
|
|
|
const handleLoadMore = () => {
|
|
|
|
setVisibleDevs(visibleDevs + VISIBLE_MAX);
|
2019-02-03 17:23:33 +07:00
|
|
|
};
|
|
|
|
|
2019-08-12 12:06:10 +07:00
|
|
|
const renderDeveloperDetails = ({ name, avatar, email }, packageMeta) => {
|
|
|
|
const { name: packageName, version } = packageMeta.latest;
|
2019-02-03 17:23:33 +07:00
|
|
|
|
2019-08-12 12:06:10 +07:00
|
|
|
return <AvatarTooltip avatar={avatar} email={email} name={name} packageName={packageName} version={version} />;
|
2019-04-09 03:29:20 +07:00
|
|
|
};
|
2019-03-28 05:39:06 +07:00
|
|
|
|
2019-08-12 12:06:10 +07:00
|
|
|
const renderDevelopers = (developers, packageMeta) => {
|
|
|
|
const listVisibleDevelopers = developers.slice(0, visibleDevs);
|
|
|
|
|
2019-02-03 17:23:33 +07:00
|
|
|
return (
|
2019-08-12 12:06:10 +07:00
|
|
|
<Fragment>
|
2019-03-28 05:39:06 +07:00
|
|
|
<Heading variant={'subheading'}>{type}</Heading>
|
|
|
|
<Content>
|
2019-08-12 12:06:10 +07:00
|
|
|
{listVisibleDevelopers.map(developer => (
|
|
|
|
<Details key={developer.email}>{renderDeveloperDetails(developer, packageMeta)}</Details>
|
2019-03-28 05:39:06 +07:00
|
|
|
))}
|
2019-04-09 03:29:20 +07:00
|
|
|
{visibleDevs < developers.length && (
|
2019-08-12 12:06:10 +07:00
|
|
|
<Fab onClick={handleLoadMore} size="small">
|
2019-04-09 03:29:20 +07:00
|
|
|
<Add />
|
|
|
|
</Fab>
|
|
|
|
)}
|
2019-03-28 05:39:06 +07:00
|
|
|
</Content>
|
2019-08-12 12:06:10 +07:00
|
|
|
</Fragment>
|
2019-02-03 17:23:33 +07:00
|
|
|
);
|
2019-04-09 03:29:20 +07:00
|
|
|
};
|
2019-02-03 17:23:33 +07:00
|
|
|
|
2019-08-12 12:06:10 +07:00
|
|
|
const developerList = packageMeta && packageMeta.latest[type];
|
|
|
|
if (!developerList || developerList.length === 0) {
|
|
|
|
return null;
|
2019-02-03 17:23:33 +07:00
|
|
|
}
|
|
|
|
|
2019-08-12 12:06:10 +07:00
|
|
|
return renderDevelopers(developerList, packageMeta);
|
|
|
|
};
|
2019-02-03 17:23:33 +07:00
|
|
|
|
|
|
|
export default Developers;
|