From 39616e1fa63eb63dee7c6179e927f5092826fac4 Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Thu, 18 Jan 2018 17:10:58 -0600 Subject: [PATCH] replace sample data with FL API data --- .../ClientApp/components/FetchData.tsx | 65 ------------------- .../ClientApp/components/Home.tsx | 58 +++++++++++++++++ src/FilterLists.Web/ClientApp/routes.tsx | 4 +- 3 files changed, 60 insertions(+), 67 deletions(-) delete mode 100644 src/FilterLists.Web/ClientApp/components/FetchData.tsx create mode 100644 src/FilterLists.Web/ClientApp/components/Home.tsx diff --git a/src/FilterLists.Web/ClientApp/components/FetchData.tsx b/src/FilterLists.Web/ClientApp/components/FetchData.tsx deleted file mode 100644 index b0098bba8..000000000 --- a/src/FilterLists.Web/ClientApp/components/FetchData.tsx +++ /dev/null @@ -1,65 +0,0 @@ -import * as React from "react"; -import { RouteComponentProps } from "react-router"; -import "isomorphic-fetch"; - -interface FetchDataExampleState { - forecasts: WeatherForecast[]; - loading: boolean; -} - -export class FetchData extends React.Component, FetchDataExampleState> { - constructor() { - super(); - this.state = { forecasts: [], loading: true }; - - fetch("api/SampleData/WeatherForecasts") - .then(response => response.json() as Promise) - .then(data => { - this.setState({ forecasts: data, loading: false }); - }); - } - - render() { - const contents = this.state.loading - ?

- Loading... -

- : FetchData.renderForecastsTable(this.state.forecasts); - - return
-

Weather forecast

-

This component demonstrates fetching data from the server.

- { contents } -
; - } - - private static renderForecastsTable(forecasts: WeatherForecast[]) { - return - - - - - - - - - - {forecasts.map(forecast => - - - - - - - )} - -
DateTemp. (C)Temp. (F)Summary
{ forecast.dateFormatted }{ forecast.temperatureC }{ forecast.temperatureF }{ forecast.summary }
; - } -} - -interface WeatherForecast { - dateFormatted: string; - temperatureC: number; - temperatureF: number; - summary: string; -} \ No newline at end of file diff --git a/src/FilterLists.Web/ClientApp/components/Home.tsx b/src/FilterLists.Web/ClientApp/components/Home.tsx new file mode 100644 index 000000000..9cf778e40 --- /dev/null +++ b/src/FilterLists.Web/ClientApp/components/Home.tsx @@ -0,0 +1,58 @@ +import * as React from "react"; +import { RouteComponentProps } from "react-router"; +import "isomorphic-fetch"; + +interface IFilterListsState { + filterLists: IFilterList[]; + loading: boolean; +} + +export class Home extends React.Component, IFilterListsState> { + constructor() { + super(); + this.state = { filterLists: [], loading: true }; + + fetch("https://api.filterlists.com/v1/lists") + .then(response => response.json() as Promise) + .then(data => { + this.setState({ filterLists: data, loading: false }); + }); + } + + render() { + const contents = this.state.loading + ?

+ Loading... +

+ : Home.renderFilterListsTable(this.state.filterLists); + + return
+ {contents} +
; + } + + private static renderFilterListsTable(filterLists: IFilterList[]) { + return + + + + + + + + {filterLists.map(filterList => + + + + + )} + +
NameDescription
{filterList.name}{filterList.description}
; + } +} + +interface IFilterList { + id: number; + name: string; + description: string; +} \ No newline at end of file diff --git a/src/FilterLists.Web/ClientApp/routes.tsx b/src/FilterLists.Web/ClientApp/routes.tsx index f4ec3ec8b..5a14cda26 100644 --- a/src/FilterLists.Web/ClientApp/routes.tsx +++ b/src/FilterLists.Web/ClientApp/routes.tsx @@ -1,8 +1,8 @@ import * as React from "react"; import { Route } from "react-router-dom"; import { Layout } from "./components/Layout"; -import { FetchData } from "./components/FetchData"; +import { Home } from "./components/Home"; export const routes = - + ; \ No newline at end of file