-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Solution #1834
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
base: master
Are you sure you want to change the base?
Solution #1834
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,34 @@ | ||
| import { PeoplePage } from './components/PeoplePage'; | ||
| import { Navbar } from './components/Navbar'; | ||
| import { Navbar } from './components/NavBar/Navbar'; | ||
|
|
||
| import './App.scss'; | ||
| import { Navigate, Route, Routes } from 'react-router-dom'; | ||
| import { HomePage } from './pages/HomePage/HomePage'; | ||
| import { NotFoundPage } from './pages/NotFoundPage/NotFoundPage'; | ||
| import { PeoplePage } from './pages/PeoplePage/PeoplePage'; | ||
| import { PeopleProvider } from './store/PeopleContext'; | ||
|
|
||
| export const App = () => { | ||
| return ( | ||
| <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 /> | ||
| <Routes> | ||
| <Route path="/home" element={<Navigate to="/" replace />} /> | ||
| <Route path="/" element={<HomePage />} /> | ||
| <Route | ||
| path="/people/:slug?" | ||
|
Comment on lines
+20
to
+21
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. The route setup is fine, but when 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. This |
||
| element={ | ||
| <PeopleProvider> | ||
| <PeoplePage /> | ||
| </PeopleProvider> | ||
| } | ||
| /> | ||
| <Route path="*" element={<NotFoundPage />} /> | ||
| </Routes> | ||
| </div> | ||
| </div> | ||
| </main> | ||
| </div> | ||
| ); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { NavLink, useSearchParams } from 'react-router-dom'; | ||
|
|
||
| const navClass = ({ isActive }: { isActive: boolean }) => | ||
| ['navbar-item', isActive && 'has-background-grey-lighter'] | ||
| .filter(Boolean) | ||
| .join(' '); | ||
|
|
||
| export const Navbar = () => { | ||
| const [searchParams] = useSearchParams(); | ||
|
|
||
| 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={navClass} to="/"> | ||
|
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.
|
||
| Home | ||
| </NavLink> | ||
| <NavLink | ||
| className={navClass} | ||
| to={{ pathname: '/people', search: searchParams.toString() }} | ||
| > | ||
| People | ||
| </NavLink> | ||
| </div> | ||
|
Comment on lines
+12
to
+29
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. You already have a shared |
||
| </div> | ||
| </nav> | ||
| ); | ||
| }; | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| import { useSearchParams } from 'react-router-dom'; | ||
| import { SearchLink } from '../SearchLink/SearchLink'; | ||
| import { getSearchWith, SearchParams } from '../../utils/searchHelper'; | ||
|
|
||
| type Props = {}; | ||
|
|
||
| export const PeopleFilters: React.FC<Props> = () => { | ||
| const [searchParams, setSearchParams] = useSearchParams(); | ||
| const sex = searchParams.get('sex') || ''; | ||
| const query = searchParams.get('query') || ''; | ||
| const centuries = searchParams.getAll('centuries') || []; | ||
|
|
||
| function setSearchWith(params: SearchParams) { | ||
| const search = getSearchWith(searchParams, params); | ||
|
|
||
| setSearchParams(search); | ||
| } | ||
|
|
||
| const handleQueryChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
| setSearchWith({ query: event.target.value || null }); | ||
| }; | ||
|
|
||
| const toggledCenturies = (century: number) => { | ||
| return centuries.includes(century.toString()) | ||
| ? centuries.filter(cent => cent !== century.toString()) | ||
| : [...centuries, century].map(String); | ||
| }; | ||
|
|
||
| return ( | ||
| <nav className="panel"> | ||
| <p className="panel-heading">Filters</p> | ||
|
|
||
| <p className="panel-tabs" data-cy="SexFilter"> | ||
| <SearchLink | ||
| className={`${sex !== 'm' && sex !== 'f' ? 'is-active' : ''}`} | ||
| params={{ sex: null }} | ||
| > | ||
| All | ||
| </SearchLink> | ||
| <SearchLink | ||
| className={`${sex === 'm' ? 'is-active' : ''}`} | ||
| params={{ sex: 'm' }} | ||
| > | ||
| Male | ||
| </SearchLink> | ||
| <SearchLink | ||
| className={`${sex === 'f' ? 'is-active' : ''}`} | ||
| params={{ sex: 'f' }} | ||
| > | ||
| 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={handleQueryChange} | ||
| /> | ||
|
|
||
| <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"> | ||
| {[16, 17, 18, 19, 20].map(century => { | ||
| return ( | ||
| <SearchLink | ||
| key={century} | ||
| data-cy="century" | ||
| className={`button mr-1 ${centuries.includes(century.toString()) ? 'is-info' : ''}`} | ||
| params={{ centuries: toggledCenturies(century) }} | ||
| > | ||
| {century} | ||
| </SearchLink> | ||
| ); | ||
| })} | ||
| </div> | ||
|
|
||
| <div className="level-right ml-4"> | ||
| <SearchLink | ||
| data-cy="centuryALL" | ||
| className="button is-success is-outlined" | ||
| params={{ centuries: null }} | ||
| > | ||
| All | ||
| </SearchLink> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div className="panel-block"> | ||
| <SearchLink | ||
| className="button is-link is-outlined is-fullwidth" | ||
| params={{ sex: null, centuries: null, query: null }} | ||
| > | ||
| Reset all filters | ||
| </SearchLink> | ||
| </div> | ||
| </nav> | ||
| ); | ||
| }; |
This file was deleted.
This file was deleted.
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.
This link navigates to
/people/${person.slug}but does not include the current search params from the URL, so filters and sorting are lost when selecting a person. The description requires that search params be kept when selecting a person within the People page; consider usingSearchLinkoruseSearchParamsto construct atoobject that preserves the existing search string while changing only thepathname.