use real FilterLists data from API

This commit is contained in:
Collin M. Barrett 2019-08-04 17:48:54 -05:00
parent 756fe20dc0
commit 44061745e9
5 changed files with 37 additions and 23 deletions

View file

@ -1,12 +1,10 @@
import React from 'react';
import { AllListsTable } from './AllListsTable';
import { AllListsTable } from './modules';
import './App.css';
const App: React.FC = () => {
return (
<div className="App">
<AllListsTable></AllListsTable>
</div>
<AllListsTable></AllListsTable>
);
}

View file

@ -1,28 +1,16 @@
import { Table } from 'antd';
import * as React from "react";
import { List } from './List';
const columns = [
{
title: 'Name',
dataIndex: 'name',
sorter: true,
render: (name: { first: any; last: any; }) => `${name.first} ${name.last}`,
width: '20%',
},
{
title: 'Gender',
dataIndex: 'gender',
filters: [{ text: 'Male', value: 'male' }, { text: 'Female', value: 'female' }],
width: '20%',
},
{
title: 'Email',
dataIndex: 'email',
},
}
];
interface State {
data: [];
data: List[];
loading: boolean;
}
@ -39,13 +27,12 @@ export class AllListsTable extends React.Component<{}, State> {
this.fetch();
}
fetch = () => {
fetch() {
this.setState({ loading: true });
fetch("https://randomuser.me/api")
fetch("/api/v1/lists")
.then(response => response.json())
.then(json => {
this.setState({ data: json.results });
this.setState({ loading: false })
this.setState({ data: json, loading: false });
})
};
@ -53,6 +40,7 @@ export class AllListsTable extends React.Component<{}, State> {
return (
<Table
columns={columns}
rowKey={record => record.id.toString()}
dataSource={this.state.data}
loading={this.state.loading}
/>

View file

@ -0,0 +1,22 @@
export interface List {
id: number;
chatUrl: string;
description: string;
descriptionSourceUrl: string;
donateUrl: string;
emailAddress: string;
forumUrl: string;
homeUrl: string;
issuesUrl: string;
languageIds: number[];
licenseId: number;
maintainerIds: number[];
name: string;
policyUrl: string;
publishedDate: string;
submissionUrl: string;
syntaxId: number;
tagIds: number[];
viewUrl: string;
viewUrlMirrors: string[];
};

View file

@ -0,0 +1,3 @@
import { AllListsTable } from './AllListsTable'
export { AllListsTable }

View file

@ -0,0 +1,3 @@
import { AllListsTable } from './allListsTable'
export { AllListsTable }