From d104d5702745d1f709712eb62ec6e2f427a1f4a0 Mon Sep 17 00:00:00 2001 From: Stanislaw Adaszewski Date: Tue, 4 Feb 2020 15:07:48 +0100 Subject: [PATCH] Adapted WBNavbar to handle URLs in addition to onclick callbacks. --- frontend/src/js/component/wb-navbar-common.js | 22 ++++++----- frontend/src/js/page/wb-app.js | 14 +++---- frontend/src/js/widget/wb-navbar.js | 37 +++++++++++++++---- 3 files changed, 47 insertions(+), 26 deletions(-) diff --git a/frontend/src/js/component/wb-navbar-common.js b/frontend/src/js/component/wb-navbar-common.js index c4b4cf3..3b6a09b 100644 --- a/frontend/src/js/component/wb-navbar-common.js +++ b/frontend/src/js/component/wb-navbar-common.js @@ -5,15 +5,19 @@ import WBInlineSearch from 'wb-inline-search'; class WBNavbarCommon extends Component { render({ app, items, activeItem }) { return ( - - ) } onItemClicked={ item => app.navbarItemClicked(item) } - activeItem={ activeItem } /> + + ) } + titleUrl = { '/browse/' + app.state.currentUser.uuid } + getItemUrl={ item => app.navbarItemUrl(item) } + activeItem={ activeItem } /> ); } } diff --git a/frontend/src/js/page/wb-app.js b/frontend/src/js/page/wb-app.js index f229443..a24eb7f 100644 --- a/frontend/src/js/page/wb-app.js +++ b/frontend/src/js/page/wb-app.js @@ -26,22 +26,18 @@ class WBApp extends Component { }; } - navbarItemClicked(item) { + navbarItemUrl(item) { if (item['id'] === 'sign-out') { delete window.localStorage['arvHost']; delete window.localStorage['arvToken']; delete window.localStorage['currentUser']; - route('/sign-in'); - + return ('/sign-in'); } else if (item['id'] === 'home') { - route('/browse/' + this.appState.currentUser.uuid); - + return ('/browse/' + this.appState.currentUser.uuid); } else if (item['id'] === 'all-projects') { - route('/browse'); - + return ('/browse'); } else if (item['id'] === 'all-users') { - route('/users'); - + return ('/users'); } } diff --git a/frontend/src/js/widget/wb-navbar.js b/frontend/src/js/widget/wb-navbar.js index b44686f..cbdef5c 100644 --- a/frontend/src/js/widget/wb-navbar.js +++ b/frontend/src/js/widget/wb-navbar.js @@ -1,10 +1,12 @@ import { h, Component } from 'preact'; class WBNavbar extends Component { - render({ title, items, rhs, onItemClicked, onTitleClicked, activeItem }) { + render({ title, items, rhs, onItemClicked, onTitleClicked, + activeItem, titleUrl, getItemUrl }) { + return ( ); } + + titleClicked(e) { + let { onTitleClicked } = this.props; + if (!onTitleClicked) + return; + e.preventDefault(); + onTitleClicked(); + } + + itemClicked(e, i) { + let { onItemClicked } = this.props; + if (!onItemClicked) + return; + e.preventDefault(); + onItemClicked(i); + } } WBNavbar.defaultProps = { 'title': 'Workbench Advanced', 'items': [], 'form': null, - 'onItemClicked': () => {}, - 'onTitleClicked': () => {}, - 'activeItem': null + 'activeItem': null, + 'titleUrl': '#', + 'getItemUrl': () => ('#') } export default WBNavbar;