Skip to content

Commit

Permalink
fix the edit and remove auto logout and fix dialog bug
Browse files Browse the repository at this point in the history
  • Loading branch information
milon27 committed Dec 19, 2021
1 parent b911e68 commit fb65341
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 99 deletions.
36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@
"eject": "expo eject"
},
"dependencies": {
"@expo-google-fonts/lobster-two": "^0.2.0",
"@react-native-async-storage/async-storage": "^1.13.0",
"@expo-google-fonts/lobster-two": "0.2.0",
"@react-native-async-storage/async-storage": "1.13.0",
"@react-native-community/masked-view": "0.1.10",
"@react-navigation/drawer": "^5.12.5",
"@react-navigation/native": "^5.9.4",
"@react-navigation/stack": "^5.14.5",
"axios": "^0.21.1",
"crypto-es": "^1.2.7",
"expo": "~41.0.1",
"expo-clipboard": "~1.0.2",
"expo-status-bar": "~1.0.4",
"@react-navigation/drawer": "5.12.5",
"@react-navigation/native": "5.9.4",
"@react-navigation/stack": "5.14.5",
"axios": "0.21.1",
"crypto-es": "1.2.7",
"expo": "41.0.1",
"expo-clipboard": "1.0.2",
"expo-status-bar": "1.0.4",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-41.0.0.tar.gz",
"react-native-dropdown-picker": "^5.1.21",
"react-native-gesture-handler": "~1.10.2",
"react-native-reanimated": "~2.1.0",
"react-native-dropdown-picker": "5.1.21",
"react-native-gesture-handler": "1.10.2",
"react-native-reanimated": "2.1.0",
"react-native-safe-area-context": "3.2.0",
"react-native-screens": "~3.0.0",
"react-native-vector-icons": "^8.1.0",
"react-native-web": "~0.13.12"
"react-native-screens": "3.0.0",
"react-native-vector-icons": "8.1.0",
"react-native-web": "0.13.12"
},
"devDependencies": {
"@babel/core": "^7.9.0"
"@babel/core": "7.9.0"
},
"private": true
}
}
7 changes: 3 additions & 4 deletions src/components/layouts/modal/PasswordModal.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useContext, useState, useEffect } from 'react'
import { View, Text, StyleSheet } from 'react-native'
import { Text, StyleSheet } from 'react-native'
import MModal from './MModal'
import Theme from './../../../utils/helpers/Theme';
import ListAction from './../../../utils/context/actions/ListAction';
Expand All @@ -22,7 +22,6 @@ export default function PasswordModal({ open, setOpen, item }) {
let mounted = true
const load = async () => {
try {

const password = await Helper.decryptPass(item?.password)
if (mounted === true) {
//console.log("mounted=== ", mounted);
Expand All @@ -32,14 +31,14 @@ export default function PasswordModal({ open, setOpen, item }) {
console.log("model: ", e);
}
}
if (isFocused === true) {
if (isFocused === true && open === true) {
load()
}
return () => {
mounted = false
}

}, [isFocused])
}, [isFocused, open])

