diff --git a/README.md b/README.md index 05bc534..f460654 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ This repository should be fairly simple to get running locally if you have exper - once you have navigated passed the first page, there should be a 'previous' button - once you have reached the last page, two things should happen - the 'next' button should disappear or disable - - the table should contain the remaining player records (there should be 96 records in the file, so 6 results are expected) + - the table should contain the remaining player records (there should be 95 records in the file, so 5 results are expected) - clicking on a row in the table should show that players data in a summary view somewhere on the page - finally: submit a **pull request** diff --git a/src/App.js b/src/App.js index 265a516..5b34c32 100644 --- a/src/App.js +++ b/src/App.js @@ -1,17 +1,85 @@ -import React from 'react'; +import React, { useState, useMemo } from 'react'; import players from './_players.json'; +import { PLAYER_TABLE_DISPLAY_LIMIT, playersTableColumns } from './players.constants.js' +import { paginatePlayerTableItems } from './players.utils.js' const App = () => { + const [displayIndex, setDisplayIndex] = useState(0); + const [playerSummary, setPlayerSummary] = useState(null); + + // Memoized to prevent re-running calculation when selecting a player summary to view + const playersToDisplay = useMemo( + () => paginatePlayerTableItems(players, displayIndex, PLAYER_TABLE_DISPLAY_LIMIT), + [displayIndex] + ); + + const isFirstPage = displayIndex === 0; + const isLastPage = displayIndex >= players.length - PLAYER_TABLE_DISPLAY_LIMIT; + return (
| hello | -world | + {playersTableColumns.map(header =>{header.display} | )}
|---|---|---|
| {player[header.key]} | + })} +
{`${playerSummary.nameFirst} is ${playerSummary.age}-year-old, ${playerSummary.handedness.toLowerCase()} handed, and plays the ${playerSummary.position.toLowerCase()} position.`}
+{`Phone: ${playerSummary.phone}`}
+{`Email: ${playerSummary.email}`}
+