From 077632f184f5832ff465dbf7ed7b3564ccb1740c Mon Sep 17 00:00:00 2001 From: Collin Barrett Date: Tue, 11 Sep 2018 17:48:08 -0500 Subject: [PATCH] components refactor wip ref #467 --- .../ClientApp/components/Home.tsx | 6 +- .../detailsExpander/DetailsExpander.tsx | 22 +++--- .../MaintainerAdditionalLists.tsx | 21 ++++++ .../MaintainerInfoCard.tsx | 69 ++++--------------- .../MaintainerLinkButtonGroup.tsx | 18 +++++ .../MaintainersInfoCard.tsx | 3 +- .../components/linkButtons/EmailButton.tsx | 17 +++++ .../components/linkButtons/HomeButton.tsx | 17 +++++ .../components/linkButtons/TwitterButton.tsx | 17 +++++ src/FilterLists.Web/ClientApp/css/site.css | 25 ++++++- .../IMaintainerAdditionalListsProps.ts | 4 ++ .../IMaintainerLinkButtonGroupProps.ts | 6 ++ .../linkButtons/IEmailButtonProps.tsx | 4 ++ .../linkButtons/ITwitterButtonProps.tsx | 4 ++ 14 files changed, 163 insertions(+), 70 deletions(-) create mode 100644 src/FilterLists.Web/ClientApp/components/detailsExpander/maintainersInfoCard/MaintainerAdditionalLists.tsx create mode 100644 src/FilterLists.Web/ClientApp/components/detailsExpander/maintainersInfoCard/MaintainerLinkButtonGroup.tsx create mode 100644 src/FilterLists.Web/ClientApp/components/linkButtons/EmailButton.tsx create mode 100644 src/FilterLists.Web/ClientApp/components/linkButtons/HomeButton.tsx create mode 100644 src/FilterLists.Web/ClientApp/components/linkButtons/TwitterButton.tsx create mode 100644 src/FilterLists.Web/ClientApp/interfaces/detailsExpander/maintainersInfoCard/IMaintainerAdditionalListsProps.ts create mode 100644 src/FilterLists.Web/ClientApp/interfaces/detailsExpander/maintainersInfoCard/IMaintainerLinkButtonGroupProps.ts create mode 100644 src/FilterLists.Web/ClientApp/interfaces/linkButtons/IEmailButtonProps.tsx create mode 100644 src/FilterLists.Web/ClientApp/interfaces/linkButtons/ITwitterButtonProps.tsx diff --git a/src/FilterLists.Web/ClientApp/components/Home.tsx b/src/FilterLists.Web/ClientApp/components/Home.tsx index 34f1045ea9..557ce2626e 100644 --- a/src/FilterLists.Web/ClientApp/components/Home.tsx +++ b/src/FilterLists.Web/ClientApp/components/Home.tsx @@ -3,8 +3,8 @@ import { RouteComponentProps } from "react-router"; import "isomorphic-fetch"; import ReactTable from "react-table" import "react-table/react-table.css" -import ListDetailsExpander from "./listDetailsExpander/DetailsExpander"; import * as moment from "moment"; +import DetailsExpander from "./detailsExpander/DetailsExpander"; interface IHomeState { lists: IListDto[]; @@ -166,7 +166,7 @@ export class Home extends React.Component, IHomeState> { Cell: (cell: any) =>
{cell.value.map( (e: any) => {e.name})}
, width: 200, headerClassName: "d-none d-md-block", @@ -247,7 +247,7 @@ export class Home extends React.Component, IHomeState> { ]} SubComponent={(row: any) => { return ( - + ); }} className="-striped -highlight"/>; diff --git a/src/FilterLists.Web/ClientApp/components/detailsExpander/DetailsExpander.tsx b/src/FilterLists.Web/ClientApp/components/detailsExpander/DetailsExpander.tsx index bb0d0bcee5..1fd7171c7c 100644 --- a/src/FilterLists.Web/ClientApp/components/detailsExpander/DetailsExpander.tsx +++ b/src/FilterLists.Web/ClientApp/components/detailsExpander/DetailsExpander.tsx @@ -1,46 +1,48 @@ import * as React from "react"; import "isomorphic-fetch"; import InfoCard from "./InfoCard"; -import MaintainerInfoCard from "./MaintainersInfoCard"; import LinkButtonGroup from "./LinkButtonGroup"; +import MaintainersInfoCard from "./maintainersInfoCard/MaintainersInfoCard"; export default class DetailsExpander extends React.Component { constructor(props: IDetailsExpanderProps) { super(props); this.state = { - responseLoaded: false, - listId: props.listId + responseReceived: false }; + } + + componentDidMount() { this.fetchData(); } fetchData() { - fetch(`https://filterlists.com/api/v1/lists/${this.state.listId}`) + fetch(`https://filterlists.com/api/v1/lists/${this.props.listId}`) .then(response => response.json() as Promise) .then(data => { this.setState({ filterListDetails: data, - responseLoaded: true + responseReceived: true }); }); } render() { - return this.state.responseLoaded + return this.state.responseReceived ?
- - + +
- +
- :
Loading...
; + :
Loading
; } //https://stackoverflow.com/a/11868398/2343739 diff --git a/src/FilterLists.Web/ClientApp/components/detailsExpander/maintainersInfoCard/MaintainerAdditionalLists.tsx b/src/FilterLists.Web/ClientApp/components/detailsExpander/maintainersInfoCard/MaintainerAdditionalLists.tsx new file mode 100644 index 0000000000..677eadf5e6 --- /dev/null +++ b/src/FilterLists.Web/ClientApp/components/detailsExpander/maintainersInfoCard/MaintainerAdditionalLists.tsx @@ -0,0 +1,21 @@ +import * as React from "react"; + +export default class MaintainerAdditionalLists extends React.Component { + constructor(props: IMaintainerAdditionalListsProps) { + super(props); + } + + render() { + return this.props.additionalLists.length > 0 + ?
+
+

More by {this.props.name}:

+
    + {this.props.additionalLists.map((list: IMaintainerAdditionalListsDto) => +
  • {list.name}
  • )} +
+
+
+ : null; + } +} \ No newline at end of file diff --git a/src/FilterLists.Web/ClientApp/components/detailsExpander/maintainersInfoCard/MaintainerInfoCard.tsx b/src/FilterLists.Web/ClientApp/components/detailsExpander/maintainersInfoCard/MaintainerInfoCard.tsx index b963cea20c..6294e680bf 100644 --- a/src/FilterLists.Web/ClientApp/components/detailsExpander/maintainersInfoCard/MaintainerInfoCard.tsx +++ b/src/FilterLists.Web/ClientApp/components/detailsExpander/maintainersInfoCard/MaintainerInfoCard.tsx @@ -1,4 +1,6 @@ import * as React from "react"; +import MaintainerAdditionalLists from "./MaintainerAdditionalLists"; +import MaintainerLinkButtonGroup from "./MaintainerLinkButtonGroup"; export default class MaintainerInfoCard extends React.Component { constructor(props: IListMaintainerDto) { @@ -6,59 +8,18 @@ export default class MaintainerInfoCard extends React.Component -
-

Maintained by {this.props.name}

-
-
- - -
-
-
- ; + return this.props.name + ?
+
+

Maintained by {this.props.name}

+
+
+ + +
+
+
+
+ : null; } -} - -function MaintainerAdditionalLists(props: any) { - return
- {props.maintainer.additionalLists.length > 0 - ?
-

More by {props.maintainer.name}:

-
    - {props.maintainer.additionalLists.map( - (list: any) => )} -
-
- : null} -
; -} - -function MaintainerAdditionalList(props: any) { - return
  • {props.list.name}
  • ; -} - -function MaintainerUrls(props: any) { - return
    - {props.maintainer.homeUrl - ? - Home - - : null} - {props.maintainer.emailAddress - ? - Email - - : null} - {props.maintainer.twitterHandle - ? - Twitter - - : null} -
    ; } \ No newline at end of file diff --git a/src/FilterLists.Web/ClientApp/components/detailsExpander/maintainersInfoCard/MaintainerLinkButtonGroup.tsx b/src/FilterLists.Web/ClientApp/components/detailsExpander/maintainersInfoCard/MaintainerLinkButtonGroup.tsx new file mode 100644 index 0000000000..e8b553344e --- /dev/null +++ b/src/FilterLists.Web/ClientApp/components/detailsExpander/maintainersInfoCard/MaintainerLinkButtonGroup.tsx @@ -0,0 +1,18 @@ +import * as React from "react"; +import HomeButton from "../../linkButtons/HomeButton"; +import EmailButton from "../../linkButtons/EmailButton"; +import TwitterButton from "../../linkButtons/TwitterButton"; + +export default class MaintainerLinkButtonGroup extends React.Component { + constructor(props: IMaintainerLinkButtonGroupProps) { + super(props); + } + + render() { + return
    + + + +
    ; + } +} \ No newline at end of file diff --git a/src/FilterLists.Web/ClientApp/components/detailsExpander/maintainersInfoCard/MaintainersInfoCard.tsx b/src/FilterLists.Web/ClientApp/components/detailsExpander/maintainersInfoCard/MaintainersInfoCard.tsx index f7b57c043a..74419153fe 100644 --- a/src/FilterLists.Web/ClientApp/components/detailsExpander/maintainersInfoCard/MaintainersInfoCard.tsx +++ b/src/FilterLists.Web/ClientApp/components/detailsExpander/maintainersInfoCard/MaintainersInfoCard.tsx @@ -9,8 +9,7 @@ export default class MaintainersInfoCard extends React.Component 0 ?
    - {this.props.map((maintainer: IListMaintainerDto) => - )} + {this.props.map((maintainer: IListMaintainerDto) => )}
    : null; } diff --git a/src/FilterLists.Web/ClientApp/components/linkButtons/EmailButton.tsx b/src/FilterLists.Web/ClientApp/components/linkButtons/EmailButton.tsx new file mode 100644 index 0000000000..38abfe8de2 --- /dev/null +++ b/src/FilterLists.Web/ClientApp/components/linkButtons/EmailButton.tsx @@ -0,0 +1,17 @@ +import * as React from "react"; + +export default class EmailButton extends React.Component { + constructor(props: IEmailButtonProps) { + super(props); + } + + render() { + return this.props.emailAddress + ? + Email + + : null; + } +} \ No newline at end of file diff --git a/src/FilterLists.Web/ClientApp/components/linkButtons/HomeButton.tsx b/src/FilterLists.Web/ClientApp/components/linkButtons/HomeButton.tsx new file mode 100644 index 0000000000..f69e5387d4 --- /dev/null +++ b/src/FilterLists.Web/ClientApp/components/linkButtons/HomeButton.tsx @@ -0,0 +1,17 @@ +import * as React from "react"; + +export default class HomeButton extends React.Component { + constructor(props: IUrlButtonProps) { + super(props); + } + + render() { + return this.props.url + ? + Home + + : null; + } +} \ No newline at end of file diff --git a/src/FilterLists.Web/ClientApp/components/linkButtons/TwitterButton.tsx b/src/FilterLists.Web/ClientApp/components/linkButtons/TwitterButton.tsx new file mode 100644 index 0000000000..efb2bfc61e --- /dev/null +++ b/src/FilterLists.Web/ClientApp/components/linkButtons/TwitterButton.tsx @@ -0,0 +1,17 @@ +import * as React from "react"; + +export default class TwitterButton extends React.Component { + constructor(props: ITwitterButtonProps) { + super(props); + } + + render() { + return this.props.twitterHandle + ? + Twitter + + : null; + } +} \ No newline at end of file diff --git a/src/FilterLists.Web/ClientApp/css/site.css b/src/FilterLists.Web/ClientApp/css/site.css index 7c74e73645..3ba3936014 100644 --- a/src/FilterLists.Web/ClientApp/css/site.css +++ b/src/FilterLists.Web/ClientApp/css/site.css @@ -19,4 +19,27 @@ div.rt-tbody, div.rt-thead.-filters, div.rt-thead.-header { min-width: 320px !im max-width: 90px; } -.fl-description { margin: 0 0 .5rem; } \ No newline at end of file +.fl-description { margin: 0 0 .5rem; } + + +/** https://codepen.io/thetallweeks/pen/yybGra **/ + +.loading:after { + -webkit-animation: ellipsis steps(4, end) 900ms infinite; + animation: ellipsis steps(4, end) 900ms infinite; + content: "\2026"; + display: inline-block; + overflow: hidden; + vertical-align: bottom; + width: 0; +} + +@keyframes ellipsis { + to { width: 1.25em; } +} + +@-webkit-keyframes ellipsis { + to { width: 1.25em; } +} + +/** **/ \ No newline at end of file diff --git a/src/FilterLists.Web/ClientApp/interfaces/detailsExpander/maintainersInfoCard/IMaintainerAdditionalListsProps.ts b/src/FilterLists.Web/ClientApp/interfaces/detailsExpander/maintainersInfoCard/IMaintainerAdditionalListsProps.ts new file mode 100644 index 0000000000..56c48ee2ed --- /dev/null +++ b/src/FilterLists.Web/ClientApp/interfaces/detailsExpander/maintainersInfoCard/IMaintainerAdditionalListsProps.ts @@ -0,0 +1,4 @@ +interface IMaintainerAdditionalListsProps { + name: string; + additionalLists: IMaintainerAdditionalListsDto[]; +} \ No newline at end of file diff --git a/src/FilterLists.Web/ClientApp/interfaces/detailsExpander/maintainersInfoCard/IMaintainerLinkButtonGroupProps.ts b/src/FilterLists.Web/ClientApp/interfaces/detailsExpander/maintainersInfoCard/IMaintainerLinkButtonGroupProps.ts new file mode 100644 index 0000000000..79ade3f300 --- /dev/null +++ b/src/FilterLists.Web/ClientApp/interfaces/detailsExpander/maintainersInfoCard/IMaintainerLinkButtonGroupProps.ts @@ -0,0 +1,6 @@ +interface IMaintainerLinkButtonGroupProps { + emailAddress: string; + homeUrl: string; + name: string; + twitterHandle: string; +} \ No newline at end of file diff --git a/src/FilterLists.Web/ClientApp/interfaces/linkButtons/IEmailButtonProps.tsx b/src/FilterLists.Web/ClientApp/interfaces/linkButtons/IEmailButtonProps.tsx new file mode 100644 index 0000000000..5df9593d46 --- /dev/null +++ b/src/FilterLists.Web/ClientApp/interfaces/linkButtons/IEmailButtonProps.tsx @@ -0,0 +1,4 @@ +interface IEmailButtonProps { + name: string; + emailAddress: string; +} \ No newline at end of file diff --git a/src/FilterLists.Web/ClientApp/interfaces/linkButtons/ITwitterButtonProps.tsx b/src/FilterLists.Web/ClientApp/interfaces/linkButtons/ITwitterButtonProps.tsx new file mode 100644 index 0000000000..97d2c784f4 --- /dev/null +++ b/src/FilterLists.Web/ClientApp/interfaces/linkButtons/ITwitterButtonProps.tsx @@ -0,0 +1,4 @@ +interface ITwitterButtonProps { + name: string; + twitterHandle: string; +} \ No newline at end of file