formatting

This commit is contained in:
balzack 2024-09-14 23:01:32 -07:00
parent dc5119fae7
commit 8af7ab1dc5
13 changed files with 224 additions and 111 deletions

View File

@ -6,14 +6,21 @@ import {
View, View,
Image, Image,
} from 'react-native'; } from 'react-native';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view' import {KeyboardAwareScrollView} from 'react-native-keyboard-aware-scroll-view';
import {useAccess} from './useAccess.hook'; import {useAccess} from './useAccess.hook';
import {styles} from './Access.styled'; import {styles} from './Access.styled';
import left from '../images/login.png'; import left from '../images/login.png';
import {IconButton, Modal, Surface, Text, TextInput, Button} from 'react-native-paper'; import {
IconButton,
Modal,
Surface,
Text,
TextInput,
Button,
} from 'react-native-paper';
import {SafeAreaView} from 'react-native-safe-area-context'; import {SafeAreaView} from 'react-native-safe-area-context';
import { BlurView } from "@react-native-community/blur"; import {BlurView} from '@react-native-community/blur';
import { InputCode } from '../utils/InputCode'; import {InputCode} from '../utils/InputCode';
export function Access() { export function Access() {
const [text, setText] = useState(''); const [text, setText] = useState('');
@ -64,7 +71,9 @@ export function Access() {
{state.layout === 'large' && ( {state.layout === 'large' && (
<Image style={styles.left} source={left} resizeMode="contain" /> <Image style={styles.left} source={left} resizeMode="contain" />
)} )}
<KeyboardAwareScrollView style={styles.frame} contentContainerStyle={styles.scroll}> <KeyboardAwareScrollView
style={styles.frame}
contentContainerStyle={styles.scroll}>
<SafeAreaView style={styles.right} edges={['top', 'bottom']}> <SafeAreaView style={styles.right} edges={['top', 'bottom']}>
<View style={styles.header}> <View style={styles.header}>
<View style={styles.admin} /> <View style={styles.admin} />
@ -92,9 +101,7 @@ export function Access() {
</View> </View>
{state.mode === 'account' && ( {state.mode === 'account' && (
<View style={styles.body}> <View style={styles.body}>
<Text variant="headlineSmall"> <Text variant="headlineSmall">{state.strings.accountLogin}</Text>
{state.strings.accountLogin}
</Text>
<TextInput <TextInput
style={styles.input} style={styles.input}
mode="flat" mode="flat"
@ -160,9 +167,7 @@ export function Access() {
)} )}
{state.mode === 'reset' && ( {state.mode === 'reset' && (
<View style={styles.body}> <View style={styles.body}>
<Text variant="headlineSmall"> <Text variant="headlineSmall">{state.strings.accessAccount}</Text>
{state.strings.accessAccount}
</Text>
<TextInput <TextInput
style={styles.input} style={styles.input}
mode="flat" mode="flat"
@ -202,9 +207,7 @@ export function Access() {
)} )}
{state.mode === 'create' && ( {state.mode === 'create' && (
<View style={styles.body}> <View style={styles.body}>
<Text variant="headlineSmall"> <Text variant="headlineSmall">{state.strings.createAccount}</Text>
{state.strings.createAccount}
</Text>
<View style={styles.spacer}> <View style={styles.spacer}>
{!state.available && ( {!state.available && (
<TextInput <TextInput
@ -365,7 +368,12 @@ export function Access() {
</SafeAreaView> </SafeAreaView>
</KeyboardAwareScrollView> </KeyboardAwareScrollView>
{(alert || otp) && ( {(alert || otp) && (
<BlurView style={styles.blur} blurType="dark" blurAmount={2} reducedTransparencyFallbackColor="dark" /> <BlurView
style={styles.blur}
blurType="dark"
blurAmount={2}
reducedTransparencyFallbackColor="dark"
/>
)} )}
<Modal <Modal
visible={alert} visible={alert}
@ -395,7 +403,7 @@ export function Access() {
mode="outlined" mode="outlined"
style={styles.submit} style={styles.submit}
onPress={() => setOtp(false)}> onPress={() => setOtp(false)}>
{state.strings.cancel} {state.strings.cancel}
</Button> </Button>
<Button <Button
mode="contained" mode="contained"
@ -405,7 +413,7 @@ export function Access() {
disabled={state.code.length !== 6}> disabled={state.code.length !== 6}>
{state.strings.login} {state.strings.login}
</Button> </Button>
</View> </View>
</Surface> </Surface>
</Modal> </Modal>
</Surface> </Surface>

View File

@ -47,8 +47,7 @@ export function useAccess() {
if (node) { if (node) {
const available = await app.actions.getAvailable(node, secure); const available = await app.actions.getAvailable(node, secure);
updateState({available}); updateState({available});
} } else {
else {
updateState({available: 0}); updateState({available: 0});
} }
} catch (err) { } catch (err) {
@ -76,9 +75,8 @@ export function useAccess() {
secure, secure,
); );
updateState({taken: !available}); updateState({taken: !available});
} } else {
else { updateState({taken: false});
updateState({ taken: false });
} }
} catch (err) { } catch (err) {
console.log(err); console.log(err);

View File

@ -1,9 +1,11 @@
import { useContext } from 'react'; import {useContext} from 'react';
import { Text, Button } from 'react-native-paper'; import {Text, Button} from 'react-native-paper';
import { SafeAreaView } from 'react-native'; import {SafeAreaView} from 'react-native';
export function Channels() { export function Channels() {
return ( return (
<SafeAreaView><Text>CHANNELS</Text></SafeAreaView> <SafeAreaView>
<Text>CHANNELS</Text>
</SafeAreaView>
); );
} }

View File

@ -1,9 +1,11 @@
import { useContext } from 'react'; import {useContext} from 'react';
import { Text, Button } from 'react-native-paper'; import {Text, Button} from 'react-native-paper';
import { SafeAreaView } from 'react-native'; import {SafeAreaView} from 'react-native';
export function Contacts() { export function Contacts() {
return ( return (
<SafeAreaView><Text>Contacts</Text></SafeAreaView> <SafeAreaView>
<Text>Contacts</Text>
</SafeAreaView>
); );
} }

View File

@ -47,7 +47,7 @@ export function useAppContext() {
appName: 'databag', appName: 'databag',
}; };
console.log("SDK LOGIN:", username, password, node, secure); console.log('SDK LOGIN:', username, password, node, secure);
const login = await sdk.current.login( const login = await sdk.current.login(
username, username,

View File

@ -16,8 +16,8 @@ export function useDisplayContext() {
}; };
useEffect(() => { useEffect(() => {
const layout = dim.width < SMALL_LARGE ? 'small' : 'large' const layout = dim.width < SMALL_LARGE ? 'small' : 'large';
updateState({ layout }); updateState({layout});
}, [dim.width]); }, [dim.width]);
const actions = {}; const actions = {};

View File

@ -1,5 +1,5 @@
import {Text} from 'react-native-paper'; import {Text} from 'react-native-paper';
export function Details() { export function Details() {
return <Text>DETAILS</Text> return <Text>DETAILS</Text>;
} }

View File

@ -1,3 +1,3 @@
export function Profile() { export function Profile() {
return <></> return <></>;
} }

View File

@ -1,4 +1,3 @@
export function Registry() { export function Registry() {
return <></> return <></>;
} }

View File

@ -21,4 +21,3 @@ export const styles = StyleSheet.create({
flexGrow: 1, flexGrow: 1,
}, },
}); });

View File

@ -1,17 +1,17 @@
import { useState, useContext } from 'react'; import {useState, useContext} from 'react';
import { View, SafeAreaView } from 'react-native'; import {View, SafeAreaView} from 'react-native';
import {styles} from './Session.styled'; import {styles} from './Session.styled';
import { BottomNavigation, Button, Text } from 'react-native-paper'; import {BottomNavigation, Button, Text} from 'react-native-paper';
import { DisplayContext } from '../context/DisplayContext'; import {DisplayContext} from '../context/DisplayContext';
import { Settings } from '../settings/Settings'; import {Settings} from '../settings/Settings';
import { Channels } from '../channels/Channels'; import {Channels} from '../channels/Channels';
import { Contacts } from '../contacts/Contacts'; import {Contacts} from '../contacts/Contacts';
import { Registry } from '../registry/Registry'; import {Registry} from '../registry/Registry';
import { Profile } from '../profile/Profile'; import {Profile} from '../profile/Profile';
import { Details } from '../details/Details'; import {Details} from '../details/Details';
import { NavigationContainer } from '@react-navigation/native'; import {NavigationContainer} from '@react-navigation/native';
import { createDrawerNavigator } from '@react-navigation/drawer'; import {createDrawerNavigator} from '@react-navigation/drawer';
const ChannelsRoute = () => <Channels />; const ChannelsRoute = () => <Channels />;
const ContactsRoute = () => <Contacts />; const ContactsRoute = () => <Contacts />;
@ -27,11 +27,26 @@ export function Session() {
const display = useContext(DisplayContext); const display = useContext(DisplayContext);
const [index, setIndex] = useState(0); const [index, setIndex] = useState(0);
const [routes] = useState([ const [routes] = useState([
{ key: 'channels', title: 'Channels', focusedIcon: 'comment-multiple', unfocusedIcon: 'comment-multiple-outline' }, {
{ key: 'contacts', title: 'Contacts', focusedIcon: 'contacts', unfocusedIcon: 'contacts-outline' }, key: 'channels',
{ key: 'settings', title: 'Settings', focusedIcon: 'cog', unfocusedIcon: 'cog-outline' }, title: 'Channels',
focusedIcon: 'comment-multiple',
unfocusedIcon: 'comment-multiple-outline',
},
{
key: 'contacts',
title: 'Contacts',
focusedIcon: 'contacts',
unfocusedIcon: 'contacts-outline',
},
{
key: 'settings',
title: 'Settings',
focusedIcon: 'cog',
unfocusedIcon: 'cog-outline',
},
]); ]);
const sessionNav = { settings: null }; const sessionNav = {settings: null};
const renderScene = BottomNavigation.SceneMap({ const renderScene = BottomNavigation.SceneMap({
channels: ChannelsRoute, channels: ChannelsRoute,
@ -44,7 +59,7 @@ export function Session() {
{display.state.layout !== 'large' && ( {display.state.layout !== 'large' && (
<BottomNavigation <BottomNavigation
labeled={false} labeled={false}
navigationState={{ index, routes }} navigationState={{index, routes}}
onIndexChange={setIndex} onIndexChange={setIndex}
renderScene={renderScene} renderScene={renderScene}
/> />
@ -56,9 +71,9 @@ export function Session() {
)} )}
</View> </View>
); );
}; }
function DetailsScreen({ nav }) { function DetailsScreen({nav}) {
return ( return (
<ProfileDrawer.Navigator <ProfileDrawer.Navigator
id="ProfileDrawer" id="ProfileDrawer"
@ -67,16 +82,17 @@ function DetailsScreen({ nav }) {
drawerPosition: 'right', drawerPosition: 'right',
drawerType: 'front', drawerType: 'front',
headerShown: false, headerShown: false,
}} }}>
>
<ProfileDrawer.Screen name="profile"> <ProfileDrawer.Screen name="profile">
{({ navigation }) => <ProfileScreen nav={{...nav, details: navigation}} />} {({navigation}) => (
<ProfileScreen nav={{...nav, details: navigation}} />
)}
</ProfileDrawer.Screen> </ProfileDrawer.Screen>
</ProfileDrawer.Navigator> </ProfileDrawer.Navigator>
) );
} }
function ProfileScreen({ nav }) { function ProfileScreen({nav}) {
return ( return (
<ProfileDrawer.Navigator <ProfileDrawer.Navigator
id="ProfileDrawer" id="ProfileDrawer"
@ -85,16 +101,17 @@ function ProfileScreen({ nav }) {
drawerPosition: 'right', drawerPosition: 'right',
drawerType: 'front', drawerType: 'front',
headerShown: false, headerShown: false,
}} }}>
>
<ProfileDrawer.Screen name="registry"> <ProfileDrawer.Screen name="registry">
{({ navigation }) => <RegistryScreen nav={{...nav, profile: navigation}} />} {({navigation}) => (
<RegistryScreen nav={{...nav, profile: navigation}} />
)}
</ProfileDrawer.Screen> </ProfileDrawer.Screen>
</ProfileDrawer.Navigator> </ProfileDrawer.Navigator>
) );
} }
function RegistryScreen({ nav }) { function RegistryScreen({nav}) {
return ( return (
<RegistryDrawer.Navigator <RegistryDrawer.Navigator
id="RegistryDrawer" id="RegistryDrawer"
@ -103,16 +120,17 @@ function RegistryScreen({ nav }) {
drawerPosition: 'right', drawerPosition: 'right',
drawerType: 'front', drawerType: 'front',
headerShown: false, headerShown: false,
}} }}>
>
<RegistryDrawer.Screen name="contacts"> <RegistryDrawer.Screen name="contacts">
{({ navigation }) => <ContactsScreen nav={{...nav, registry: navigation}} />} {({navigation}) => (
<ContactsScreen nav={{...nav, registry: navigation}} />
)}
</RegistryDrawer.Screen> </RegistryDrawer.Screen>
</RegistryDrawer.Navigator> </RegistryDrawer.Navigator>
) );
} }
function ContactsScreen({ nav }) { function ContactsScreen({nav}) {
return ( return (
<ContactsDrawer.Navigator <ContactsDrawer.Navigator
id="ContactsDrawer" id="ContactsDrawer"
@ -121,16 +139,17 @@ function ContactsScreen({ nav }) {
drawerPosition: 'right', drawerPosition: 'right',
drawerType: 'front', drawerType: 'front',
headerShown: false, headerShown: false,
}} }}>
>
<ContactsDrawer.Screen name="settings"> <ContactsDrawer.Screen name="settings">
{({ navigation }) => <SettingsScreen nav={{...nav, contacts: navigation}} />} {({navigation}) => (
<SettingsScreen nav={{...nav, contacts: navigation}} />
)}
</ContactsDrawer.Screen> </ContactsDrawer.Screen>
</ContactsDrawer.Navigator> </ContactsDrawer.Navigator>
) );
} }
function SettingsScreen({ nav }) { function SettingsScreen({nav}) {
return ( return (
<SettingsDrawer.Navigator <SettingsDrawer.Navigator
id="SettingsDrawer" id="SettingsDrawer"
@ -139,16 +158,15 @@ function SettingsScreen({ nav }) {
drawerPosition: 'right', drawerPosition: 'right',
drawerType: 'front', drawerType: 'front',
headerShown: false, headerShown: false,
}} }}>
>
<SettingsDrawer.Screen name="home"> <SettingsDrawer.Screen name="home">
{({ navigation }) => <HomeScreen nav={{...nav, settings: navigation}} />} {({navigation}) => <HomeScreen nav={{...nav, settings: navigation}} />}
</SettingsDrawer.Screen> </SettingsDrawer.Screen>
</SettingsDrawer.Navigator> </SettingsDrawer.Navigator>
) );
} }
function HomeScreen({ nav }) { function HomeScreen({nav}) {
return ( return (
<SafeAreaView style={styles.frame}> <SafeAreaView style={styles.frame}>
<View style={styles.left}> <View style={styles.left}>

View File

@ -1,14 +1,16 @@
import { useContext } from 'react'; import {useContext} from 'react';
import { AppContext } from '../context/AppContext'; import {AppContext} from '../context/AppContext';
import { Text, Button } from 'react-native-paper'; import {Text, Button} from 'react-native-paper';
import { SafeAreaView } from 'react-native'; import {SafeAreaView} from 'react-native';
export function Settings() { export function Settings() {
const app = useContext(AppContext); const app = useContext(AppContext);
return ( return (
<SafeAreaView> <SafeAreaView>
<Button mode="contained" onPress={app.actions.accountLogout}>Logout</Button> <Button mode="contained" onPress={app.actions.accountLogout}>
Logout
</Button>
</SafeAreaView> </SafeAreaView>
); );
} }

View File

@ -1,50 +1,135 @@
import { TextInput, Text, View, TouchableOpacity } from 'react-native'; import {TextInput, Text, View, TouchableOpacity} from 'react-native';
import { useState, useRef } from 'react'; import {useState, useRef} from 'react';
export function InputCode({ onChangeText, style }) {
export function InputCode({onChangeText, style}) {
const [code, setCode] = useState(''); const [code, setCode] = useState('');
const ref = useRef(); const ref = useRef();
const updateCode = (value) => { const updateCode = value => {
if (value.length >= 6) { if (value.length >= 6) {
onChangeText(value.slice(0, 6)); onChangeText(value.slice(0, 6));
if (ref.current) { if (ref.current) {
ref.current.blur(); ref.current.blur();
} }
} } else {
else {
onChangeText(''); onChangeText('');
} }
setCode(value.slice(0, 6)); setCode(value.slice(0, 6));
} };
return ( return (
<View style={style}> <View style={style}>
<View style={{ width: '100%', height: 32 }}> <View style={{width: '100%', height: 32}}>
<View style={{ width: '100%', height: '100%', display: 'flex', flexDirection: 'row', justifyContent: 'space-between' }}> <View
<View style={{ width: 32, height: '100%', borderWidth: 1, borderRadius: 4, backgroundColor: '#dddddd', borderColor: '#aaaaaa', alignItems: 'center', justifyContent: 'center', display: 'flex' }}> style={{
<Text style={{ fontSize: 20 }}>{ code.charAt(0) }</Text> width: '100%',
height: '100%',
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between',
}}>
<View
style={{
width: 32,
height: '100%',
borderWidth: 1,
borderRadius: 4,
backgroundColor: '#dddddd',
borderColor: '#aaaaaa',
alignItems: 'center',
justifyContent: 'center',
display: 'flex',
}}>
<Text style={{fontSize: 20}}>{code.charAt(0)}</Text>
</View> </View>
<View style={{ width: 32, height: '100%', borderWidth: 1, borderRadius: 4, backgroundColor: '#dddddd', borderColor: '#aaaaaa', alignItems: 'center', justifyContent: 'center', display: 'flex' }}> <View
<Text style={{ fontSize: 20 }}>{ code.charAt(1) }</Text> style={{
width: 32,
height: '100%',
borderWidth: 1,
borderRadius: 4,
backgroundColor: '#dddddd',
borderColor: '#aaaaaa',
alignItems: 'center',
justifyContent: 'center',
display: 'flex',
}}>
<Text style={{fontSize: 20}}>{code.charAt(1)}</Text>
</View> </View>
<View style={{ width: 32, height: '100%', borderWidth: 1, borderRadius: 4, backgroundColor: '#dddddd', borderColor: '#aaaaaa', alignItems: 'center', justifyContent: 'center', display: 'flex' }}> <View
<Text style={{ fontSize: 20 }}>{ code.charAt(2) }</Text> style={{
width: 32,
height: '100%',
borderWidth: 1,
borderRadius: 4,
backgroundColor: '#dddddd',
borderColor: '#aaaaaa',
alignItems: 'center',
justifyContent: 'center',
display: 'flex',
}}>
<Text style={{fontSize: 20}}>{code.charAt(2)}</Text>
</View> </View>
<View style={{ width: 32, height: '100%', borderWidth: 1, borderRadius: 4, backgroundColor: '#dddddd', borderColor: '#aaaaaa', alignItems: 'center', justifyContent: 'center', display: 'flex' }}> <View
<Text style={{ fontSize: 20 }}>{ code.charAt(3) }</Text> style={{
width: 32,
height: '100%',
borderWidth: 1,
borderRadius: 4,
backgroundColor: '#dddddd',
borderColor: '#aaaaaa',
alignItems: 'center',
justifyContent: 'center',
display: 'flex',
}}>
<Text style={{fontSize: 20}}>{code.charAt(3)}</Text>
</View> </View>
<View style={{ width: 32, height: '100%', borderWidth: 1, borderRadius: 4, backgroundColor: '#dddddd', borderColor: '#aaaaaa', alignItems: 'center', justifyContent: 'center', display: 'flex' }}> <View
<Text style={{ fontSize: 20 }}>{ code.charAt(4) }</Text> style={{
width: 32,
height: '100%',
borderWidth: 1,
borderRadius: 4,
backgroundColor: '#dddddd',
borderColor: '#aaaaaa',
alignItems: 'center',
justifyContent: 'center',
display: 'flex',
}}>
<Text style={{fontSize: 20}}>{code.charAt(4)}</Text>
</View> </View>
<View style={{ width: 32, height: '100%', borderWidth: 1, borderRadius: 4, backgroundColor: '#dddddd', borderColor: '#aaaaaa', alignItems: 'center', justifyContent: 'center', display: 'flex' }}> <View
<Text style={{ fontSize: 20 }}>{ code.charAt(5) }</Text> style={{
width: 32,
height: '100%',
borderWidth: 1,
borderRadius: 4,
backgroundColor: '#dddddd',
borderColor: '#aaaaaa',
alignItems: 'center',
justifyContent: 'center',
display: 'flex',
}}>
<Text style={{fontSize: 20}}>{code.charAt(5)}</Text>
</View> </View>
</View> </View>
<TextInput style={{ width: '100%', height: '100%', opacity: 0, position: 'absolute', top: 0, left: 0 }} keyboardType={Platform.OS === 'ios' ? 'numeric' : 'number-pad'} onChangeText={updateCode} autoCorrect={false} autoCapitalize="none" maxLength={6} ref={ref} /> <TextInput
style={{
width: '100%',
height: '100%',
opacity: 0,
position: 'absolute',
top: 0,
left: 0,
}}
keyboardType={Platform.OS === 'ios' ? 'numeric' : 'number-pad'}
onChangeText={updateCode}
autoCorrect={false}
autoCapitalize="none"
maxLength={6}
ref={ref}
/>
</View> </View>
</View> </View>
); );
} }