diff --git a/src/App.scss b/src/App.scss index 93f0af3a..70d8e384 100644 --- a/src/App.scss +++ b/src/App.scss @@ -2,3 +2,7 @@ iframe { display: none; } + +.selected { + background-color: red; +} diff --git a/src/App.tsx b/src/App.tsx index f6361547..ed0aecfb 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -3,36 +3,88 @@ import React from 'react'; import '@fortawesome/fontawesome-free/css/all.css'; import 'bulma/css/bulma.css'; import './App.scss'; +import { getPeopleFromServer } from './api'; +import { Person } from './types/Person'; +import { PeoplesTable } from './PeoplesTable'; +import { Loader } from './Loader'; -import peopleFromServer from './people.json'; +const MOCK_LOADING_TIME = 1000; -export class App extends React.Component { - state = {}; +type State = { + peopleFromServer: Person[]; + isError: boolean; + isLoading: boolean; +}; + +export class App extends React.Component<{}, State> { + state: State = { + peopleFromServer: [], + isError: false, + isLoading: false, + }; + + componentDidMount() { + this.setState({ + isLoading: true, + }); + + const people = getPeopleFromServer(); + + if (!people) { + setTimeout( + () => { + this.setState({ + isError: true, + isLoading: false, + }); + }, + MOCK_LOADING_TIME, + ); + + return; + } + + setTimeout( + () => { + this.setState({ + peopleFromServer: people, + isLoading: false, + }); + }, + MOCK_LOADING_TIME, + ); + } render() { + const { + peopleFromServer, + isLoading, + isError, + } = this.state; + + const isNoUsers = peopleFromServer.length === 0 + && !isLoading + && !isError; + return (
| name | -sex | -born | -
|---|---|---|
| {person.name} | -{person.sex} | -{person.born} | -
Sorry, an error occurred
+ )} + + {isLoading && ( +No users.
+ )} + + {peopleFromServer.length > 0 && ( +Loading...
+); diff --git a/src/PeoplesTable.tsx b/src/PeoplesTable.tsx new file mode 100644 index 00000000..5615fd7f --- /dev/null +++ b/src/PeoplesTable.tsx @@ -0,0 +1,61 @@ +import React from 'react'; +import { PersonFromTable } from './PersonFromTable'; +import { Person } from './types/Person'; + +type Props = { + peopleToDisplay: Person[]; +}; + +type State = { + selectedPersonSlug: string; +}; + +export class PeoplesTable extends React.Component| name | +sex | +born | +select | +
|---|