Skip to content

Commit 6d5c8e4

Browse files
committed
Breadcrumbified the navbar
1 parent 7c8e3b1 commit 6d5c8e4

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

TODO.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ My personal remaining TODO.
66
- In the ReadMe, explain what changes might be needed if this app were intended to be run in a "concurrent" environment.
77

88
## Bonus:
9-
- *Change debug navbar into breadcrumb that remembers search term while viewing Pokémon (and update the readme to reflect this (#Design))*
109
- *When visiting a search page, add it to the search history. (useful for when people visit from a bookmark)*
1110
- *Make it so that pressing the down arrow while the search history dropdown is open will move the focus into the dropdown*
1211
- *Allow the user to remove history entries with an "X" button, like exists in the searchbar*

frontend/app/src/layout/nav.tsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,39 @@
1-
import {FunctionComponent} from 'react';
1+
import {useAppSelector} from '@/redux/hooks.ts';
2+
import {Fragment, FunctionComponent} from 'react';
23
import {Link, useLocation} from 'react-router-dom';
34

45
////////////////////////////////////////////////////////////////////////////////
56
//TODO: Make `Nav` into a breadcrumb, rather than just a tool for debugging.
67
export const Nav: FunctionComponent = () => {
78
const location = useLocation();
9+
const history = useAppSelector(state => state.search.history);
810

911
// // // // // // // // // // // // // // // // // // // //
1012
const entries: Array<{
1113
name: string,
1214
path: string,
15+
args?: string,
1316
}> = [{
1417
name: 'Home',
1518
path: '/',
1619
}, {
1720
name: 'Search',
1821
path: '/search',
22+
args: `?q=${history[0]}`,
1923
}, {
2024
name: 'Pokémon',
2125
path: '/pokemon',
22-
}, {
23-
name: '404',
24-
path: '/error',
2526
}];
2627

2728
// // // // // // // // // // // // // // // // // // // //
2829
return (
29-
<nav style={{display: 'none'}}>
30+
<nav>
3031
<ul>{
31-
entries.map((entry, index) =>
32-
<li key={index}>{
33-
entry.path !== location.pathname
34-
? <Link to={entry.path}>{entry.name}</Link>
35-
: <a className="activated">{entry.name}</a>
36-
}</li>
37-
)
32+
entries.map((entry, index) => <Fragment key={index}>{
33+
entry.path !== location.pathname
34+
? <li><Link to={entry.path + (entry.args ?? '')}>{entry.name}</Link></li>
35+
: <li className="hide-following"><a className="activated">{entry.name}</a></li>
36+
}</Fragment>)
3837
}</ul>
3938
</nav>
4039
);

frontend/app/src/styles/elements/_layout.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ nav {
9393
display: block;
9494
@include button($color-nav-background);
9595
border-radius: unset;
96+
9697
}
9798
}
9899
}

frontend/app/src/styles/utilities/_overrides.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
.error {
55
color: $color-error;
66
}
7+
.hide-following ~* {
8+
display: none;
9+
}
710
.raw-data {
811
font-family: $font-mono;
912
}

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pokedex",
3-
"version": "1.1.1",
3+
"version": "1.2.0",
44
"license": "LAGPL-3.0-or-later",
55
"description": "A web application that displays data on Pokémon®. Not affiliated with Nintendo®.",
66
"keywords": [

0 commit comments

Comments
 (0)