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 #1122

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Develop #1122

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://momos1703.github.io/react_people-table-advanced/) and add it to the PR description.
18 changes: 10 additions & 8 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "GPL-3.0",
"dependencies": {
"@fortawesome/fontawesome-free": "^6.5.2",
"bulma": "^1.0.1",
"bulma": "^0.9.4",
"classnames": "^2.5.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand All @@ -16,7 +16,7 @@
},
"devDependencies": {
"@cypress/react18": "^2.0.1",
"@mate-academy/scripts": "^1.8.5",
"@mate-academy/scripts": "^1.9.12",
"@mate-academy/students-ts-config": "*",
"@mate-academy/stylelint-config": "*",
"@types/node": "^20.14.10",
Expand Down
11 changes: 4 additions & 7 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { PeoplePage } from './components/PeoplePage';
import { Navbar } from './components/Navbar';

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

Check failure on line 3 in src/App.tsx

View workflow job for this annotation

GitHub Actions / run_linter (20.x)

Missing file extension for "./components/Navbar"

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

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

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

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

const { search } = useLocation();

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

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

This file was deleted.

130 changes: 79 additions & 51 deletions src/components/PeopleFilters.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,60 @@
/* eslint-disable @typescript-eslint/indent */
import { useSearchParams } from 'react-router-dom';
import { getSearchWith } from '../utils/searchHelper';
import classNames from 'classnames';
import { SearchLink } from './SearchLink';

export const PeopleFilters = () => {
const [searchParams, setSearchParams] = useSearchParams();
const centuryList = ['16', '17', '18', '19', '20'];
const query = searchParams.getAll('query') || '';
const sex = searchParams.get('sex') || '';
const selectedCenturies = searchParams.getAll('centuries') || [];

const handleQuery = (event: React.ChangeEvent<HTMLInputElement>) => {
const search = getSearchWith(searchParams, {
query: event.target.value || null,
});

setSearchParams(search);
};

const checkIfAllreadyChoose = (
selectedFilters: string[],
newSelected: string,
): string[] => {
const newFilters = selectedFilters.includes(newSelected)
? selectedFilters.filter(selectedFilter => selectedFilter !== newSelected)
: [...selectedFilters, newSelected];

return newFilters;
};

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

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

<SearchLink
className={classNames({ 'is-active': sex === 'm' })}
params={{ sex: 'm' }}
>
Male
</a>
<a className="" href="#/people?sex=f">
</SearchLink>

<SearchLink
className={classNames({ 'is-active': sex === 'f' })}
params={{ sex: 'f' }}
>
Female
</a>
</SearchLink>
</p>

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

<span className="icon is-left">
Expand All @@ -33,63 +77,47 @@ 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>
{centuryList.map(century => (
<SearchLink
key={century}
data-cy="century"
className={classNames('button mr-1', {
'is-info': selectedCenturies.includes(century),
})}
params={{
centuries: checkIfAllreadyChoose(selectedCenturies, century),
}}
>
{century}
</SearchLink>
))}
</div>

<div className="level-right ml-4">
<a
<SearchLink
data-cy="centuryALL"
className="button is-success is-outlined"
href="#/people"
className={classNames('button is-success', {
'is-outlined': selectedCenturies.length > 0,
})}
params={{ centuries: null }}
>
All
</a>
</SearchLink>
</div>
</div>
</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={{
centuries: null,
query: null,
sex: null,
}}
>
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