extract PublishedDate, misc. linting

This commit is contained in:
Collin M. Barrett 2019-09-01 16:57:08 -05:00
parent 1727c168c6
commit 3cb2c45703
9 changed files with 143 additions and 100 deletions

View file

@ -1,28 +1,33 @@
import { Tag } from 'antd';
import * as React from 'react';
import { License } from '../interfaces/License';
interface Props {
license: License;
name: string;
descriptionUrl: string;
showLabel?: boolean
};
export const LicenseTag = (props: Props) =>
props.license && props.license.name
? <div>
props.name
? <>
{props.showLabel && <h3>License:</h3>}
<Tag>
<TagContents {...props} />
<TagContents name={props.name} descriptionUrl={props.descriptionUrl} />
</Tag>
</div>
</>
: null;
const TagContents = (props: Props) =>
props.license.descriptionUrl
? <a href={props.license.descriptionUrl} target="_blank" rel="noopener noreferrer">
{props.license.name}
interface TagContentsProps {
name: string;
descriptionUrl: string;
};
const TagContents = (props: TagContentsProps) =>
props.descriptionUrl
? <a href={props.descriptionUrl}
target="_blank" rel="noopener noreferrer">
{props.name}
</a>
: <>
{props.license.name}
{props.name}
</>;

View file

@ -11,13 +11,15 @@ interface Props {
};
export const LinkButton = (props: Props) =>
<Button
href={props.url}
title={props.title}
type={props.type || "default"}
block
style={{ borderLeftColor: "rgb(217, 217, 217)" }} //HACK: override buggy style in antd
icon={props.icon}
target="_blank" rel="noopener noreferrer" >
{props.text}
</Button >;
props.url && props.text
? <Button
href={props.url}
title={props.title}
type={props.type || "default"}
block
style={{ borderLeftColor: "rgb(217, 217, 217)" }} //HACK: override buggy style in antd
icon={props.icon}
target="_blank" rel="noopener noreferrer" >
{props.text}
</Button >
: null;

View file

