Skip to content
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

add task solution #1171

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ implement the ability to filter and sort people in the table.
- Implement a solution following the [React task guideline](https://github.com/mate-academy/react_task-guideline#react-tasks-guideline).
- Use the [React TypeScript cheat sheet](https://mate-academy.github.io/fe-program/js/extra/react-typescript).
- Open one more terminal and run tests with `npm test` to ensure your solution is correct.
- Replace `<your_account>` with your Github username in the [DEMO LINK](https://<your_account>.github.io/react_people-table-advanced/) and add it to the PR description.
- Replace `<your_account>` with your Github username in the [DEMO LINK](https://Mariagosp.github.io/react_people-table-advanced/) and add it to the PR description.
6 changes: 2 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PeoplePage } from './components/PeoplePage';
import { Navbar } from './components/Navbar';

import './App.scss';
import { Outlet } from 'react-router-dom';

export const App = () => {
return (
Expand All @@ -10,9 +10,7 @@ export const App = () => {

<div className="section">
<div className="container">
<h1 className="title">Home Page</h1>
<h1 className="title">Page not found</h1>
<PeoplePage />
<Outlet />
</div>
</div>
</div>
Expand Down
27 changes: 27 additions & 0 deletions src/Root.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {
Navigate,
Route,
HashRouter as Router,
Routes,
} from 'react-router-dom';
import { App } from './App';
import { PeoplePage } from './pages/PeoplePage';
import { HomePage } from './pages/HomePage';
import { NotFoundPage } from './pages/NotFoundPage';

export const Root = () => (
<Router>
<Routes>
<Route path="/" element={<App />}>
<Route index element={<HomePage />} />
<Route path="people">
<Route index element={<PeoplePage />} />
<Route path=":slug" element={<PeoplePage />} />
</Route>

<Route path="/home" element={<Navigate to="/" replace />} />
<Route path="*" element={<NotFoundPage />} />
</Route>
</Routes>
</Router>
);
18 changes: 10 additions & 8 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import cn from 'classnames';
import { NavLink } from 'react-router-dom';

export const Navbar = () => {
const getLinkClass = ({ isActive }: { isActive: boolean }) =>
cn('navbar-item', { 'has-background-grey-lighter': isActive });

return (
<nav
data-cy="nav"
Expand All @@ -8,17 +14,13 @@ export const Navbar = () => {
>
<div className="container">
<div className="navbar-brand">
<a className="navbar-item" href="#/">
<NavLink className={getLinkClass} to="/">
Home
</a>
</NavLink>

<a
aria-current="page"
className="navbar-item has-background-grey-lighter"
href="#/people"
>
<NavLink aria-current="page" className={getLinkClass} to="/people">
People
</a>
</NavLink>
</div>
</div>
</nav>
Expand Down
118 changes: 69 additions & 49 deletions src/components/PeopleFilters.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,65 @@
export const PeopleFilters = () => {
import cn from 'classnames';
import { SexType } from '../types/SexType';
import { SearchLink } from './SearchLink';

type Props = {
query: string;
sex: SexType;
centuries: string[];
handleQueryChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
// handleSexChange: (sex: SexType) => void;
// toggleCenturies: (ch: string) => void;
};
Comment on lines +10 to +11

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The handlers handleSexChange and toggleCenturies are commented out. If these are necessary for the component's functionality, consider implementing and using them.


export const PeopleFilters: React.FC<Props> = props => {
const { query, sex, centuries, handleQueryChange } = props;

return (
<nav className="panel">
<p className="panel-heading">Filters</p>

<p className="panel-tabs" data-cy="SexFilter">
<a className="is-active" href="#/people">
<SearchLink
params={{ sex: null }}
className={cn({ 'is-active': sex === SexType.All })}
>
All
</a>
<a className="" href="#/people?sex=m">
</SearchLink>
<SearchLink
params={{ sex: SexType.Male }}
className={cn({ 'is-active': sex === SexType.Male })}
>
Male
</a>
<a className="" href="#/people?sex=f">
</SearchLink>
<SearchLink
params={{ sex: SexType.Female }}
className={cn({ 'is-active': sex === SexType.Female })}
>
Female
</a>
</SearchLink>
</p>

{/* <p className="panel-tabs" data-cy="SexFilter">
{Object.values(SexType).map(sexOption => (
<SearchLink
key={sexOption}
params={{ sex: sexOption === SexType.All ? null : sexOption }}
className={cn({ 'is-active': sexOption === sex })}
>
{sexOption}
</SearchLink>
))}
</p> */}

<div className="panel-block">
<p className="control has-icons-left">
<input
data-cy="NameFilter"
type="search"
className="input"
placeholder="Search"
value={query}
onChange={handleQueryChange}
/>

<span className="icon is-left">
Expand All @@ -33,51 +71,30 @@ export const PeopleFilters = () => {
<div className="panel-block">
<div className="level is-flex-grow-1 is-mobile" data-cy="CenturyFilter">
<div className="level-left">
<a
data-cy="century"
className="button mr-1"
href="#/people?centuries=16"
>
16
</a>

<a
data-cy="century"
className="button mr-1 is-info"
href="#/people?centuries=17"
>
17
</a>

<a
data-cy="century"
className="button mr-1 is-info"
href="#/people?centuries=18"
>
18
</a>

<a
data-cy="century"
className="button mr-1 is-info"
href="#/people?centuries=19"
>
19
</a>

<a
data-cy="century"
className="button mr-1"
href="#/people?centuries=20"
>
20
</a>
{['16', '17', '18', '19', '20'].map(century => (
<SearchLink
key={century}
params={{
centuries: centuries.includes(century)
? centuries.filter(cent => cent !== century)
: [...centuries, century],
}}
data-cy="century"
className={cn('button mr-1', {
'is-info': centuries.includes(century),
})}
>
{century}
</SearchLink>
))}
</div>

<div className="level-right ml-4">
<a
data-cy="centuryALL"
className="button is-success is-outlined"
className={cn('button is-success', {
'is-outlined': centuries.length !== 0,
})}
href="#/people"
>
All
Expand All @@ -87,9 +104,12 @@ export const PeopleFilters = () => {
</div>

<div className="panel-block">
<a className="button is-link is-outlined is-fullwidth" href="#/people">
<SearchLink
className="button is-link is-outlined is-fullwidth"
params={{ query: '', sex: SexType.All, centuries: [] }}
>
Reset all filters
</a>
</SearchLink>
</div>
</nav>
);
Expand Down
33 changes: 0 additions & 33 deletions src/components/PeoplePage.tsx

This file was deleted.

Loading
Loading