From 7c4e3dc553a30a676c553b2c9cea5227e7166513 Mon Sep 17 00:00:00 2001 From: Collin Barrett Date: Sun, 18 Feb 2018 15:01:31 -0600 Subject: [PATCH] cleanup modal logic should fix #248 --- .../ClientApp/components/ListDetailsModal.tsx | 133 ++++++++++-------- 1 file changed, 74 insertions(+), 59 deletions(-) diff --git a/src/FilterLists.Web/ClientApp/components/ListDetailsModal.tsx b/src/FilterLists.Web/ClientApp/components/ListDetailsModal.tsx index 5d14119fc..52cfcbac8 100644 --- a/src/FilterLists.Web/ClientApp/components/ListDetailsModal.tsx +++ b/src/FilterLists.Web/ClientApp/components/ListDetailsModal.tsx @@ -3,49 +3,47 @@ import "isomorphic-fetch"; import * as ReactModal from "react-modal"; export default class ListDetailsModal extends React.Component { - private listId: any; constructor(props: any) { super(props); - this.state = { showModal: false, loading: true }; - this.listId = props.listId; - this.handleOpenModal = this.handleOpenModal.bind(this); - this.handleCloseModal = this.handleCloseModal.bind(this); + this.state = { + isModalOpen: false, + listId: props.listId + }; + this.openModal = this.openModal.bind(this); + this.closeModal = this.closeModal.bind(this); } componentWillReceiveProps(nextProps: any) { - this.setState({ showModal: false }); - this.setState({ filterListDetails: null }); - this.listId = nextProps.listId; + this.setState({ + isModalOpen: false, + listId: nextProps.listId + }); } - handleOpenModal() { - fetch(`https://api.filterlists.com/v1/lists/${this.listId}`) + openModal() { + fetch(`https://api.filterlists.com/v1/lists/${this.state.listId}`) .then(response => response.json() as Promise) - .then(data => { this.setState({ filterListDetails: data, loading: false }); }); - this.setState({ showModal: true }); + .then(data => { + this.setState({ + filterListDetails: data, + isModalOpen: true + }); + }); } - handleCloseModal() { - this.setState({ showModal: false }); + closeModal() { + this.setState({ isModalOpen: false }); } render() { - const contents = this.state.loading - ? null - : - - - ; - return ( -
- - {contents} -
- ); + return
+ + + + + +
; } } @@ -57,13 +55,13 @@ function FilterListDetails(props: any) { - - - - - - - + + + + + + + ; } @@ -72,8 +70,11 @@ function Name(props: any) { } function Description(props: any) { - return props.description ? (props.url ?
{props.description}
:

{ - props.description}

) : null; + return props.description + ? (props.url + ?
{props.description}
+ :

{props.description}

) + : null; } function PublishedDate(props: any) { @@ -99,45 +100,59 @@ function ViewUrl(props: any) { } function HomeUrl(props: any) { - return props.url ? - Home - : null; + return props.url + ? + Home + + : null; } function PolicyUrl(props: any) { - return props.url ? - Policy - : null; + return props.url + ? + Policy + + : null; } function DonateUrl(props: any) { - return props.url ? - Donate - : null; + return props.url + ? + Donate + + : null; } function IssuesUrl(props: any) { - return props.url ? - GitHub Issues - : null; + return props.url + ? + GitHub Issues + + : null; } function ForumUrl(props: any) { - return props.url ? - Forum - : null; + return props.url + ? + Forum + + : null; } function SubmissionUrl(props: any) { - return props.url ? - Submit New Rule - : null; + return props.url + ? + Submit New Rule + + : null; } function EmailAddress(props: any) { - return props.email ? - Email - : null; + return props.email + ? + Email + + : null; } interface IFilterListDetailsDto {