@ -3,18 +3,16 @@ import React from 'react';
import { RouteComponentProps } from 'react-router-dom';
import slugify from 'slugify';
import { List } from '../interfaces/List';
interface Props {
list: List;
listName: string;
};
export const ListInfoButton = (props: RouteComponentProps & Props) => {
const listPath = `/lists/${slugify(props.list.name)}`;
const listPath = `/lists/${slugify(props.listName)}`;
return (
<Button
type="primary"
title={`View more information about ${props.list.name}.`}
title={`View more information about ${props.listName}.`}
onClick={() => props.location.pathname === listPath
? props.history.push("/")
: props.history.push(listPath)} >

View file

@ -12,6 +12,7 @@ import { Description } from './Description';
import { LanguageCloud } from './languageCloud';
import { LicenseTag } from './LicenseTag';
import { LinkButton } from './LinkButton';
import { PublishedDate } from './PublishedDate';
import { SoftwareCloud } from './softwareCloud';
import { SubscribeButtons } from './SubscribeButtons';
import { TagCloud } from './tagCloud';
@ -19,7 +20,7 @@ import { TagCloud } from './tagCloud';
interface Props {
list: List;
languages: Language[];
license?: License;
license: License;
software: Software[];
tags: Tag[];
};
@ -40,73 +41,76 @@ export const ListInfoDrawer = (props: RouteComponentProps & Props) => {
title={props.list.name}
destroyOnClose={true}
onClose={() => props.history.push("/")}>
<Description {...props.list} />
{props.list.languageIds
? <LanguageCloud languages={props.languages} showLabel={true} />
: null}
{props.list.tagIds
? <TagCloud tags={props.tags} showLabel={true} />
: null}
{props.license
? <LicenseTag license={props.license as License} showLabel={true} />
: null}
{props.list.syntaxId
? <SoftwareCloud software={props.software} showLabel={true} />
: null}
{props.list.publishedDate
? <div>
<h3>First Published Date:</h3>
{new Date(props.list.publishedDate).toDateString()}
</div>
: null}
<Description
description={props.list.description}
descriptionSourceUrl={props.list.descriptionSourceUrl} />
<LanguageCloud
languages={props.languages}
showLabel={true} />
<TagCloud
tags={props.tags}
showLabel={true} />
<LicenseTag
name={props.license.name}
descriptionUrl={props.license.descriptionUrl}
showLabel={true} />
<SoftwareCloud
software={props.software}
showLabel={true} />
<PublishedDate
publishedDate={props.list.publishedDate}
showLabel={true} />
<Divider />
<ButtonGroup style={{ display: "inherit" }}>
{props.list.viewUrl && <SubscribeButtons {...props.list} />}
{props.list.viewUrl &&
<LinkButton url={props.list.viewUrl}
text="View"
title={`View ${props.list.name} in its raw format`}
icon="search" />}
{props.list.homeUrl &&
<LinkButton url={props.list.homeUrl}
text="Home"
title={`View ${props.list.name}'s homepage.`}
icon="home" />}
{props.list.policyUrl &&
<LinkButton url={props.list.policyUrl}
text="Policy"
title={`View the types of rules that ${props.list.name} includes.`}
icon="file-exclamation" />}
{props.list.emailAddress &&
<LinkButton url={`mailto:${props.list.emailAddress}`}
text="Email"
title={`Email ${props.list.name}.`}
icon="mail" />}
{props.list.issuesUrl &&
<LinkButton url={props.list.issuesUrl}
text="GitHub Issues"
title={`View the GitHub Issues for ${props.list.name}.`}
icon="github" />}
{props.list.submissionUrl &&
<LinkButton url={props.list.submissionUrl}
text="Submit a Rule"
title={`Submit a new rule to be included in ${props.list.name}.`}
icon="form" />}
{props.list.forumUrl &&
<LinkButton url={props.list.forumUrl}
text="Forum"
title={`View the forum for ${props.list.name}.`}
icon="team" />}
{props.list.chatUrl &&
<LinkButton url={props.list.chatUrl}
text="Chat"
title={`Enter the chat room for ${props.list.name}.`}
icon="message" />}
{props.list.donateUrl &&
<LinkButton url={props.list.donateUrl}
text="Donate"
title={`Donate to the maintainer of ${props.list.name}.`}
icon="dollar" />}
<SubscribeButtons
name={props.list.name}
viewUrl={props.list.viewUrl}
viewUrlMirrors={props.list.viewUrlMirrors} />
<LinkButton
url={props.list.viewUrl}
text="View"
title={`View ${props.list.name} in its raw format`}
icon="search" />
<LinkButton
url={props.list.homeUrl}
text="Home"
title={`View ${props.list.name}'s homepage.`}
icon="home" />
<LinkButton
url={props.list.policyUrl}
text="Policy"
title={`View the types of rules that ${props.list.name} includes.`}
icon="file-exclamation" />
<LinkButton
url={`mailto:${props.list.emailAddress}`}
text="Email"
title={`Email ${props.list.name}.`}
icon="mail" />
<LinkButton
url={props.list.issuesUrl}
text="GitHub Issues"
title={`View the GitHub Issues for ${props.list.name}.`}
icon="github" />
<LinkButton
url={props.list.submissionUrl}
text="Submit a Rule"
title={`Submit a new rule to be included in ${props.list.name}.`}
icon="form" />
<LinkButton
url={props.list.forumUrl}
text="Forum"
title={`View the forum for ${props.list.name}.`}
icon="team" />
<LinkButton
url={props.list.chatUrl}
text="Chat"
title={`Enter the chat room for ${props.list.name}.`}
icon="message" />
<LinkButton
url={props.list.donateUrl}
text="Donate"
title={`Donate to the maintainer of ${props.list.name}.`}
icon="dollar" />
</ButtonGroup>
</Drawer>
);

View file

@ -0,0 +1,14 @@
import React from 'react';
interface Props {
publishedDate: string;
showLabel?: boolean;
};
export const PublishedDate = (props: Props) =>
props.publishedDate
? <>
{props.showLabel && <h3>First Published Date:</h3>}
{new Date(props.publishedDate).toDateString()}
</>
: null;

View file

@ -11,8 +11,13 @@ interface Props {
export const SubscribeButtons = (props: Props) =>
props.viewUrl
? <>
<SubscribeButton name={props.name} viewUrl={props.viewUrl} text="Subscribe" />
<MirrorButtons name={props.name} viewUrlMirrors={props.viewUrlMirrors} />
<SubscribeButton
name={props.name}
viewUrl={props.viewUrl}
text="Subscribe" />
<MirrorButtons
name={props.name}
viewUrlMirrors={props.viewUrlMirrors} />
</>
: null;
@ -25,7 +30,11 @@ const MirrorButtons = (props: MirrorButtonsProps) =>
<>
{props.viewUrlMirrors && props.viewUrlMirrors.length
? props.viewUrlMirrors.map((viewUrlMirror: string, i: number) =>
<SubscribeButton key={i} name={props.name} viewUrl={viewUrlMirror} text={`Subscribe (Mirror ${i + 1})`} />)
<SubscribeButton
key={i}
name={props.name}
viewUrl={viewUrlMirror}
text={`Subscribe (Mirror ${i + 1})`} />)
: null}
</>;

View file

@ -23,7 +23,7 @@ export const ListDrawer = (props: Props) => {
? <ListInfoDrawer
list={list as List}
languages={list.languageIds && props.languages.filter((l: Language) => list.languageIds.includes(l.id))}
license={list.licenseId ? props.licenses.find((l: License) => list.licenseId === l.id) : undefined}
license={(list.licenseId ? props.licenses.find((l: License) => list.licenseId === l.id) : props.licenses.find((l: License) => l.id === 5)) as License}
software={list.syntaxId ? props.software.filter((s: Software) => s.syntaxIds.includes(list.syntaxId)) : []}
tags={list.tagIds && props.tags.filter((t: Tag) => list.tagIds.includes(t.id))}
{...rp} />

View file

@ -40,7 +40,7 @@ export const ListsTable = (props: RouteComponentProps & Props) => {
dataIndex={nameof<List>("id")}
className={styles.nogrow}
fixed="left"
render={(_text: string, record: List) => <ListInfoButton list={record} {...props} />} />
render={(_text: string, record: List) => <ListInfoButton listName={record.name} {...props} />} />
<Table.Column<List>
title="Name"
dataIndex={nameof<List>("name")}

View file

@ -13,8 +13,19 @@ export const ListsTableHoc = (props: RouteComponentProps) => {
const tags = useTags();
return (
<>
<ListsTable lists={lists} languages={languages} licenses={licenses} software={software} tags={tags} {...props} />
<ListDrawer lists={lists} languages={languages} licenses={licenses} software={software} tags={tags} />
<ListsTable
lists={lists}
languages={languages}
licenses={licenses}
software={software}
tags={tags}
{...props} />
<ListDrawer
lists={lists}
languages={languages}
licenses={licenses}
software={software}
tags={tags} />
</>
);
};