From e1905f928d9f16857aca49378e4e896beb992660 Mon Sep 17 00:00:00 2001 From: NikolaBorislavovHristov Date: Wed, 18 Dec 2019 16:47:07 +0200 Subject: [PATCH] NavTabButton selected by bool prop instead of match against location hash --- src/common/MainNavBar/MainNavBar.js | 18 ++++++++++++------ src/common/NavBar/NavBar.js | 6 ++++-- .../NavBar/NavTabButton/NavTabButton.js | 19 +++---------------- src/common/NavBar/NavTabButton/styles.less | 2 +- src/routes/Board/Board.js | 2 +- src/routes/Discover/Discover.js | 2 +- src/routes/Library/Library.js | 2 +- 7 files changed, 23 insertions(+), 28 deletions(-) diff --git a/src/common/MainNavBar/MainNavBar.js b/src/common/MainNavBar/MainNavBar.js index 507f8d229..55bdce638 100644 --- a/src/common/MainNavBar/MainNavBar.js +++ b/src/common/MainNavBar/MainNavBar.js @@ -3,17 +3,22 @@ const PropTypes = require('prop-types'); const NavBar = require('stremio/common/NavBar'); const TABS = [ - { label: 'Board', icon: 'ic_board', href: '#/' }, - { label: 'Discover', icon: 'ic_discover', href: '#/discover' }, - { label: 'Library', icon: 'ic_library', href: '#/library' } + { id: 'board', label: 'Board', icon: 'ic_board', href: '#/' }, + { id: 'discover', label: 'Discover', icon: 'ic_discover', href: '#/discover' }, + { id: 'library', label: 'Library', icon: 'ic_library', href: '#/library' } ]; -const MainNavBar = React.memo(({ className }) => { +const MainNavBar = React.memo(({ className, selected }) => { return ( ({ + label, + icon, + href, + selected: id === selected + }))} searchBar={true} addonsButton={true} fullscreenButton={true} @@ -26,7 +31,8 @@ const MainNavBar = React.memo(({ className }) => { MainNavBar.displayName = 'MainNavBar'; MainNavBar.propTypes = { - className: PropTypes.string + className: PropTypes.string, + selected: PropTypes.string }; module.exports = MainNavBar; diff --git a/src/common/NavBar/NavBar.js b/src/common/NavBar/NavBar.js index 92663af21..6fe9859ed 100644 --- a/src/common/NavBar/NavBar.js +++ b/src/common/NavBar/NavBar.js @@ -28,13 +28,14 @@ const NavBar = React.memo(({ className, backButton, tabs, title, searchBar, addo } { Array.isArray(tabs) && tabs.length > 0 ? - tabs.slice(0, 4).map(({ href = '', icon = '', label = '', onClick }) => ( + tabs.slice(0, 4).map(({ href, icon, label, selected, onClick }, index) => ( )) @@ -88,6 +89,7 @@ NavBar.propTypes = { icon: PropTypes.string, label: PropTypes.string, href: PropTypes.string, + selected: PropTypes.bool, onClick: PropTypes.func })), title: PropTypes.string, diff --git a/src/common/NavBar/NavTabButton/NavTabButton.js b/src/common/NavBar/NavTabButton/NavTabButton.js index 3af4bd7fb..7a525b868 100644 --- a/src/common/NavBar/NavTabButton/NavTabButton.js +++ b/src/common/NavBar/NavTabButton/NavTabButton.js @@ -3,25 +3,11 @@ const PropTypes = require('prop-types'); const classnames = require('classnames'); const Icon = require('stremio-icons/dom'); const Button = require('stremio/common/Button'); -const routesRegexp = require('stremio/common/routesRegexp'); -const useRouteActive = require('stremio/common/useRouteActive'); const styles = require('./styles'); -const NavTabButton = ({ className, icon, label, href, onClick }) => { - const routeRegexp = React.useMemo(() => { - if (typeof href === 'string' && href.startsWith('#')) { - for (const { regexp } of Object.values(routesRegexp)) { - if (href.slice(1).match(regexp)) { - return regexp; - } - } - } - - return null; - }, [href]); - const routeActive = useRouteActive(routeRegexp); +const NavTabButton = ({ className, icon, label, href, selected, onClick }) => { return ( -