Skip to content
Open

done #1774

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
129 changes: 39 additions & 90 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"devDependencies": {
"@cypress/react18": "^2.0.1",
"@mate-academy/scripts": "^1.9.12",
"@mate-academy/scripts": "^2.1.3",
"@mate-academy/students-ts-config": "*",
"@mate-academy/stylelint-config": "*",
"@types/node": "^20.14.10",
Expand Down
65 changes: 50 additions & 15 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,55 @@
import { PeoplePage } from './components/PeoplePage';
import { Navbar } from './components/Navbar';

import './App.scss';

export const App = () => {
return (
<div data-cy="app">
<Navbar />
import { Route, Routes, Navigate, NavLink } from 'react-router-dom';
import { HomePage } from './components/HomePage';
import { PeoplePage } from './components/PeoplePage';
import { NotFoundPage } from './components/NotFoundPage';

export const App = () => (
<div data-cy="app">
<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
to="/"
className={({ isActive }) =>
isActive
? 'navbar-item has-background-grey-lighter'
: 'navbar-item'
}
>
Home
</NavLink>

<div className="section">
<div className="container">
<h1 className="title">Home Page</h1>
<h1 className="title">Page not found</h1>
<PeoplePage />
<NavLink
to="/people"
className={({ isActive }) =>
isActive
? 'navbar-item has-background-grey-lighter'
: 'navbar-item'
}
>
People
</NavLink>
</div>
</div>
</div>
);
};
</nav>

<main className="section">
<div className="container">
<Routes>
<Route path="/" element={<HomePage />} />
<Route path="/home" element={<Navigate to="/" replace />} />
<Route path="/people/:slug" element={<PeoplePage />} />
<Route path="/people" element={<PeoplePage />} />
<Route path="*" element={<NotFoundPage />} />
</Routes>
</div>
</main>
</div>
);
3 changes: 3 additions & 0 deletions src/components/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const HomePage = () => {
return <h1 className="title">Home Page</h1>;
};
3 changes: 3 additions & 0 deletions src/components/NotFoundPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const NotFoundPage = () => {
return <h1 className="title">Page not found</h1>;
};
122 changes: 90 additions & 32 deletions src/components/PeopleFilters.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,64 @@
import { useSearchParams } from 'react-router-dom';
import { SearchLink } from './SearchLink';

export const PeopleFilters = () => {
const [searchParams, setSearchParams] = useSearchParams();

const query = searchParams.get('query') || '';
const sex = searchParams.get('sex');
const centuries = searchParams.getAll('centuries');

const handleQueryChange = (value: string) => {
const params = new URLSearchParams(searchParams);

if (value) {
params.set('query', value);
} else {
params.delete('query');
}

setSearchParams(params);
};

const toggleCentury = (century: string) => {
const params = new URLSearchParams(searchParams);
const current: string[] = params.getAll('centuries');

if (current.includes(century)) {
params.delete('centuries');
current
.filter(c => c !== century)
.forEach(c => params.append('centuries', c));
} else {
params.append('centuries', century);
}

setSearchParams(params);
};

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={sex === null ? 'is-active' : ''}
params={{ sex: null }}
>
All
</a>
<a className="" href="#/people?sex=m">
</SearchLink>
<SearchLink
className={sex === 'm' ? 'is-active' : ''}
params={{ sex: 'm' }}
>
Male
</a>
<a className="" href="#/people?sex=f">
</SearchLink>
<SearchLink
className={sex === 'f' ? 'is-active' : ''}
params={{ sex: 'f' }}
>
Female
</a>
</SearchLink>
</p>

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

<span className="icon is-left">
Expand All @@ -33,64 +81,74 @@ export const PeopleFilters = () => {
<div className="panel-block">
<div className="level is-flex-grow-1 is-mobile" data-cy="CenturyFilter">
<div className="level-left">
<a
<button
data-cy="century"
className="button mr-1"
href="#/people?centuries=16"
className={`button mr-1 ${centuries.includes('16') ? 'is-info' : ''}`}
onClick={() => toggleCentury('16')}
>
{' '}
16
</a>
</button>

<a
<button
data-cy="century"
className="button mr-1 is-info"
href="#/people?centuries=17"
className={`button mr-1 ${centuries.includes('17') ? 'is-info' : ''}`}
onClick={() => toggleCentury('17')}
>
{' '}
17
</a>
</button>

<a
<button
data-cy="century"
className="button mr-1 is-info"
href="#/people?centuries=18"
className={`button mr-1 ${centuries.includes('18') ? 'is-info' : ''}`}
onClick={() => toggleCentury('18')}
>
{' '}
18
</a>
</button>

<a
<button
data-cy="century"
className="button mr-1 is-info"
href="#/people?centuries=19"
className={`button mr-1 ${centuries.includes('19') ? 'is-info' : ''}`}
onClick={() => toggleCentury('19')}
>
{' '}
19
</a>
</button>

<a
<button
data-cy="century"
className="button mr-1"
href="#/people?centuries=20"
className={`button mr-1 ${centuries.includes('20') ? 'is-info' : ''}`}
onClick={() => toggleCentury('20')}
>
{' '}
20
</a>
</button>
</div>

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

<div className="panel-block">
<a className="button is-link is-outlined is-fullwidth" href="#/people">
<button
className="button is-link is-outlined is-fullwidth"
onClick={() => {
setSearchParams({});
}}
>
Reset all filters
</a>
</button>
</div>
</nav>
);
};
};
Loading
Loading