Adds navigation tree to define the hierarchy
This commit is contained in:
+10
-6
@@ -10,7 +10,7 @@ import { getNavigation, navigate } from '../slices/navigation'
|
|||||||
|
|
||||||
import Header from './header'
|
import Header from './header'
|
||||||
import Menu from './menu'
|
import Menu from './menu'
|
||||||
import { pagesList, isSymptomView, isSettingsView } from './pages'
|
import { viewsList, isSymptomView, isSettingsView, pages } from './pages'
|
||||||
|
|
||||||
import { headerTitles } from '../i18n/en/labels'
|
import { headerTitles } from '../i18n/en/labels'
|
||||||
import setupNotifications from '../lib/notifications'
|
import setupNotifications from '../lib/notifications'
|
||||||
@@ -46,20 +46,24 @@ class App extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleBackButtonPress = () => {
|
handleBackButtonPress = () => {
|
||||||
const { current, prev } = this.props.navigation
|
const { currentPage } = this.props.navigation
|
||||||
if (current === 'Home') {
|
|
||||||
|
if (currentPage === 'Home') {
|
||||||
closeDb()
|
closeDb()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
this.props.navigate(prev)
|
|
||||||
|
const page = pages.find(item => item.component === currentPage)
|
||||||
|
this.props.navigate(page.parent)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { cycleDay } = this.state
|
const { cycleDay } = this.state
|
||||||
const currentPage = this.props.navigation.current
|
const { currentPage } = this.props.navigation
|
||||||
|
|
||||||
const Page = pagesList[currentPage]
|
const Page = viewsList[currentPage]
|
||||||
const title = headerTitles[currentPage]
|
const title = headerTitles[currentPage]
|
||||||
|
|
||||||
const isSymptomEditView = isSymptomView(currentPage)
|
const isSymptomEditView = isSymptomView(currentPage)
|
||||||
|
|||||||
@@ -7,20 +7,21 @@ import MenuItem from './menu-item'
|
|||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import { getNavigation, navigate } from '../../slices/navigation'
|
import { getNavigation, navigate } from '../../slices/navigation'
|
||||||
|
|
||||||
import { menuItems } from './menu-config'
|
import { pages } from '../pages'
|
||||||
|
|
||||||
import styles from '../../styles'
|
import styles from '../../styles'
|
||||||
|
|
||||||
const Menu = ({ navigation, navigate }) => {
|
const Menu = ({ navigate, navigation }) => {
|
||||||
|
const menuItems = pages.filter(page => page.isInMenu)
|
||||||
return (
|
return (
|
||||||
<View style={styles.menu}>
|
<View style={styles.menu}>
|
||||||
{ menuItems.map(({ icon, labelKey, component, children }) => {
|
{ menuItems.map(({ icon, label, component, children }) => {
|
||||||
const isActive = (component === navigation.current) ||
|
const isActive = (component === navigation.currentPage) ||
|
||||||
(children && children.indexOf(navigation.current) !== -1)
|
(children && children.indexOf(navigation.currentPage) !== -1)
|
||||||
return (
|
return (
|
||||||
<MenuItem
|
<MenuItem
|
||||||
key={labelKey}
|
key={label}
|
||||||
labelKey={labelKey}
|
label={label}
|
||||||
icon={icon}
|
icon={icon}
|
||||||
active={isActive}
|
active={isActive}
|
||||||
onPress={() => navigate(component)}
|
onPress={() => navigate(component)}
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
import settingsViews from '../settings'
|
|
||||||
|
|
||||||
export const menuItems = [
|
|
||||||
{
|
|
||||||
labelKey: 'Home',
|
|
||||||
icon: 'home',
|
|
||||||
component: 'Home',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
labelKey: 'Calendar',
|
|
||||||
icon: 'calendar-range',
|
|
||||||
component: 'Calendar',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
labelKey: 'Chart',
|
|
||||||
icon: 'chart-line',
|
|
||||||
component: 'Chart',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
labelKey: 'Stats',
|
|
||||||
icon: 'chart-pie',
|
|
||||||
component: 'Stats',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
labelKey: 'Settings',
|
|
||||||
icon: 'settings',
|
|
||||||
component: 'SettingsMenu',
|
|
||||||
children: Object.keys(settingsViews),
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@@ -11,7 +11,7 @@ const menuTitlesLowerCase = Object.keys(menuTitles).reduce((acc, curr) => {
|
|||||||
return acc
|
return acc
|
||||||
}, {})
|
}, {})
|
||||||
|
|
||||||
const MenuItem = ({ icon, labelKey, active, onPress }) => {
|
const MenuItem = ({ icon, label, active, onPress }) => {
|
||||||
const styleActive = active ? { color: secondaryColor } : null
|
const styleActive = active ? { color: secondaryColor } : null
|
||||||
return (
|
return (
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
@@ -20,10 +20,10 @@ const MenuItem = ({ icon, labelKey, active, onPress }) => {
|
|||||||
>
|
>
|
||||||
<Icon name={icon} {...iconStyles.menuIcon} {...styleActive} />
|
<Icon name={icon} {...iconStyles.menuIcon} {...styleActive} />
|
||||||
<Text
|
<Text
|
||||||
testID={active ? 'activeMenuItem' : `menuItem${labelKey}`}
|
testID={active ? 'activeMenuItem' : `menuItem${label}`}
|
||||||
style={[styles.menuText, styleActive]}
|
style={[styles.menuText, styleActive]}
|
||||||
>
|
>
|
||||||
{menuTitlesLowerCase[labelKey]}
|
{menuTitlesLowerCase[label]}
|
||||||
</Text>
|
</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
)
|
)
|
||||||
|
|||||||
+81
-1
@@ -7,7 +7,10 @@ import SettingsMenu from './settings/settings-menu'
|
|||||||
import settingsViews from './settings'
|
import settingsViews from './settings'
|
||||||
import Stats from './stats'
|
import Stats from './stats'
|
||||||
|
|
||||||
export const pagesList = {
|
import settingsLabels from '../i18n/en/settings'
|
||||||
|
const labels = settingsLabels.menuTitles
|
||||||
|
|
||||||
|
export const viewsList = {
|
||||||
Home,
|
Home,
|
||||||
Calendar,
|
Calendar,
|
||||||
CycleDay,
|
CycleDay,
|
||||||
@@ -23,3 +26,80 @@ export const isSymptomView =
|
|||||||
|
|
||||||
export const isSettingsView =
|
export const isSettingsView =
|
||||||
(page) => Object.keys(settingsViews).includes(page)
|
(page) => Object.keys(settingsViews).includes(page)
|
||||||
|
|
||||||
|
const symptomsPages = Object.keys(symptomViews).map(symptomView => ({
|
||||||
|
component: symptomView, parent: 'CycleDay',
|
||||||
|
}))
|
||||||
|
|
||||||
|
export const pages = [
|
||||||
|
{
|
||||||
|
component: 'Home',
|
||||||
|
icon: 'home',
|
||||||
|
isInMenu: true,
|
||||||
|
label: 'Home',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'Calendar',
|
||||||
|
icon: 'calendar-range',
|
||||||
|
isInMenu: true,
|
||||||
|
label: 'Calendar',
|
||||||
|
parent: 'Home',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'Chart',
|
||||||
|
icon: 'chart-line',
|
||||||
|
isInMenu: true,
|
||||||
|
label: 'Chart',
|
||||||
|
parent: 'Home',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'Stats',
|
||||||
|
icon: 'chart-pie',
|
||||||
|
isInMenu: true,
|
||||||
|
label: 'Stats',
|
||||||
|
parent: 'Home',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
children: Object.keys(settingsViews),
|
||||||
|
component: 'SettingsMenu',
|
||||||
|
icon: 'settings',
|
||||||
|
isInMenu: true,
|
||||||
|
label: 'Settings',
|
||||||
|
parent: 'Home',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'Reminders',
|
||||||
|
label: labels.reminders,
|
||||||
|
parent: 'SettingsMenu',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'NfpSettings',
|
||||||
|
label: labels.nfpSettings,
|
||||||
|
parent: 'SettingsMenu',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'DataManagement',
|
||||||
|
label: labels.dataManagement,
|
||||||
|
parent: 'SettingsMenu',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'Password',
|
||||||
|
label: labels.password,
|
||||||
|
parent: 'SettingsMenu',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'About',
|
||||||
|
label: labels.about,
|
||||||
|
parent: 'SettingsMenu',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'License',
|
||||||
|
label: labels.license,
|
||||||
|
parent: 'SettingsMenu',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'CycleDay',
|
||||||
|
parent: 'Home',
|
||||||
|
},
|
||||||
|
...symptomsPages
|
||||||
|
]
|
||||||
@@ -3,14 +3,12 @@ import { createSlice } from 'redux-starter-kit'
|
|||||||
const navigationSlice = createSlice({
|
const navigationSlice = createSlice({
|
||||||
slice: 'navigation',
|
slice: 'navigation',
|
||||||
initialState: {
|
initialState: {
|
||||||
current: 'Home',
|
currentPage: 'Home',
|
||||||
prev: null,
|
|
||||||
},
|
},
|
||||||
reducers: {
|
reducers: {
|
||||||
navigate: (state, action) => {
|
navigate: (state, action) => {
|
||||||
return {
|
return {
|
||||||
current: action.payload,
|
currentPage: action.payload,
|
||||||
prev: state.current
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user