-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Complete Task #1726
base: master
Are you sure you want to change the base?
Complete Task #1726
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { | ||
Navigate, | ||
Route, | ||
HashRouter as Router, | ||
Routes, | ||
} from 'react-router-dom'; | ||
import { App } from './App'; | ||
import { HomePage } from './pages/HomePage'; | ||
import { PeoplePage } from './pages/PeoplePage'; | ||
import { PeopleProvider } from './store/peopleContext'; | ||
|
||
export const Root = () => ( | ||
<PeopleProvider> | ||
<Router> | ||
<Routes> | ||
<Route path="/" element={<App />}> | ||
<Route index element={<HomePage />} /> | ||
<Route path="home" element={<Navigate to=".." />} /> | ||
<Route path="people/:persSlug?" element={<PeoplePage />} /> | ||
<Route path="*" element={<h1 className="title">Page not found</h1>} /> | ||
</Route> | ||
</Routes> | ||
</Router> | ||
</PeopleProvider> | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import classNames from 'classnames'; | ||
import { NavLink } from 'react-router-dom'; | ||
|
||
const getLinkClass = ({ isActive }: { isActive: boolean }) => | ||
classNames('navbar-item', { | ||
'has-background-grey-lighter': isActive, | ||
}); | ||
|
||
export const Header = () => { | ||
return ( | ||
<nav | ||
data-cy="nav" | ||
className="navbar is-fixed-top has-shadow" | ||
role="navigation" | ||
aria-label="main navigation" | ||
> | ||
<div className="container"> | ||
<div className="navbar-brand"> | ||
<NavLink className={getLinkClass} to="/"> | ||
Home | ||
</NavLink> | ||
|
||
<NavLink className={getLinkClass} to="/people"> | ||
People | ||
</NavLink> | ||
</div> | ||
</div> | ||
</nav> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Header'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React, { useContext } from 'react'; | ||
import { Person } from '../../types'; | ||
import { useParams } from 'react-router-dom'; | ||
import { PeopleContext } from '../../store/peopleContext'; | ||
import classNames from 'classnames'; | ||
|
||
type Props = { | ||
person: Person; | ||
}; | ||
|
||
export const PeopleItem: React.FC<Props> = ({ person }) => { | ||
const { persSlug } = useParams(); | ||
const currPerson = { ...person }; | ||
const { people } = useContext(PeopleContext); | ||
|
||
if (person.motherName) { | ||
currPerson.mother = people.find(p => p.name === person.motherName); | ||
} | ||
|
||
if (person.fatherName) { | ||
currPerson.father = people.find(p => p.name === person.fatherName); | ||
} | ||
|
||
return ( | ||
<tr | ||
data-cy="person" | ||
className={classNames({ | ||
'has-background-warning': persSlug === currPerson.slug, | ||
})} | ||
> | ||
<td> | ||
<a | ||
className={classNames({ 'has-text-danger': person.sex === 'f' })} | ||
href={`#/people/${currPerson.slug}`} | ||
> | ||
{currPerson.name} | ||
</a> | ||
</td> | ||
|
||
<td>{currPerson.sex}</td> | ||
<td>{currPerson.born}</td> | ||
<td>{currPerson.died}</td> | ||
|
||
<td> | ||
{currPerson.mother ? ( | ||
<a | ||
className="has-text-danger" | ||
href={`#/people/${currPerson.mother?.slug}`} | ||
> | ||
{currPerson.motherName} | ||
</a> | ||
) : currPerson.motherName ? ( | ||
currPerson.motherName | ||
) : ( | ||
'-' | ||
)} | ||
</td> | ||
|
||
<td> | ||
{currPerson.father ? ( | ||
<a href={`#/people/${currPerson.father.slug}`}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure that |
||
{currPerson.fatherName} | ||
</a> | ||
) : currPerson.fatherName ? ( | ||
currPerson.fatherName | ||
) : ( | ||
'-' | ||
)} | ||
</td> | ||
</tr> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './PeopleItem'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { useContext } from 'react'; | ||
import { PeopleContext } from '../../store/peopleContext'; | ||
import { PeopleItem } from '../PeopleItem'; | ||
|
||
export const PeopleTable = () => { | ||
const { people } = useContext(PeopleContext); | ||
|
||
return ( | ||
<table | ||
data-cy="peopleTable" | ||
className="table is-striped is-hoverable is-narrow is-fullwidth" | ||
> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
<th>Sex</th> | ||
<th>Born</th> | ||
<th>Died</th> | ||
<th>Mother</th> | ||
<th>Father</th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
{people.map((person, index) => ( | ||
<PeopleItem key={index} person={person} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using a unique identifier from the |
||
))} | ||
|
||
{/* <tr data-cy="person" className="has-background-warning"> | ||
<td> | ||
<a href="#/people/jan-frans-van-brussel-1761"> | ||
Jan Frans van Brussel | ||
</a> | ||
</td> | ||
|
||
<td>m</td> | ||
<td>1761</td> | ||
<td>1833</td> | ||
<td>-</td> | ||
|
||
<td> | ||
<a href="#/people/jacobus-bernardus-van-brussel-1736"> | ||
Jacobus Bernardus van Brussel | ||
</a> | ||
</td> | ||
</tr> */} | ||
</tbody> | ||
</table> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './PeopleTable'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
import { createRoot } from 'react-dom/client'; | ||
import { HashRouter as Router } from 'react-router-dom'; | ||
|
||
import 'bulma/css/bulma.css'; | ||
import '@fortawesome/fontawesome-free/css/all.css'; | ||
|
||
import { App } from './App'; | ||
import { Root } from './Root'; | ||
|
||
createRoot(document.getElementById('root') as HTMLDivElement).render( | ||
<Router> | ||
<App /> | ||
</Router>, | ||
); | ||
createRoot(document.getElementById('root') as HTMLDivElement).render(<Root />); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const HomePage = () => { | ||
return <h1 className="title">Home Page</h1>; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './HomePage'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that
currPerson.mother?.slug
is defined before accessing it. Ifslug
is not guaranteed to be present, consider adding a check or default value.