From 58f5a3b6c7fd05d4d203ca6cdcd8ce8aab3d658a Mon Sep 17 00:00:00 2001 From: Ahiya Elster Date: Sun, 13 Oct 2019 12:50:52 +0300 Subject: [PATCH 1/2] NavigationDrawer - slight refactor to use props consts, and two small functions --- app/components/NavDrawer.js | 96 +++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 41 deletions(-) diff --git a/app/components/NavDrawer.js b/app/components/NavDrawer.js index 4bb6f8b1..919e013c 100644 --- a/app/components/NavDrawer.js +++ b/app/components/NavDrawer.js @@ -52,13 +52,15 @@ class NavDrawer extends Component { } onResetHomeProfilePressed() { + const {tracker, actions} = this.props; + Alert.alert('Logout', 'Are you sure that you want to logout?', [ {text: 'Cancel', style: 'cancel'}, {text: 'OK', onPress: () => { - this.props.tracker.trackEvent('Logout', 'Success'); - this.props.actions.resetHomeProfile(); + tracker.trackEvent('Logout', 'Success'); + actions.resetHomeProfile(); setTimeout(() => { AsyncStorage.setItem("homeProfile", ""); }, 1000); @@ -67,21 +69,23 @@ class NavDrawer extends Component { } goto(route) { + const {actions, contextIdStackFavourite, contextIdStackHome, contextIdStackSearch} = this.props; + Actions.drawerClose(); - this.props.actions.changeParent(route); + actions.changeParent(route); if(route == 'Home') { - if(this.props.contextIdStackHome.length > 0) { - this.props.actions.changeContextId(this.props.contextIdStackHome[this.props.contextIdStackHome.length-1]); + if(contextIdStackHome.length > 0) { + actions.changeContextId(contextIdStackHome[contextIdStackHome.length-1]); } Actions.homeTab(); } else if(route == 'Favourites') { - if(this.props.contextIdStackFavourite.length > 0) { - this.props.actions.changeContextId(this.props.contextIdStackFavourite[this.props.contextIdStackFavourite.length-1]); + if(contextIdStackFavourite.length > 0) { + actions.changeContextId(contextIdStackFavourite[contextIdStackFavourite.length-1]); } Actions.favouriteTab(); } else if(route == 'Search') { - if(this.props.contextIdStackSearch.length > 0) { - this.props.actions.changeContextId(this.props.contextIdStackSearch[this.props.contextIdStackSearch.length-1]); + if(contextIdStackSearch.length > 0) { + actions.changeContextId(contextIdStackSearch[contextIdStackSearch.length-1]); } Actions.searchTab(); } else if(route == 'Settings') { @@ -89,87 +93,97 @@ class NavDrawer extends Component { } } - render() { - var paddingView; + getPaddingView = () => { if(Platform.OS === 'ios') { if(DeviceInfo.getModel() == "iPhone X") - paddingView = + return ; else - paddingView = + return ; } else { - paddingView = + return ; } - var logout = (); - if(this.props.profile != "") { - logout = ( + } + + getLogoutView = () => { + const { profile, mod, legend, secondLegend } = this.props; + + return (profile != "") ? {this.onResetHomeProfilePressed()}}> - + - + - Logout + Logout - + - ); - } + : + ; + } + + render() { + const { mod, legend, secondLegend } = this.props; + + const paddingView = this.getPaddingView(); + const logoutView = this.getLogoutView(); + return ( - + {paddingView} {this.goto('Home')}}> - + - + - Home + Home - + {this.goto('Favourites')}}> - + - + - Favourites + Favourites - + {this.goto('Search')}}> - + - + - Search + Search - + {this.goto('Settings')}}> - + - + - Settings + Settings - + - {logout} + {logoutView} From 8358745aa5761c1c3dfce74af557d2a531b97fd2 Mon Sep 17 00:00:00 2001 From: Ahiya Elster Date: Sun, 13 Oct 2019 16:12:18 +0300 Subject: [PATCH 2/2] refactored render method --- app/components/NavDrawer.js | 72 ++++++++++++------------------------- 1 file changed, 23 insertions(+), 49 deletions(-) diff --git a/app/components/NavDrawer.js b/app/components/NavDrawer.js index 919e013c..ab3e4a9d 100644 --- a/app/components/NavDrawer.js +++ b/app/components/NavDrawer.js @@ -106,9 +106,9 @@ class NavDrawer extends Component { getLogoutView = () => { const { profile, mod, legend, secondLegend } = this.props; - + return (profile != "") ? - + {this.onResetHomeProfilePressed()}}> @@ -123,68 +123,42 @@ class NavDrawer extends Component { : ; + } + + getMenuItem = (itemName, fontName) => { + const { mod, legend, secondLegend } = this.props; + + return {this.goto(itemName)}}> + + + + + + {itemName} + + + ; } render() { - const { mod, legend, secondLegend } = this.props; + const { mod, legend } = this.props; const paddingView = this.getPaddingView(); const logoutView = this.getLogoutView(); - + return ( {paddingView} - {this.goto('Home')}}> - - - - - - Home - - - + {this.getMenuItem("Home", "home")} - - {this.goto('Favourites')}}> - - - - - - Favourites - - - + {this.getMenuItem("Favourites", "star")} - - {this.goto('Search')}}> - - - - - - Search - - - + {this.getMenuItem("Search", "search")} - - {this.goto('Settings')}}> - - - - - - Settings - - - + {this.getMenuItem("Settings", "cog")} - {logoutView} - )