generated from mate-academy/react_people-table
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
463f841
commit a7ef529
Showing
19 changed files
with
29,975 additions
and
933 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,15 @@ | ||
import { PeoplePage } from './components/PeoplePage'; | ||
import { Outlet } from 'react-router-dom'; | ||
import { Navbar } from './components/Navbar'; | ||
|
||
import './App.scss'; | ||
|
||
export const App = () => { | ||
return ( | ||
<div data-cy="app"> | ||
<Navbar /> | ||
|
||
<div className="section"> | ||
<div className="container"> | ||
<h1 className="title">Home Page</h1> | ||
<h1 className="title">Page not found</h1> | ||
<PeoplePage /> | ||
</div> | ||
export const App = () => ( | ||
<div data-cy="app"> | ||
<Navbar /> | ||
<main className="section"> | ||
<div className="container"> | ||
<Outlet /> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
</main> | ||
</div> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { | ||
HashRouter, | ||
Routes, | ||
Route, | ||
Navigate, | ||
} from 'react-router-dom'; | ||
import { App } from './App'; | ||
import { HomePage } from './pages/HomePage'; | ||
import { NotFoundPage } from './pages/NotFoundPage'; | ||
import { PeoplePage } from './pages/PeoplePage'; | ||
import { PeopleProvider } from './store/PeopleContext'; | ||
|
||
export const Root = () => { | ||
return ( | ||
<HashRouter> | ||
<PeopleProvider> | ||
<Routes> | ||
<Route path="/" element={<App />}> | ||
<Route path="*" element={<NotFoundPage />} /> | ||
<Route index element={<HomePage />} /> | ||
<Route path="people" element={<PeoplePage />}> | ||
<Route path=":slug" element={<PeoplePage />} /> | ||
</Route> | ||
<Route path="home" element={<Navigate to="/" replace />} /> | ||
</Route> | ||
</Routes> | ||
</PeopleProvider> | ||
</HashRouter> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import React from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
import classNames from 'classnames'; | ||
import { Person } from '../../types'; | ||
import { PersonLink } from './PersonLink'; | ||
import { SortLink } from '../SortLink'; | ||
|
||
type Props = { | ||
people: Person[]; | ||
}; | ||
|
||
export const People: React.FC<Props> = ({ people }) => { | ||
const { slug } = useParams(); | ||
const realSlug = slug ?? null; | ||
|
||
return ( | ||
<table | ||
data-cy="peopleTable" | ||
className="table is-striped is-hoverable is-narrow is-fullwidth" | ||
> | ||
<thead> | ||
<tr> | ||
<th> | ||
<SortLink sortField="name">Name</SortLink> | ||
</th> | ||
<th> | ||
<SortLink sortField="sex">Sex</SortLink> | ||
</th> | ||
<th> | ||
<SortLink sortField="born">Born</SortLink> | ||
</th> | ||
<th> | ||
<SortLink sortField="died">Died</SortLink> | ||
</th> | ||
<th>Mother</th> | ||
<th>Father</th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
{people.map(person => ( | ||
<tr | ||
data-cy="person" | ||
key={person.slug} | ||
className={classNames({ | ||
'has-background-warning': person.slug === realSlug, | ||
})} | ||
> | ||
<td> | ||
<PersonLink person={person} /> | ||
</td> | ||
<td>{person.sex}</td> | ||
<td>{person.born}</td> | ||
<td>{person.died}</td> | ||
<td> | ||
{person.mother | ||
? ( | ||
<PersonLink person={person.mother} /> | ||
) : ( | ||
person.motherName || '-' | ||
)} | ||
</td> | ||
<td> | ||
{person.father | ||
? ( | ||
<PersonLink person={person.father} /> | ||
) : ( | ||
person.fatherName || '-' | ||
)} | ||
</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react'; | ||
import { Link, useLocation } from 'react-router-dom'; | ||
import classNames from 'classnames'; | ||
import { Person } from '../../types'; | ||
|
||
type Props = { | ||
person: Person; | ||
}; | ||
|
||
export const PersonLink: React.FC<Props> = ({ person }) => { | ||
const { search } = useLocation(); | ||
|
||
return ( | ||
<Link | ||
to={{ | ||
pathname: person.slug, | ||
search, | ||
}} | ||
className={classNames({ | ||
'has-text-danger': person.sex === 'f', | ||
})} | ||
> | ||
{person.name} | ||
</Link> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './PersonLink'; | ||
export * from './People'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.