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

Initial solution #1110

Open
wants to merge 4 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
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@ implement the ability to filter and sort people in the table.
1. Keep search params when navigating within the `People` page (when selecting a person or clicking the `People` link).
1. The sidebar with the filters should appear only when people are loaded.
1. `NameFilter` should update the `query` search param with the text from the input.
- show only people with the `name`, `motherName` or `fatherName` that match the query case insensitive;
- if the input is empty there should not be `query` in the search params.
- show only people with the `name`, `motherName` or `fatherName` that match the query case insensitive;
- if the input is empty there should not be `query` in the search params.
1. `CenturyFilter` should allow to choose several centuries or all of them.
- add `centuries` search params using `append` method `getAll` method;
- add `centuries` search params using `append` method `getAll` method;
1. Implement sorting by `name`, `sex`, `born` and `died` by clicking on arrows in a `th`;
- the first click on a column sorts people by the selected field ascending (`a -> z` or `0 -> 9`);
- the second click (when people are already sorted ascending by this field) reverses the order of sorting;
- the third click (when people are already sorted in reversed order by this field) disables sorting;
- use `sort` search param to save sort field;
- add `order=desc` (short for `descending`) if sorted in reversed order;
- if sorting is disabled there should not be `sort` and `order` search params;
- the first click on a column sorts people by the selected field ascending (`a -> z` or `0 -> 9`);
- the second click (when people are already sorted ascending by this field) reverses the order of sorting;
- the third click (when people are already sorted in reversed order by this field) disables sorting;
- use `sort` search param to save sort field;
- add `order=desc` (short for `descending`) if sorted in reversed order;
- if sorting is disabled there should not be `sort` and `order` search params;

## Instructions

- Install Prettier Extention and use this [VSCode settings](https://mate-academy.github.io/fe-program/tools/vscode/settings.json) to enable format on save.
- 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://v1rnt.github.io/react_people-table-advanced/) and add it to the PR description.
2,730 changes: 1,176 additions & 1,554 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 3 additions & 5 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 { Navbar } from './components/Navbar/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 { HomePage } from './pages/HomePage';
import { PeoplePage } from './pages/PeoplePage';
import { PageNotFound } from './pages/PageNotFound';
import { App } from './App';
import { Paths } from './types/Paths';

export const Root = () => (
<Router>
<Routes>
<Route path={Paths.Home} element={<App />}>
<Route index element={<HomePage />} />
<Route path={Paths.HomePage} element={<Navigate to="/" replace />} />
<Route path={Paths.People} element={<PeoplePage />}>
<Route index />
<Route path={Paths.PersonDetail} />
</Route>
<Route path={Paths.PageNotFound} element={<PageNotFound />} />
</Route>
</Routes>
</Router>
);
26 changes: 0 additions & 26 deletions src/components/Navbar.tsx

This file was deleted.

31 changes: 31 additions & 0 deletions src/components/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import cn from 'classnames';
import { NavLink } from 'react-router-dom';

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

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={activeNavbar} to="/">
Home
</NavLink>

<NavLink aria-current="page" className={activeNavbar} to="/people">
People
</NavLink>
</div>
</div>
</nav>
);
};
1 change: 1 addition & 0 deletions src/components/Navbar/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Navbar';
96 changes: 0 additions & 96 deletions src/components/PeopleFilters.tsx

This file was deleted.

102 changes: 102 additions & 0 deletions src/components/PeopleFilters/PeopleFilters.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import cn from 'classnames';
import { SearchLink } from '../SearchLink';
import { useFilters } from '../../hooks/useFilters';
import { CENTURIES } from '../../constants/CENTURIES';
import { Sex } from '../../types/Sex';

export const PeopleFilters = () => {
const { sex, query, centuries, handleSetQuery, getCenturiesParams } =
useFilters();

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

<p className="panel-tabs" data-cy="SexFilter">
<SearchLink
className={cn({ 'is-active': sex === null })}
params={{ sex: null }}

Choose a reason for hiding this comment

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

You can create an enum for sex values

>
All
</SearchLink>

<SearchLink
className={cn({ 'is-active': sex === Sex.MALE })}
params={{ sex: Sex.MALE }}
>
Male
</SearchLink>

<SearchLink
className={cn({ 'is-active': sex === Sex.FEMALE })}
params={{ sex: Sex.FEMALE }}
>
Female
</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={event => {
handleSetQuery(event.target.value);
}}
/>

<span className="icon is-left">
<i className="fas fa-search" aria-hidden="true" />
</span>
</p>
</div>

<div className="panel-block">
<div className="level is-flex-grow-1 is-mobile" data-cy="CenturyFilter">
<div className="level-left">
{CENTURIES.map(century => (
<SearchLink
key={century}
data-cy="century"
params={{
centuries: getCenturiesParams(century),
}}
className={cn('button mr-1', {
'is-info': centuries.includes(century),
})}
>
{century}
</SearchLink>
))}
</div>

<div className="level-right ml-4">
<SearchLink
data-cy="centuryALL"
className={cn('button is-success', {
'is-outlined': centuries.length !== 0,
})}
params={{ centuries: null }}
>
All
</SearchLink>
</div>
</div>
</div>

<div className="panel-block">
<SearchLink
className={cn('button is-link is-outlined is-fullwidth', {
'is-outlined': sex === null && !centuries.length && query === '',

Choose a reason for hiding this comment

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

Create a variable for these conditions checks

})}
params={{ sex: null, centuries: null, query: null }}
>
Reset all filters
</SearchLink>
</div>
</nav>
);
};
1 change: 1 addition & 0 deletions src/components/PeopleFilters/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './PeopleFilters';
33 changes: 0 additions & 33 deletions src/components/PeoplePage.tsx

This file was deleted.

Loading