generated from mate-academy/react_people-table
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
solution #525
Open
emil-owczarek
wants to merge
1
commit into
mate-academy:master
Choose a base branch
from
emil-owczarek:develop
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
solution #525
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,36 @@ | ||
import { PeoplePage } from './components/PeoplePage'; | ||
import { Navbar } from './components/Navbar'; | ||
|
||
import { Navigate, createHashRouter, RouterProvider } from 'react-router-dom'; | ||
import './App.scss'; | ||
import Home from './pages/HomePage'; | ||
import RootLayout from './pages/Root'; | ||
import ErrorPage from './pages/Error'; | ||
import PeoplePage from './pages/People'; | ||
|
||
const router = createHashRouter([{ | ||
path: '/', | ||
element: <RootLayout />, | ||
errorElement: <ErrorPage />, | ||
children: [ | ||
{ path: '/', element: <Home /> }, | ||
{ path: '/home', element: <Navigate to="/" replace /> }, | ||
{ | ||
path: '/people', | ||
element: <PeoplePage />, | ||
children: [ | ||
{ path: ':slug', element: <PeoplePage /> }, | ||
], | ||
}, | ||
], | ||
}]); | ||
|
||
export const App = () => { | ||
function App() { | ||
return ( | ||
<div data-cy="app"> | ||
<Navbar /> | ||
|
||
<div className="section"> | ||
<div className="container"> | ||
<h1 className="title">Home Page</h1> | ||
<h1 className="title">Page not found</h1> | ||
<PeoplePage /> | ||
</div> | ||
<> | ||
<div data-cy="app"> | ||
<RouterProvider router={router} /> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}; | ||
} | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import classNames from 'classnames'; | ||
import { NavLink } from 'react-router-dom'; | ||
|
||
function MainNavigation() { | ||
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={({ isActive }) => classNames( | ||
'navbar-item', { 'has-background-grey-lighter': isActive }, | ||
)} | ||
to="/" | ||
> | ||
Home | ||
</NavLink> | ||
<NavLink | ||
className={({ isActive }) => classNames( | ||
'navbar-item', { 'has-background-grey-lighter': isActive }, | ||
)} | ||
to="/people" | ||
> | ||
People | ||
</NavLink> | ||
</div> | ||
</div> | ||
</nav> | ||
</> | ||
); | ||
} | ||
|
||
export default MainNavigation; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* eslint-disable max-len */ | ||
import { SearchLink } from '../SearchLink'; | ||
|
||
interface PeopleFiltersProps { | ||
setSearchParams: (params: Record<string, any>) => void; | ||
searchParams: URLSearchParams; | ||
} | ||
|
||
const centuriesList = ['16', '17', '18', '19', '20']; | ||
|
||
const PeopleFilters: React.FC<PeopleFiltersProps> | ||
= ({ setSearchParams, searchParams }) => { | ||
const handleNameFilterChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
const query = event.target.value; | ||
|
||
setSearchParams({ ...searchParams, query: query || null }); | ||
}; | ||
|
||
const handleCenturyClick = (century: string): string[] => { | ||
const currentCenturies = searchParams.getAll('centuries').includes(century) | ||
? searchParams.getAll('centuries').filter(c => c !== century) | ||
: [...searchParams.getAll('centuries'), century]; | ||
|
||
return currentCenturies; | ||
}; | ||
|
||
const handleSexClick = (sex: string | null) => { | ||
setSearchParams({ ...searchParams, sex: sex || undefined }); | ||
}; | ||
|
||
const getActiveClass = (key: string, value: string) => { | ||
if (key === 'centuries') { | ||
return searchParams.getAll(key).includes(value) ? 'is-info' : ''; | ||
} | ||
|
||
return searchParams.get(key) === value ? 'is-active' : ''; | ||
}; | ||
|
||
return ( | ||
<nav className="panel"> | ||
<p className="panel-heading">Filters</p> | ||
|
||
<p className="panel-tabs" data-cy="SexFilter"> | ||
{['All', 'Male', 'Female'].map(label => { | ||
const sexValue = label === 'All' ? '' : label[0].toLowerCase(); | ||
|
||
return ( | ||
<SearchLink | ||
key={label} | ||
className={getActiveClass('sex', sexValue)} | ||
params={{ sex: sexValue }} | ||
onClick={() => handleSexClick(sexValue)} | ||
> | ||
{label} | ||
</SearchLink> | ||
); | ||
})} | ||
</p> | ||
|
||
<div className="panel-block"> | ||
<p className="control has-icons-left"> | ||
<input | ||
data-cy="NameFilter" | ||
type="search" | ||
className="input" | ||
placeholder="Search" | ||
onChange={handleNameFilterChange} | ||
value={searchParams.get('query') || ''} | ||
/> | ||
<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"> | ||
{centuriesList.map(century => ( | ||
<SearchLink | ||
key={century} | ||
className={`button mr-1 ${getActiveClass('centuries', century)}`} | ||
params={{ centuries: handleCenturyClick(century) }} | ||
onClick={() => { | ||
const updatedCenturies = handleCenturyClick(century); | ||
|
||
setSearchParams({ ...searchParams, centuries: updatedCenturies }); | ||
}} | ||
Comment on lines
+84
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think should a separate function |
||
> | ||
{century} | ||
</SearchLink> | ||
))} | ||
</div> | ||
<div className="level-right ml-4"> | ||
<SearchLink className="button is-success is-outlined" params={{ centuries: [] }}> | ||
All | ||
</SearchLink> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div className="panel-block"> | ||
<a className="button is-link is-outlined is-fullwidth" href="#/people"> | ||
Reset all filters | ||
</a> | ||
</div> | ||
</nav> | ||
); | ||
}; | ||
|
||
export default PeopleFilters; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.