From ee570630ac23e88103142bf1c7a22ccc5d79a416 Mon Sep 17 00:00:00 2001 From: gustavo-em Date: Tue, 1 Mar 2022 16:29:41 -0300 Subject: [PATCH] implementing logic of application --- App.tsx | 25 ++++++++------- .../app/pages/list_portals/component.tsx | 21 ++++++------ react-native/app/pages/list_portals/styles.ts | 2 -- .../app/pages/store_portals/component.tsx | 32 +++++++++++++++---- react-native/app/routes/component.js | 20 +++--------- react-native/bootstrap/start/component.js | 14 ++++---- 6 files changed, 61 insertions(+), 53 deletions(-) diff --git a/App.tsx b/App.tsx index 022972f..39a8222 100644 --- a/App.tsx +++ b/App.tsx @@ -1,21 +1,24 @@ import 'react-native-gesture-handler'; import * as React from 'react'; -import { StyleSheet, Platform, LogBox } from 'react-native'; import { Routes } from './react-native/app/routes/component'; import { PortalContextContainer } from './react-native/app/contexts/portals/container'; +import { LogBox } from 'react-native'; +import { Bootstrap } from './react-native/bootstrap/start/component'; + + + export default function App() { - React.useEffect(()=>{ - LogBox.ignoreLogs([ - "[react-native-gesture-handler] Seems like you\'re using an old API with gesture components, check out new Gestures system!", - ]); - }) + React.useEffect(()=>{ + LogBox.ignoreAllLogs(); + }, []) + return ( - <> - - - + <> + + + - ); + ); } diff --git a/react-native/app/pages/list_portals/component.tsx b/react-native/app/pages/list_portals/component.tsx index 969ec3f..c6fab7c 100644 --- a/react-native/app/pages/list_portals/component.tsx +++ b/react-native/app/pages/list_portals/component.tsx @@ -3,15 +3,18 @@ import React, { useRef } from 'react' import { ButtonDelete, ButtonOpen, DivButtonDelete, DivDelete, ItemList, TextButtonOpen, TextItem, TextWithoutPortal, WrapperItemListText, WrapperItemListView, WrapperList, WrapperListContainer, WrapperViewAdd } from './styles' import { usePortal } from '../../contexts/portals/hook'; import { Modalize } from 'react-native-modalize'; -import { Alert } from 'react-native'; import { StorePortals } from '../store_portals/component'; import FontAwesome5 from 'react-native-vector-icons/FontAwesome5'; import { colors } from '../../styles/colors'; import { SwipeListView } from 'react-native-swipe-list-view'; import { IHandles } from 'react-native-modalize/lib/options'; import { IItem, IItemDelete, IListPortalsDTO } from './types' +import i18next from 'i18next' +import { initTranslation } from '../../translations/index'; export const ListPortals = ({ navigation }: IListPortalsDTO)=>{ + + initTranslation() const icon = ; const {portals, setPortals} = usePortal() async function getPortals(){ @@ -22,9 +25,9 @@ export const ListPortals = ({ navigation }: IListPortalsDTO)=>{ let portalsStorage = await AsyncStorage.getItem('portal') portalsStorage = JSON.parse(portalsStorage as string) setPortals(portalsStorage) - console.log('portals', portals) + } else { - console.log('Dont Have Portals Storage') + console.log('Error: Dont Have Portals Storage') } } catch(e){ console.log('error',e) @@ -52,7 +55,7 @@ export const ListPortals = ({ navigation }: IListPortalsDTO)=>{ await AsyncStorage.setItem('portal', JSON.stringify(newPortalStorage)) setPortals(newPortalStorage) } else { - Alert.alert('Portals', 'Dont have Portals in Storage') + console.log('Error: Dont have Portals in Storage') } } catch(e){ console.log('error',e) @@ -72,7 +75,7 @@ export const ListPortals = ({ navigation }: IListPortalsDTO)=>{ - New Portal {icon} + {i18next.t("mobileApp.portals.list.add.button.label")} {icon} @@ -99,8 +102,8 @@ export const ListPortals = ({ navigation }: IListPortalsDTO)=>{ leftOpenValue={0} rightOpenValue={-80} disableRightSwipe={true} - closeOnRowPress={true} - closeOnRowOpen={true} + closeOnRowPress={true} + closeOnRowOpen={true} onRowOpen={(rowKey, rowMap) => { //This timeout is recommended https://github.com/jemise111/react-native-swipe-list-view/blob/master/docs/migrating-to-flatlist.md setTimeout(() => { @@ -109,8 +112,8 @@ export const ListPortals = ({ navigation }: IListPortalsDTO)=>{ } }, 3000) }} - /> - : There aren't Portals + /> + : {i18next.t("mobileApp.portals.list.empty.label")} } ) diff --git a/react-native/app/pages/list_portals/styles.ts b/react-native/app/pages/list_portals/styles.ts index 13239b2..dc86894 100644 --- a/react-native/app/pages/list_portals/styles.ts +++ b/react-native/app/pages/list_portals/styles.ts @@ -97,8 +97,6 @@ export const ButtonDelete = styled.TouchableOpacity` margin: 3% auto; width: 100%; height: 80px; - //left: 20px; - justify-content: center; align-items: center; diff --git a/react-native/app/pages/store_portals/component.tsx b/react-native/app/pages/store_portals/component.tsx index 6f3d665..e2fe335 100644 --- a/react-native/app/pages/store_portals/component.tsx +++ b/react-native/app/pages/store_portals/component.tsx @@ -6,29 +6,42 @@ import { ButtonApp } from '../../components/button/component'; import AsyncStorage from '@react-native-async-storage/async-storage'; import { usePortal } from '../../contexts/portals/hook'; import { IStore } from './types'; +import { initTranslation } from '../../translations/index'; +import i18next from 'i18next'; export const StorePortals = ({navigation, modalizeRef}:IStore)=>{ + initTranslation() const {portals, setPortals} = usePortal() const [name, setName] = React.useState(''); const [url, setUrl] = React.useState(''); const [emptyFields, setEmptyFields] = React.useState(false); + const [nameAlreadyUsed, setNameAlreadyUsed] = React.useState(false); async function newPortal(name:string, url:string){ let portalsStorage; portalsStorage = await AsyncStorage.getItem('portal') portalsStorage = portalsStorage ? JSON.parse(portalsStorage) : null - portalsStorage.push({name, url}) - AsyncStorage.setItem('portal', JSON.stringify(portalsStorage)) + portalsStorage.push({name, url}) + AsyncStorage.setItem('portal', JSON.stringify(portalsStorage)) setPortals(portalsStorage) modalizeRef?.current?.close(); navigation.navigate(name) } async function onPress(){ - + //return false; if(!name || !url) return setEmptyFields(true) try{ + let portalsFilter = portals.filter((portal: {name: string, url: string})=>{ + if(portal.name != name ) return false + return portal + }) + if(portalsFilter.length >= 1){ + setNameAlreadyUsed(true) + return false; + } await newPortal(name, url ) + } catch(e){ console.log('error', e) await AsyncStorage.setItem('portal', JSON.stringify([])) @@ -41,7 +54,12 @@ export const StorePortals = ({navigation, modalizeRef}:IStore)=>{ <> { emptyFields ? - Empty Fields + {i18next.t("mobileApp.portals.addPortalPopup.validation.emptyFilds")} + : null + } + { + nameAlreadyUsed ? + {i18next.t("mobileApp.portals.addPortalPopup.validation.portalNameAlreadyExists")} : null } @@ -53,13 +71,13 @@ export const StorePortals = ({navigation, modalizeRef}:IStore)=>{ {textEmptyFields()} - setName(e)} placeholder='Demo Server' label='Portal Name'/> + setName(e)} placeholder={i18next.t("mobileApp.portals.fields.name.placeholder")} label={i18next.t("mobileApp.portals.fields.name.label")}/> - setUrl(e)} placeholder='https://bigbluebutton.org/' label='Server URL'/> + setUrl(e)} placeholder={i18next.t("mobileApp.portals.fields.url.placeholder")} label={i18next.t("mobileApp.portals.fields.url.label")}/> - Add + {i18next.t("mobileApp.portals.addPortalPopup.confirm.button.label")} diff --git a/react-native/app/routes/component.js b/react-native/app/routes/component.js index 03f129c..961df83 100644 --- a/react-native/app/routes/component.js +++ b/react-native/app/routes/component.js @@ -1,18 +1,19 @@ import * as React from 'react'; -import { Alert } from 'react-native'; import { NavigationContainer } from '@react-navigation/native'; import { ListPortals } from '../pages/list_portals/component'; import { usePortal } from '../contexts/portals/hook'; import AsyncStorage from '@react-native-async-storage/async-storage'; +import i18next from 'i18next'; import { createDrawerNavigator, } from '@react-navigation/drawer'; import SdkContainer from '../../bootstrap/sdk/container'; +import { initTranslation } from '../translations/index'; const Drawer = createDrawerNavigator(); export const Routes = ()=>{ - + initTranslation() const {portals, setPortals} = usePortal() async function getPortals(){ @@ -22,8 +23,6 @@ export const Routes = ()=>{ let portalsStorage = await AsyncStorage.getItem('portal') portalsStorage = JSON.parse(portalsStorage) setPortals(portalsStorage) - } else { - Alert.alert('Portals', 'Dont have Portals in Storage') } } catch(e){ console.log('error', e) @@ -45,7 +44,7 @@ export const Routes = ()=>{ }} > - + { portals || portals != 0 ? portals.map((item)=>{ @@ -56,15 +55,4 @@ export const Routes = ()=>{ ); -} - - -export const RoutesContainer = ()=>{ - - return( - - <> - - - ) } \ No newline at end of file diff --git a/react-native/bootstrap/start/component.js b/react-native/bootstrap/start/component.js index 5e6b5d1..e54da00 100644 --- a/react-native/bootstrap/start/component.js +++ b/react-native/bootstrap/start/component.js @@ -1,15 +1,13 @@ import React from 'react' -import { GestureHandlerRootView } from 'react-native-gesture-handler' import { Routes } from '../../app/routes/component'; +import { PortalContextContainer } from '../../app/contexts/portals/container'; -//This archive is used to envolve app in contexts, libs, etc.. +//This file is used to envolve app in contexts, libs, etc.. export const Bootstrap = ()=>{ - return ( - <> - - - - + return ( + + + ) } \ No newline at end of file