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

Develop #511

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 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://voronine.github.io/react_people-table-advanced/) and add it to the PR description.
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"classnames": "^2.3.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.15.0",
"react-router-dom": "^6.16.0",
"react-scripts": "4.0.3"
},
"devDependencies": {
Expand Down
22 changes: 10 additions & 12 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { PeoplePage } from './components/PeoplePage';
import { Navbar } from './components/Navbar';

import './App.scss';
import { Outlet } from 'react-router-dom';
import { Navbar } from './components/Navbar';
import { PeopleProvider } from './store/PeopleContext';

export const App = () => {
return (
export const App = () => (
<PeopleProvider>
<div data-cy="app">
<Navbar />

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

import { App } from './App';

import { HomePage } from './pages/HomePage';
import { PeoplePage } from './pages/PeoplePage';
import { NotFoundPage } from './pages/NotFoundPage';

export const Root = () => (
<Router>
<Routes>
<Route path="/" element={<App />}>
<Route path="*" element={<NotFoundPage />} />
<Route index element={<HomePage />} />
<Route path="home" element={<Navigate to="/" replace />} />
<Route path="people" element={<PeoplePage />}>
<Route path=":personId?" />
</Route>
</Route>
</Routes>
</Router>
);
10 changes: 10 additions & 0 deletions src/components/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Navigate } from 'react-router-dom';

export const HomePage = () => {
return (
<>
<h1 className="title">Home Page</h1>
<Navigate to="/" replace />
voronine marked this conversation as resolved.
Show resolved Hide resolved
</>
);
};
54 changes: 32 additions & 22 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
export const Navbar = () => {
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">
<a className="navbar-item" href="#/">Home</a>
import cn from 'classnames';
import { NavLink } from 'react-router-dom';

<a
aria-current="page"
className="navbar-item has-background-grey-lighter"
href="#/people"
>
People
</a>
</div>
const getLinkClass = ({ isActive }: { isActive: boolean }) => cn(
'navbar-item',
{ 'has-background-grey-lighter': isActive },
);

export const Navbar = () => (
<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>
</nav>
);
};
</div>
</nav>
);
125 changes: 77 additions & 48 deletions src/components/PeopleFilters.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,56 @@
import cn from 'classnames';
import { useSearchParams } from 'react-router-dom';
import { getSearchWith } from '../utils/searchHelper';
import { SearchLink } from './SearchLink';
import {
CENTURIES,
EMPTY_STRING,
SEX_FEMALE,
SEX_MALE,
} from '../utils/constants';

export const PeopleFilters = () => {
const [searchParams, setSearchParams] = useSearchParams();
const query = searchParams.get('query')?.trim() || '';
const centuries = searchParams.getAll('centuries') || [];

function handleQueryChange(event: React.ChangeEvent<HTMLInputElement>) {
setSearchParams(getSearchWith(searchParams, {
query: event.target.value || null,
}));
}

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

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

<SearchLink
className={cn({
'is-active': searchParams.get('sex') === SEX_MALE,
})}
params={{ sex: SEX_MALE }}
>
Male
</SearchLink>

<SearchLink
className={cn({
'is-active': searchParams.get('sex') === SEX_FEMALE,
})}
params={{ sex: SEX_FEMALE }}
>
Female
</SearchLink>
</p>

<div className="panel-block">
Expand All @@ -16,6 +60,8 @@ export const PeopleFilters = () => {
type="search"
className="input"
placeholder="Search"
value={query}
onChange={handleQueryChange}
/>

<span className="icon is-left">
Expand All @@ -27,66 +73,49 @@ 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>
{CENTURIES.map((century) => {
const newCenturies = centuries.includes(century)
? centuries.filter(epoch => epoch !== century)
: [...centuries, century];

<a
data-cy="century"
className="button mr-1"
href="#/people?centuries=20"
>
20
</a>
return (
<SearchLink
key={century}
data-cy="century"
className={cn('button', 'mr-1', {
'is-info': centuries.includes(century),
})}
params={{ centuries: newCenturies }}
>
{century}
</SearchLink>
);
})}
</div>

<div className="level-right ml-4">
<a
<SearchLink
data-cy="centuryALL"
className="button is-success is-outlined"
href="#/people"
className={cn(
'button',
'is-success',
{ 'is-outlined': centuries.length },
)}
params={{ centuries: [] }}
>
All
</a>
</SearchLink>
</div>
</div>
</div>

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

This file was deleted.

Loading