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

Initial solution #1110

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
21 changes: 16 additions & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { PeoplePage } from './components/PeoplePage';
import { Navbar } from './components/Navbar';
import { PeoplePage } from './components/PeoplePage/PeoplePage';
import { Navbar } from './components/Navbar/Navbar';

import './App.scss';
import { Navigate, Route, Routes } from 'react-router-dom';
import { HomePage } from './components/HomePage';
import { PageNotFound } from './components/PageNotFound';

export const App = () => {
return (
Expand All @@ -10,9 +13,17 @@ export const App = () => {

<div className="section">
<div className="container">
<h1 className="title">Home Page</h1>
<h1 className="title">Page not found</h1>
<PeoplePage />
<Routes>
<Route path="/">
<Route index element={<HomePage />} />
<Route path="/home" element={<Navigate to="/" replace />} />
<Route path="/people" element={<PeoplePage />}>
<Route index />
<Route path=":personSlug?" />
</Route>
<Route path="*" element={<PageNotFound />} />
</Route>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create an enum for paths

</Routes>
</div>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/components/HomePage/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>;
};
1 change: 1 addition & 0 deletions src/components/HomePage/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './HomePage';
26 changes: 0 additions & 26 deletions src/components/Navbar.tsx

This file was deleted.

40 changes: 40 additions & 0 deletions src/components/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import cn from 'classnames';
import { NavLink } from 'react-router-dom';

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">
<NavLink
className={({ isActive }) => {
return cn('navbar-item', {
'has-background-grey-lighter': isActive,
});
}}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
className={({ isActive }) => {
return cn('navbar-item', {
'has-background-grey-lighter': isActive,
});
}}
className={({ isActive }) =>
cn('navbar-item', { 'has-background-grey-lighter': isActive })
}

to="/"
>
Home
</NavLink>

<NavLink
aria-current="page"
className={({ isActive }) => {
return cn('navbar-item', {
'has-background-grey-lighter': isActive,
});
}}
to="/people"
>
People
</NavLink>
</div>
</div>
</nav>
);
};
1 change: 1 addition & 0 deletions src/components/Navbar/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Navbar';
3 changes: 3 additions & 0 deletions src/components/PageNotFound/PageNotFound.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const PageNotFound = () => {
return <h1 className="title">Page not found</h1>;
};
1 change: 1 addition & 0 deletions src/components/PageNotFound/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './PageNotFound';
96 changes: 0 additions & 96 deletions src/components/PeopleFilters.tsx

This file was deleted.

99 changes: 99 additions & 0 deletions src/components/PeopleFilters/PeopleFilters.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import cn from 'classnames';
import { SearchLink } from '../SearchLink';
import { useFilters } from '../../hooks/useFilters';
import { CENTURIES } from '../../constants/CENTURIES';

export const PeopleFilters = () => {
const { sex, query, centuries, handleSetQuery, getCenturiesParams } =
useFilters();

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

<p className="panel-tabs" data-cy="SexFilter">
<SearchLink
className={cn({ 'is-active': sex === null })}
params={{ sex: null }}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can create an enum for sex values

>
All
</SearchLink>
<SearchLink
className={cn({ 'is-active': sex === 'm' })}
params={{ sex: 'm' }}
>
Male
</SearchLink>
<SearchLink
className={cn({ 'is-active': sex === 'f' })}
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={event => {
handleSetQuery(event.target.value);
}}
/>

<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">
{CENTURIES.map(century => (
<SearchLink
key={century}
data-cy="century"
params={{
centuries: getCenturiesParams(century),
}}
className={cn('button mr-1', {
'is-info': centuries.includes(century),
})}
>
{century}
</SearchLink>
))}
</div>

<div className="level-right ml-4">
<SearchLink
data-cy="centuryALL"
className={cn('button is-success', {
'is-outlined': centuries.length !== 0,
})}
params={{ centuries: null }}
>
All
</SearchLink>
</div>
</div>
</div>

<div className="panel-block">
<SearchLink
className={cn('button is-link is-outlined is-fullwidth', {
'is-outlined': sex === null && !centuries.length && query === '',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a variable for these conditions checks

})}
params={{ sex: null, centuries: null, query: null }}
>
Reset all filters
</SearchLink>
</div>
</nav>
);
};
1 change: 1 addition & 0 deletions src/components/PeopleFilters/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './PeopleFilters';
33 changes: 0 additions & 33 deletions src/components/PeoplePage.tsx

This file was deleted.

50 changes: 50 additions & 0 deletions src/components/PeoplePage/PeoplePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Loader } from '../Loader';
import { PeopleFilters } from '../PeopleFilters';
import { PeopleTable } from '../PeopleTable';

import { usePeople } from '../../hooks/usePeople';

export const PeoplePage = () => {
const { people, error, loading, filteredPeople } = usePeople();

const succesfullyLoadedStatus = !!people.length && !loading;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

succesfullyLoadedStatus is descriptive but a bit verbose. Consider renaming it to isLoaded for simplicity.

const isNoFilteredPeople = !filteredPeople.length && succesfullyLoadedStatus;

return (
<>
<h1 className="title">People Page</h1>

<div className="block">
<div className="columns is-desktop is-flex-direction-row-reverse">
<div className="column is-7-tablet is-narrow-desktop">
{succesfullyLoadedStatus && <PeopleFilters />}
</div>

<div className="column">
<div className="box table-container">
{loading && <Loader />}

{error && (
<p data-cy="peopleLoadingError">Something went wrong</p>
)}

{!people.length && !error && !loading && (
<p data-cy="noPeopleMessage">
There are no people on the server
</p>
)}

{isNoFilteredPeople && (
<p>There are no people matching the current search criteria</p>
)}

{succesfullyLoadedStatus && (
<PeopleTable visiblePeople={filteredPeople} />
)}
</div>
</div>
</div>
</div>
</>
);
};
Loading
Loading