const onSubmit = () => {
setOpen(false)
Expand Down
43 changes: 2 additions & 41 deletions src/components/navigation/AppNavContainer.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,18 @@
import React, { useContext, useState, useEffect, useRef } from 'react'
import React, { useContext, useState, useEffect } from 'react'
import { NavigationContainer } from '@react-navigation/native';
import AuthNav from './AuthNav';
import DashDrawNav from './DashDrawNav';
import Splash from './../screens/splash/Splash';
import { DispatchContext, StateContext } from './../../utils/context/MainContext';
import AuthAction from './../../utils/context/actions/AuthAction';
import Helper from './../../utils/helpers/Helper';
import { AppState } from 'react-native';
import useAsyncStorage from './../../utils/helpers/hooks/useAsyncstorage';

export default function AppNavContainer() {

const { auth, } = useContext(StateContext)
const { authDispatch } = useContext(DispatchContext)
const [loading, setLoading] = useState(true)

const [offline, setOffline] = useAsyncStorage("OFFLINE_TIME", new Date().getTime())




//app state
const _handleAppStateChange = async (nextAppState) => {
//appState.current.match(/inactive|background/) &&
if (
nextAppState === 'active'
) {
const ctime = new Date().getTime()
if (Math.abs(ctime - offline) > 30000) {
//if (auth?.logged_in) {
console.log("it was background for more than 30 seconds");
await new AuthAction(authDispatch).Logout()
//do logout
Helper.Toast("logged out for inactivity.")
// }
} else {
console.log("Diff=", Math.abs(ctime - offline));
}
} else {
const ctime = new Date().getTime()
console.log("App is in background!", ctime);
//set time in localstorage. when app goes to backgroud
setOffline(ctime)
}
}

useEffect(() => {
const load = async () => {
Expand All @@ -68,17 +37,9 @@ export default function AppNavContainer() {

setTimeout(() => {
setLoading(false)
}, 300);
}, 10);
}
load()

//state change listener
AppState.addEventListener('change', _handleAppStateChange)

return () => {
AppState.removeEventListener('change', _handleAppStateChange);
}

}, [])


Expand Down
3 changes: 1 addition & 2 deletions src/components/screens/category/AllCat.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export default function AllCat() {
const token = AxiosHelper.getSource()
const load = async () => {
try {
const uid = await Helper.getUserID()
const data = await AxiosHelper.getData(`pass/get-all-cat/${uid}/`, token)
const data = await AxiosHelper.getData(`pass/get-all-cat/`, token)
if (data.success) {
// console.log("data:", data)
setCat(data.object)
Expand Down
5 changes: 5 additions & 0 deletions src/components/screens/dashboard/ContactDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import OfflineListAction from './../../../utils/context/actions/OfflineListActio
import Define from '../../../utils/helpers/Define';
import { DispatchContext } from '../../../utils/context/MainContext';

/**
*
* @param {*} param0
* @returns not used in this project.
*/
export default function ContactDetail({ route: { params } }) {
const { navigate, setOptions } = useNavigation()

Expand Down
5 changes: 3 additions & 2 deletions src/components/screens/dashboard/CreateCategory.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { StateContext } from './../../../utils/context/MainContext';
import Theme from './../../../utils/helpers/Theme';
import AxiosHelper from './../../../utils/helpers/AxiosHelper';
import { StatusBar } from 'expo-status-bar';

export default function CreateCategory() {
const { app } = useContext(StateContext)
const [title, setTitle] = useState("")
Expand All @@ -20,8 +21,8 @@ export default function CreateCategory() {
setError("Enter category title.")
return
}
const userId = await Helper.getUserID()
let val = await AxiosHelper.addData('pass/create-cat', { title, user: userId })

let val = await AxiosHelper.addData('pass/create-cat', { title })
console.log("CreateCategory", val)
if (val.success) {
setTitle("")
Expand Down
21 changes: 8 additions & 13 deletions src/components/screens/dashboard/CreatePassword.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function CreatePassword({ route: { params }, navigation }) {
const { app } = useContext(StateContext)
const { appDispatch } = useContext(DispatchContext)

const [value, setValue] = useState([]);
const [value, setValue] = useState(null);//single : null, multi: []
const [open, setOpen] = useState(false);

const titleRef = useRef(null)
Expand All @@ -39,7 +39,6 @@ export default function CreatePassword({ route: { params }, navigation }) {
const N_PASSWORD = "password"
const N_EMAIL = "email"
const N_USERNAME = "username"
const N_USER = "user"
const N_OTHER = "other"
const N_CAT = "category"
const N_IS_FAV = "is_fav"
Expand All @@ -51,7 +50,6 @@ export default function CreatePassword({ route: { params }, navigation }) {
[N_USERNAME]: item[N_USERNAME] || "",
[N_PASSWORD]: "",
[N_OTHER]: item[N_OTHER] || "",
[N_USER]: item[N_USER] || "",
[N_IS_FAV]: item[N_IS_FAV] || false,
} : {
[N_TITLE]: "",
Expand All @@ -60,7 +58,6 @@ export default function CreatePassword({ route: { params }, navigation }) {
[N_USERNAME]: "",
[N_PASSWORD]: "",
[N_OTHER]: "",
[N_USER]: "",
[N_IS_FAV]: false,
}
const clear_init = {
Expand All @@ -70,7 +67,6 @@ export default function CreatePassword({ route: { params }, navigation }) {
[N_USERNAME]: "",
[N_PASSWORD]: "",
[N_OTHER]: "",
[N_USER]: "",
[N_IS_FAV]: false,
}

Expand All @@ -94,14 +90,14 @@ export default function CreatePassword({ route: { params }, navigation }) {
})
const pass = await Helper.decryptPass(item[N_PASSWORD])
setInput({ ...input, [N_PASSWORD]: pass })
setValue(item[N_CAT]);
//console.log("all cat of the current item-", item[N_CAT])//get 1st one.
setValue(item[N_CAT][0]);//set old category. or selected item.
}

const uid = await Helper.getUserID()
const data = await AxiosHelper.getData(`pass/get-all-cat/${uid}/`, token)
const data = await AxiosHelper.getData(`pass/get-all-cat/`, token)
if (data.success) {
//console.log("cat: ", data.object)
setCat(data.object)
//console.log("pass/get-all-cat/: ", data.object)//[]
setCat(data.object)//set the cat list in dropdown
}
} catch (e) {
console.log("error Create Password.js->", e);
Expand Down Expand Up @@ -141,7 +137,6 @@ export default function CreatePassword({ route: { params }, navigation }) {
const data = {
...input,
[N_PASSWORD]: await Helper.encryptPass(input[N_PASSWORD]),
[N_USER]: await Helper.getUserID(),
[N_CAT]: value
}

Expand All @@ -163,7 +158,7 @@ export default function CreatePassword({ route: { params }, navigation }) {
appac.STOP_LOADING()
if (val.success) {
setInput(clear_init)
setValue([])
setValue(null)
Helper.Toast("" + val.desc)
} else {
Helper.Toast("" + val.desc)
Expand Down Expand Up @@ -246,7 +241,7 @@ export default function CreatePassword({ route: { params }, navigation }) {

theme={Theme.STATUS_BAR_ALT.toUpperCase()}


multiple={false}
open={open}
setOpen={setOpen}
value={value}
Expand Down
10 changes: 4 additions & 6 deletions src/components/screens/dashboard/HomeScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ export default function HomeScreen() {
const token = AxiosHelper.getSource()
const load = async () => {
try {
const uid = await Helper.getUserID()
const data = await AxiosHelper.getData(`pass/get-all-cat/${uid}/`, token)
const data = await AxiosHelper.getData(`pass/get-all-cat/`, token)
if (data.success) {
// console.log("data:", data)
setCat(old => {
Expand Down Expand Up @@ -75,11 +74,10 @@ export default function HomeScreen() {
try {
//load password..
appac.START_LOADING()
const uid = await Helper.getUserID()
if (select === "all_cat") {
await listAc.getAll(`pass/get-all/${uid}/`, [])
await listAc.getAll(`pass/get-all/`, [])
} else {
await listAc.getAll(`pass/get-all/${uid}/${select}`, [])
await listAc.getAll(`pass/get-all/${select}`, [])
}
// const val =
//console.log("home pass val =", val)
Expand All @@ -96,7 +94,7 @@ export default function HomeScreen() {
return () => {
token.cancel()
}
}, [isFocused, select, pass.length])
}, [isFocused, select])


const renderItem = ({ item }) => {
Expand Down
4 changes: 3 additions & 1 deletion src/components/screens/dashboard/SingleRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import PasswordModal from './../../layouts/modal/PasswordModal';
import AreYouSureModal from './../../layouts/modal/AreYouSureModal';

export default function SingleRow({ item }) {
const [modalItem, setModalItem] = useState(null)
const [open, setOpen] = useState(false)
const [open1, setOpen1] = useState(false)
const onPress = () => {
setModalItem(item)
setOpen(true)
}

Expand All @@ -25,7 +27,7 @@ export default function SingleRow({ item }) {
return <TouchableOpacity onPress={onPress} onLongPress={onLongPress} style={styles.item_container}>
{/* {console.log("row -> ", item)} */}

<PasswordModal setOpen={setOpen} open={open} item={item} />
<PasswordModal setOpen={setOpen} open={open} item={modalItem} />
<AreYouSureModal setOpen={setOpen1} open={open1} submitText="Delete Password" onSubmit={onDelete} />

<View style={{ flexDirection: "row", alignItems: "center" }}>
Expand Down
5 changes: 2 additions & 3 deletions src/components/screens/favourite/Fav.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import Theme from '../../../utils/helpers/Theme';
import Container from './../../layouts/Container';
import ListAction from './../../../utils/context/actions/ListAction';
import AppAction from './../../../utils/context/actions/AppAction';
import Helper from './../../../utils/helpers/Helper';
import { StatusBar } from 'expo-status-bar';

export default function Fav() {

const isFocused = useIsFocused();
Expand All @@ -26,8 +26,7 @@ export default function Fav() {
try {
//load password..
appac.START_LOADING()
const uid = await Helper.getUserID()
const val = await listAc.getAll(`pass/get-all-fav/${uid}/`, [])
const val = await listAc.getAll(`pass/get-all-fav/`, [])
//console.log("fav pass val =", val)
appac.STOP_LOADING()
} catch (e) {
Expand Down
6 changes: 1 addition & 5 deletions src/components/screens/password/ChangePassword.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export default function ChangePassword() {
[N_NEW_C_PASSWORD]: "",
}
//state
const [uid, setUid] = useState("")
const [input, setInput] = useState(initValue)
const [error, setError] = useState(initValue)
//effect
Expand All @@ -45,9 +44,7 @@ export default function ChangePassword() {

try {
//load password..
const uid = await Helper.getUserID()
setUid(uid)
const val = await listAc.getAll(`pass/get-all/${uid}/`, [])
const val = await listAc.getAll(`pass/get-all/`, [])
//console.log("change pass val =", val)
} catch (e) {
console.log("error ChangePassword.js->", e);
Expand Down Expand Up @@ -109,7 +106,6 @@ export default function ChangePassword() {
const data = {
arr: resultArray,
user: {
_id: uid,
pass: input[N_NEW_PASSWORD]
}
}
Expand Down
Loading

0 comments on commit fb65341

Please sign in to comment.