Files
notesnook/apps/mobile/src/components/Menu/index.js

406 lines
10 KiB
JavaScript
Raw Normal View History

2019-12-21 11:12:55 +05:00
import React from 'react';
2019-12-04 11:40:59 +05:00
import {
2020-01-18 01:04:33 +05:00
Platform,
2019-12-04 11:40:59 +05:00
ScrollView,
2020-01-18 01:04:33 +05:00
StatusBar,
2019-12-04 11:40:59 +05:00
Text,
TouchableOpacity,
2020-01-18 01:04:33 +05:00
View,
2019-12-04 11:40:59 +05:00
} from 'react-native';
2020-01-18 01:04:33 +05:00
import FastStorage from 'react-native-fast-storage';
import Icon from 'react-native-vector-icons/Feather';
2019-12-04 11:40:59 +05:00
import {
2020-01-17 21:06:15 +05:00
ACCENT,
COLOR_SCHEME,
2020-01-18 01:04:33 +05:00
COLOR_SCHEME_DARK,
COLOR_SCHEME_LIGHT,
opacity,
pv,
2020-01-17 21:06:15 +05:00
setColorScheme,
2020-01-18 01:04:33 +05:00
SIZE,
WEIGHT,
2019-12-04 11:40:59 +05:00
} from '../../common/common';
2020-01-18 01:04:33 +05:00
import {ACTIONS, useTracked} from '../../provider';
import NavigationService from '../../services/NavigationService';
import {AnimatedSafeAreaView} from '../../views/Home';
2020-01-17 21:06:15 +05:00
2019-12-07 12:05:15 +05:00
export const Menu = ({close = () => {}, hide, update = () => {}}) => {
2020-01-17 21:26:01 +05:00
const [state, dispatch] = useTracked();
const {colors} = state;
2020-01-17 00:23:16 +05:00
// todo
2020-01-17 21:06:15 +05:00
function changeColorScheme(colors = COLOR_SCHEME, accent = ACCENT) {
let newColors = setColorScheme(colors, accent);
StatusBar.setBarStyle(newColors.night ? 'light-content' : 'dark-content');
dispatch({type: ACTIONS.THEME, colors: newColors});
}
2019-12-07 12:05:15 +05:00
const listItems = [
{
name: 'Home',
icon: 'home',
2020-01-18 00:46:09 +05:00
func: () => NavigationService.navigate('Home'),
close: true,
},
{
name: 'Notebooks',
icon: 'book',
func: () =>
2020-01-18 00:46:09 +05:00
NavigationService.navigate('Folders', {
title: 'Notebooks',
canGoBack: false,
}),
close: true,
},
{
name: 'Lists',
icon: 'list',
2020-01-18 00:46:09 +05:00
func: () => NavigationService.navigate('Lists'),
close: true,
},
{
name: 'Favorites',
icon: 'star',
2020-01-18 00:46:09 +05:00
func: () => NavigationService.navigate('Favorites'),
close: true,
},
{
name: 'Dark Mode',
icon: 'moon',
func: () => {
if (!colors.night) {
2020-01-14 20:48:03 +05:00
FastStorage.setItem('theme', JSON.stringify({night: true}));
changeColorScheme(COLOR_SCHEME_DARK);
} else {
2020-01-14 20:48:03 +05:00
FastStorage.setItem('theme', JSON.stringify({night: false}));
changeColorScheme(COLOR_SCHEME_LIGHT);
}
},
switch: true,
on: colors.night ? true : false,
close: false,
},
{
name: 'Trash',
icon: 'trash',
2020-01-18 00:46:09 +05:00
func: () => NavigationService.navigate('Trash'),
close: true,
},
{
name: 'Settings',
icon: 'settings',
2020-01-18 00:46:09 +05:00
func: () => NavigationService.navigate('Settings'),
close: true,
},
];
2019-12-07 12:05:15 +05:00
return (
<AnimatedSafeAreaView
transition="backgroundColor"
2020-01-08 11:53:38 +05:00
duration={400}
2019-12-07 12:05:15 +05:00
style={{
2019-12-04 11:40:59 +05:00
height: '100%',
2019-12-07 12:05:15 +05:00
opacity: hide ? 0 : 1,
2019-12-21 10:38:40 +05:00
backgroundColor: colors.shade,
2019-12-04 11:40:59 +05:00
}}>
2019-12-10 22:03:39 +05:00
<View
style={{
height: 2,
width: '100%',
marginBottom: 5,
marginTop: Platform.OS == 'ios' ? 0 : StatusBar.currentHeight - 10,
2019-12-10 22:03:39 +05:00
}}
/>
2019-12-14 16:00:16 +05:00
2019-12-07 12:05:15 +05:00
<ScrollView
2020-01-09 19:49:06 +05:00
contentContainerStyle={{minHeight: '80%'}}
2020-01-08 11:53:38 +05:00
showsVerticalScrollIndicator={false}>
2019-12-07 12:05:15 +05:00
<View>
<View>
{listItems.map(item => (
2019-12-07 12:05:15 +05:00
<TouchableOpacity
key={item.name}
2020-01-07 16:26:30 +05:00
activeOpacity={opacity / 2}
2019-12-07 12:05:15 +05:00
onPress={() => {
item.close === false ? null : close();
2019-12-11 01:10:04 +05:00
2019-12-07 12:05:15 +05:00
item.func();
}}
2019-12-04 11:40:59 +05:00
style={{
2019-12-07 12:05:15 +05:00
width: '100%',
alignSelf: 'center',
2019-12-04 11:40:59 +05:00
flexDirection: 'row',
2019-12-07 12:05:15 +05:00
justifyContent: 'space-between',
2019-12-14 16:00:16 +05:00
alignItems: 'center',
paddingHorizontal: '5%',
2019-12-14 16:00:16 +05:00
paddingVertical: pv + 5,
2019-12-04 11:40:59 +05:00
}}>
2019-12-07 12:05:15 +05:00
<View
2019-12-04 11:40:59 +05:00
style={{
2019-12-07 12:05:15 +05:00
flexDirection: 'row',
2019-12-14 16:00:16 +05:00
alignItems: 'center',
2019-12-04 11:40:59 +05:00
}}>
2019-12-07 12:05:15 +05:00
<Icon
style={{
width: 30,
}}
name={item.icon}
2019-12-21 10:38:40 +05:00
color={colors.pri}
2019-12-07 12:05:15 +05:00
size={SIZE.md}
/>
<Text
style={{
2019-12-14 16:00:16 +05:00
fontFamily: WEIGHT.regular,
fontSize: SIZE.sm,
2019-12-07 12:05:15 +05:00
color: colors.pri,
}}>
{item.name}
</Text>
</View>
{item.switch ? (
<Icon
size={SIZE.lg}
color={item.on ? colors.accent : colors.icon}
name={item.on ? 'toggle-right' : 'toggle-left'}
/>
) : (
undefined
)}
</TouchableOpacity>
))}
</View>
2019-12-04 11:40:59 +05:00
2019-12-07 12:05:15 +05:00
<TouchableOpacity
2020-01-07 16:26:30 +05:00
activeOpacity={opacity / 2}
2019-12-07 12:05:15 +05:00
onPress={() => {
close();
NavigationService.navigate('Tags');
}}
2019-12-04 11:40:59 +05:00
style={{
2019-12-07 12:05:15 +05:00
width: '100%',
alignSelf: 'center',
2019-12-04 11:40:59 +05:00
flexDirection: 'row',
2019-12-07 12:05:15 +05:00
justifyContent: 'space-between',
2019-12-04 11:40:59 +05:00
alignItems: 'flex-end',
paddingHorizontal: '5%',
2019-12-07 12:05:15 +05:00
marginTop: 15,
2019-12-04 11:40:59 +05:00
}}>
2019-12-07 12:05:15 +05:00
<View
2019-12-04 11:40:59 +05:00
style={{
flexDirection: 'row',
justifyContent: 'flex-start',
2019-12-14 16:00:16 +05:00
alignItems: 'center',
2019-12-04 11:40:59 +05:00
}}>
2019-12-07 12:05:15 +05:00
<Icon
style={{
width: 30,
}}
name="tag"
2019-12-21 11:12:55 +05:00
color={colors.pri}
2019-12-07 12:05:15 +05:00
size={SIZE.md}
/>
2019-12-04 11:40:59 +05:00
<Text
style={{
2019-12-14 16:00:16 +05:00
fontFamily: WEIGHT.regular,
fontSize: SIZE.sm,
2019-12-07 12:05:15 +05:00
color: colors.pri,
2019-12-04 11:40:59 +05:00
}}>
2019-12-07 12:05:15 +05:00
Tags
2019-12-04 11:40:59 +05:00
</Text>
2019-12-07 12:05:15 +05:00
</View>
</TouchableOpacity>
2019-12-04 11:40:59 +05:00
2020-01-08 11:53:38 +05:00
<View
style={{
2019-12-07 12:05:15 +05:00
flexDirection: 'row',
flexWrap: 'wrap',
paddingHorizontal: '5%',
marginBottom: 0,
}}>
{[
'home',
'office',
'work',
'book_notes',
'poem',
'lists',
'water',
].map(item => (
2019-12-04 11:40:59 +05:00
<TouchableOpacity
key={item}
2020-01-07 16:26:30 +05:00
activeOpacity={opacity / 2}
2019-12-07 12:05:15 +05:00
onPress={() => {
close();
NavigationService.navigate('Notes', {
heading: item,
});
}}
2019-12-04 11:40:59 +05:00
style={{
flexDirection: 'row',
justifyContent: 'flex-start',
alignItems: 'center',
2019-12-14 16:00:16 +05:00
padding: 7,
paddingLeft: 3.5,
2019-12-04 11:40:59 +05:00
}}>
2019-12-07 12:05:15 +05:00
<Text
2019-12-04 11:40:59 +05:00
style={{
2019-12-07 12:05:15 +05:00
fontFamily: WEIGHT.regular,
2020-01-01 00:04:59 +05:00
fontSize: SIZE.xs + 1,
2019-12-07 12:05:15 +05:00
color: colors.icon,
}}>
#{item}
</Text>
2019-12-04 11:40:59 +05:00
</TouchableOpacity>
2019-12-07 12:05:15 +05:00
))}
2020-01-08 11:53:38 +05:00
</View>
2019-12-04 11:40:59 +05:00
2020-01-08 11:53:38 +05:00
<View
style={{
2019-12-04 11:40:59 +05:00
flexDirection: 'row',
2019-12-07 12:05:15 +05:00
flexWrap: 'wrap',
paddingHorizontal: '5%',
marginBottom: 15,
2019-12-04 11:40:59 +05:00
}}>
2019-12-07 12:05:15 +05:00
{['red', 'yellow', 'green', 'blue', 'purple', 'orange', 'gray'].map(
item => (
<TouchableOpacity
key={item}
2020-01-07 16:26:30 +05:00
activeOpacity={opacity / 2}
2019-12-07 12:05:15 +05:00
style={{
flexDirection: 'row',
justifyContent: 'flex-start',
alignItems: 'center',
margin: 5,
}}>
<View
style={{
2019-12-14 16:00:16 +05:00
width: 35,
height: 35,
2019-12-07 12:05:15 +05:00
backgroundColor: item,
borderRadius: 100,
}}
/>
</TouchableOpacity>
),
)}
2020-01-08 11:53:38 +05:00
</View>
2019-12-07 12:05:15 +05:00
</View>
2019-12-04 11:40:59 +05:00
2019-12-07 12:05:15 +05:00
{/* <View
2019-12-04 11:40:59 +05:00
style={{
2019-12-07 12:05:15 +05:00
backgroundColor: '#F3A712',
width: '90%',
alignSelf: 'center',
2019-12-04 11:40:59 +05:00
borderRadius: 5,
2019-12-07 12:05:15 +05:00
flexDirection: 'row',
justifyContent: 'space-between',
2019-12-04 11:40:59 +05:00
alignItems: 'center',
2019-12-07 12:05:15 +05:00
height: 40,
paddingHorizontal: ph,
marginVertical: 10,
2019-12-04 11:40:59 +05:00
}}>
<Text
style={{
fontFamily: WEIGHT.medium,
color: 'white',
}}>
2019-12-07 12:05:15 +05:00
Upgrade to Pro
2019-12-04 11:40:59 +05:00
</Text>
2019-12-07 12:05:15 +05:00
<View
style={{
...getElevation(5),
paddingHorizontal: ph,
backgroundColor: 'white',
paddingVertical: pv - 8,
borderRadius: 5,
}}>
<Icon name="star" color="#FCBA04" size={SIZE.lg} />
</View>
</View> */}
2020-01-08 11:53:38 +05:00
</ScrollView>
<View
style={{
width: '100%',
justifyContent: 'space-between',
alignItems: 'center',
alignSelf: 'center',
marginBottom: 20,
flexDirection: 'row',
backgroundColor: colors.bg,
}}>
<TouchableOpacity
onPress={() => {
close();
2019-12-04 11:40:59 +05:00
2020-01-08 11:53:38 +05:00
NavigationService.navigate('Login');
}}
activeOpacity={opacity / 2}
2019-12-04 11:40:59 +05:00
style={{
2020-01-08 11:53:38 +05:00
paddingVertical: pv + 5,
2019-12-07 12:05:15 +05:00
paddingHorizontal: '5%',
2020-01-08 11:53:38 +05:00
backgroundColor: colors.shade,
width: '100%',
justifyContent: 'flex-start',
2019-12-07 12:05:15 +05:00
alignItems: 'center',
flexDirection: 'row',
2019-12-04 11:40:59 +05:00
}}>
2020-01-08 11:53:38 +05:00
<Icon name="log-in" color={colors.accent} size={SIZE.lg} />
2019-12-07 12:05:15 +05:00
2020-01-08 11:53:38 +05:00
<Text
2019-12-04 11:40:59 +05:00
style={{
2020-01-08 11:53:38 +05:00
fontFamily: WEIGHT.regular,
color: colors.accent,
fontSize: SIZE.md,
2019-12-04 11:40:59 +05:00
}}>
2020-01-08 11:53:38 +05:00
{' '}Login
</Text>
</TouchableOpacity>
2019-12-07 12:05:15 +05:00
2020-01-08 11:53:38 +05:00
{/* <Text
2019-12-07 12:05:15 +05:00
style={{
fontFamily: WEIGHT.semibold,
color: colors.accent,
fontSize: SIZE.md,
marginTop: 10,
}}>
Hi, Ammar!
</Text>
<Text
style={{
fontFamily: WEIGHT.regular,
color: colors.accent,
fontSize: SIZE.xs,
marginTop: 10,
}}>
80.45/100 MB
</Text> */}
2020-01-08 11:53:38 +05:00
{/* <View
2019-12-07 12:05:15 +05:00
style={{
borderRadius: 2.5,
backgroundColor: colors.accent,
marginTop: 10,
paddingHorizontal: 5,
paddingVertical: 2,
}}>
<Text
style={{
fontFamily: WEIGHT.bold,
fontSize: SIZE.xxs,
color: 'white',
}}>
Basic User
</Text>
</View> */}
2020-01-08 11:53:38 +05:00
</View>
</AnimatedSafeAreaView>
2019-12-07 12:05:15 +05:00
);
};