some cleanup on login page

This commit is contained in:
ammarahm-ed
2020-09-09 16:04:26 +05:00
parent a6238eacc4
commit 2fa5915b66
4 changed files with 99 additions and 131 deletions

View File

@@ -1,13 +1,12 @@
import React from 'react'; import React from 'react';
import {Text, TouchableOpacity, View} from 'react-native'; import { Text, TouchableOpacity, View } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {ph, pv, SIZE, WEIGHT} from '../../common/common'; import { ph, pv, SIZE, WEIGHT } from '../../common/common';
import {useTracked} from '../../provider'; import { useTracked } from '../../provider';
import {ACTIONS} from '../../provider/actions'; import { ACTIONS } from '../../provider/actions';
import NavigationService from '../../services/NavigationService'; import { db, ToastEvent } from '../../utils/utils';
import {db, ToastEvent} from '../../utils/utils'; import { Button } from '../Button';
import {Button} from '../Button'; import { ActionSheetEvent, moveNoteHideEvent } from '../DialogManager/recievers';
import {ActionSheetEvent, moveNoteHideEvent} from '../DialogManager/recievers';
import Seperator from '../Seperator'; import Seperator from '../Seperator';
export const NotebookItem = ({ export const NotebookItem = ({

View File

@@ -22,7 +22,7 @@ export function validatePass(password) {
} }
export function validateUsername(username) { export function validateUsername(username) {
let regex = /^[a-z0-9_-]{3,16}$/gim; let regex = /^[a-z0-9_-]{3,200}$/gim;
if (username && username.length > 0) { if (username && username.length > 0) {
return regex.test(username); return regex.test(username);
} else { } else {

View File

@@ -1,16 +1,30 @@
import { useIsFocused } from '@react-navigation/native'; import {useIsFocused} from '@react-navigation/native';
import React, { createRef, useEffect, useState } from 'react'; import React, {createRef, useEffect, useState} from 'react';
import { ActivityIndicator, BackHandler, Text, TouchableOpacity, View } from 'react-native'; import {
ActivityIndicator,
BackHandler,
Text,
TouchableOpacity,
View,
} from 'react-native';
import * as Animatable from 'react-native-animatable'; import * as Animatable from 'react-native-animatable';
import { TextInput } from 'react-native-gesture-handler'; import {TextInput} from 'react-native-gesture-handler';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { opacity, pv, SIZE, WEIGHT } from '../../common/common'; import {opacity, pv, SIZE, WEIGHT} from '../../common/common';
import { useTracked } from '../../provider'; import {useTracked} from '../../provider';
import { ACTIONS } from '../../provider/actions'; import {ACTIONS} from '../../provider/actions';
import { eSendEvent } from '../../services/eventManager'; import {eSendEvent} from '../../services/eventManager';
import { eCloseSideMenu, eOpenSideMenu, eSetModalNavigator, eStartSyncer, refreshNotesPage } from '../../services/events'; import {
import { validatePass, validateUsername } from '../../services/validation'; eCloseSideMenu,
import { db, DDS, getElevation, ToastEvent } from '../../utils/utils'; eOpenSideMenu,
eSetModalNavigator,
eStartSyncer,
refreshNotesPage,
} from '../../services/events';
import {validatePass, validateUsername} from '../../services/validation';
import {db, DDS, getElevation, ToastEvent} from '../../utils/utils';
import {Button} from '../../components/Button';
import Seperator from '../../components/Seperator';
export const Login = ({route, navigation}) => { export const Login = ({route, navigation}) => {
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();
@@ -75,12 +89,10 @@ export const Login = ({route, navigation}) => {
_pass.current.blur(); _pass.current.blur();
setStatus('Logging in...'); setStatus('Logging in...');
try { try {
let res = await db.user.login(username.toLowerCase(), password); let res = await db.user.login(username.toLowerCase(), password);
console.log(res,username,password); console.log(res, username, password);
if (res) { if (res) {
setStatus('Fetching data...'); setStatus('Fetching data...');
} }
} catch (e) { } catch (e) {
@@ -225,34 +237,13 @@ export const Login = ({route, navigation}) => {
justifyContent: DDS.isTab ? 'center' : 'space-between', justifyContent: DDS.isTab ? 'center' : 'space-between',
width: DDS.isTab ? '80%' : '100%', width: DDS.isTab ? '80%' : '100%',
height: DDS.isTab ? '80%' : null, height: DDS.isTab ? '80%' : null,
alignSelf: 'center', alignSelf: 'center',
}}> }}>
<View <View
style={{ style={{
height: '70%', height: '70%',
paddingHorizontal: 12,
}}> }}>
<Text
style={{
textAlign: 'right',
marginHorizontal: 12,
fontFamily: WEIGHT.regular,
textAlignVertical: 'bottom',
position: 'absolute',
right: 5,
top: 2.5,
}}>
{invalidUsername ? (
<Icon
name="alert-circle-outline"
size={SIZE.xs}
color={colors.errorText}
/>
) : null}
</Text>
<TextInput <TextInput
ref={_username} ref={_username}
onFocus={() => { onFocus={() => {
@@ -270,7 +261,6 @@ export const Login = ({route, navigation}) => {
setInvalidUsername(true); setInvalidUsername(true);
_username.current.setNativeProps({ _username.current.setNativeProps({
style: { style: {
color: colors.errorText,
borderColor: colors.errorText, borderColor: colors.errorText,
}, },
}); });
@@ -284,14 +274,13 @@ export const Login = ({route, navigation}) => {
} }
}} }}
textContentType="username" textContentType="username"
onChangeText={value => { onChangeText={(value) => {
setUsername(value); setUsername(value);
if (invalidUsername && validateUsername(username)) { if (invalidUsername && validateUsername(username)) {
setInvalidUsername(false); setInvalidUsername(false);
_username.current.setNativeProps({ _username.current.setNativeProps({
style: { style: {
color: colors.pri,
borderColor: colors.accent, borderColor: colors.accent,
}, },
}); });
@@ -300,18 +289,12 @@ export const Login = ({route, navigation}) => {
onSubmitEditing={() => { onSubmitEditing={() => {
if (!validateUsername(username)) { if (!validateUsername(username)) {
setInvalidUsername(true); setInvalidUsername(true);
_username.current.setNativeProps({
style: {
color: colors.errorText,
},
});
} }
}} }}
style={{ style={{
padding: pv, padding: pv,
borderWidth: 1.5, borderWidth: 1.5,
borderColor: colors.nav, borderColor: colors.nav,
marginHorizontal: 12,
borderRadius: 5, borderRadius: 5,
fontSize: SIZE.sm, fontSize: SIZE.sm,
fontFamily: WEIGHT.regular, fontFamily: WEIGHT.regular,
@@ -400,6 +383,23 @@ export const Login = ({route, navigation}) => {
placeholder="Email" placeholder="Email"
placeholderTextColor={colors.icon} placeholderTextColor={colors.icon}
/> */} /> */}
{invalidUsername ? (
<Text
style={{
textAlign: 'right',
fontFamily: WEIGHT.regular,
textAlignVertical: 'bottom',
fontSize: SIZE.xs,
marginTop: 2.5,
}}>
<Icon
name="alert-circle-outline"
size={SIZE.xs}
color={colors.errorText}
/>{' '}
Username is invalid
</Text>
) : null}
<View <View
style={{ style={{
@@ -407,25 +407,6 @@ export const Login = ({route, navigation}) => {
marginTop: 15, marginTop: 15,
justifyContent: 'center', justifyContent: 'center',
}}> }}>
<Text
style={{
textAlign: 'right',
marginHorizontal: 12,
fontFamily: WEIGHT.regular,
textAlignVertical: 'bottom',
position: 'absolute',
right: 5,
top: 2.5,
}}>
{invalidPassword ? (
<Icon
name="alert-circle-outline"
size={SIZE.xs}
color={colors.errorText}
/>
) : null}
</Text>
<View <View
ref={_passContainer} ref={_passContainer}
style={{ style={{
@@ -436,7 +417,6 @@ export const Login = ({route, navigation}) => {
justifyContent: 'space-between', justifyContent: 'space-between',
alignItems: 'center', alignItems: 'center',
paddingHorizontal: 10, paddingHorizontal: 10,
marginHorizontal: 12,
}}> }}>
<TextInput <TextInput
ref={_pass} ref={_pass}
@@ -449,15 +429,10 @@ export const Login = ({route, navigation}) => {
}); });
} }
}} }}
defaultValue={password}
onBlur={() => { onBlur={() => {
if (!validatePass(password) && password?.length > 0) { if (!validatePass(password) && password?.length > 0) {
setInvalidPassword(true); setInvalidPassword(true);
_pass.current.setNativeProps({
style: {
color: colors.errorText,
},
});
_passContainer.current?.setNativeProps({ _passContainer.current?.setNativeProps({
style: { style: {
borderColor: colors.errorText, borderColor: colors.errorText,
@@ -472,15 +447,12 @@ export const Login = ({route, navigation}) => {
}); });
} }
}} }}
onChangeText={value => { onChangeText={(value) => {
setPassword(value); setPassword(value);
console.log(value, 'VALUE');
if (invalidPassword && validatePass(password)) { if (invalidPassword && validatePass(password)) {
setInvalidPassword(false); setInvalidPassword(false);
_pass.current.setNativeProps({
style: {
color: colors.pri,
},
});
_passContainer.current.setNativeProps({ _passContainer.current.setNativeProps({
style: { style: {
borderColor: colors.accent, borderColor: colors.accent,
@@ -510,10 +482,9 @@ export const Login = ({route, navigation}) => {
placeholder="Password" placeholder="Password"
placeholderTextColor={colors.icon} placeholderTextColor={colors.icon}
/> />
<Icon <Icon
name="eye" name="eye"
size={20} size={SIZE.md}
onPress={() => { onPress={() => {
setSecureEntry(!secureEntry); setSecureEntry(!secureEntry);
}} }}
@@ -523,28 +494,26 @@ export const Login = ({route, navigation}) => {
color={secureEntry ? colors.icon : colors.accent} color={secureEntry ? colors.icon : colors.accent}
/> />
</View> </View>
{invalidPassword ? (
<Text
style={{
textAlign: 'right',
fontFamily: WEIGHT.regular,
textAlignVertical: 'bottom',
fontSize: SIZE.xs,
marginTop: 2.5,
}}>
<Icon
name="alert-circle-outline"
size={SIZE.xs}
color={colors.errorText}
/>{' '}
Password is invalid
</Text>
) : null}
</View> </View>
<TouchableOpacity <Button title="Login" onPress={_logIn} width="100%" />
activeOpacity={opacity}
onPress={_logIn}
style={{
...getElevation(5),
padding: pv + 2,
backgroundColor: colors.accent,
borderRadius: 5,
marginHorizontal: 12,
marginBottom: 10,
alignItems: 'center',
}}>
<Text
style={{
fontSize: SIZE.md,
fontFamily: WEIGHT.medium,
color: 'white',
}}>
Login
</Text>
</TouchableOpacity>
</View> </View>
<View <View
@@ -555,8 +524,8 @@ export const Login = ({route, navigation}) => {
}}> }}>
<TouchableOpacity <TouchableOpacity
onPress={() => { onPress={() => {
navigation.navigate('Signup',{ navigation.navigate('Signup', {
root:true root: true,
}); });
}} }}
activeOpacity={opacity} activeOpacity={opacity}

View File

@@ -1,12 +1,13 @@
import { useIsFocused } from '@react-navigation/native'; import {useIsFocused} from '@react-navigation/native';
import React, { useEffect } from 'react'; import React, {useEffect} from 'react';
import { Text, TouchableOpacity, View } from 'react-native'; import {Text, TouchableOpacity, View} from 'react-native';
import { pv, SIZE, WEIGHT } from '../../common/common'; import {pv, SIZE, WEIGHT} from '../../common/common';
import { Placeholder } from '../../components/ListPlaceholders'; import {Placeholder} from '../../components/ListPlaceholders';
import SimpleList from '../../components/SimpleList'; import SimpleList from '../../components/SimpleList';
import { useTracked } from '../../provider'; import {useTracked} from '../../provider';
import { ACTIONS } from '../../provider/actions'; import {ACTIONS} from '../../provider/actions';
import NavigationService from '../../services/NavigationService'; import NavigationService from '../../services/NavigationService';
import {PressableButton} from '../../components/PressableButton';
export const Tags = ({route, navigation}) => { export const Tags = ({route, navigation}) => {
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();
@@ -85,13 +86,7 @@ const RenderItem = ({item, index}) => {
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();
const {colors} = state; const {colors} = state;
return ( return (
<View <PressableButton
style={{
paddingHorizontal:12
}}
>
<TouchableOpacity
key={item.title}
onPress={() => { onPress={() => {
NavigationService.navigate('Notes', { NavigationService.navigate('Notes', {
type: 'tag', type: 'tag',
@@ -99,16 +94,22 @@ const RenderItem = ({item, index}) => {
tag: item, tag: item,
}); });
}} }}
style={{ selectedColor={
currentEditingNote === item.dateCreated || pinned
? colors.accent
: colors.nav
}
alpha={!colors.night ? -0.02 : 0.02}
opacity={currentEditingNote === item.dateCreated || pinned ? 0.12 : 1}
customStyle={{
paddingHorizontal: 12,
height: 80,
flexDirection: 'row', flexDirection: 'row',
justifyContent: 'flex-start', justifyContent: 'flex-start',
alignItems: 'center', alignItems: 'center',
margin: 0,
paddingVertical: pv + 5,
borderBottomWidth: 1.5, borderBottomWidth: 1.5,
borderBottomColor: colors.nav, borderBottomColor: colors.nav,
}}> }}>
<Text <Text
style={{ style={{
fontFamily: WEIGHT.bold, fontFamily: WEIGHT.bold,
@@ -136,7 +137,6 @@ const RenderItem = ({item, index}) => {
: null} : null}
</Text> </Text>
</Text> </Text>
</TouchableOpacity> </PressableButton>
</View>
); );
}; };