Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Drip
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
backup
Drip
Commits
e4209e28
Commit
e4209e28
authored
5 years ago
by
Sofiya Tepikin
Browse files
Options
Downloads
Patches
Plain Diff
Refactors App wrapper component
parent
fa20e84b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
components/app-wrapper.js
+64
-22
64 additions, 22 deletions
components/app-wrapper.js
components/password-prompt.js
+28
-44
28 additions, 44 deletions
components/password-prompt.js
with
92 additions
and
66 deletions
components/app-wrapper.js
+
64
−
22
View file @
e4209e28
import
React
,
{
Component
}
from
'
react
'
import
React
,
{
Component
}
from
'
react
'
import
{
View
}
from
'
react-native
'
import
nodejs
from
'
nodejs-mobile-react-native
'
import
nodejs
from
'
nodejs-mobile-react-native
'
import
{
getLicenseFlag
,
saveEncryptionFlag
}
from
'
../local-storage
'
import
{
openDb
}
from
'
../db
'
import
App
from
'
./app
'
import
App
from
'
./app
'
import
PasswordPrompt
from
'
./password-prompt
'
import
PasswordPrompt
from
'
./password-prompt
'
import
License
from
'
./license
'
import
License
from
'
./license
'
import
{
getLicenseFlag
}
from
'
.
.
/
local-storage
'
import
AppLoadingView
from
'
./
app-loading
'
export
default
class
AppWrapper
extends
Component
{
export
default
class
AppWrapper
extends
Component
{
constructor
()
{
constructor
()
{
super
()
super
()
this
.
state
=
{
this
.
state
=
{
retrievingLicenseSetting
:
true
isCheckingLicenseAgreement
:
true
,
shouldShowLicenseAgreement
:
false
,
shouldShowPasswordPrompt
:
false
,
shouldShowApp
:
false
,
}
}
nodejs
.
start
(
'
main.js
'
)
nodejs
.
start
(
'
main.js
'
)
this
.
checkLicenseAgreement
()
this
.
checkLicenseAgreement
()
this
.
checkDbPasswordSet
()
}
}
async
checkLicenseAgreement
()
{
async
checkLicenseAgreement
()
{
const
agreed
=
await
getLicenseFlag
()
const
isLicenseFlagSet
=
await
getLicenseFlag
()
this
.
setState
({
retrievingLicenseSetting
:
false
})
if
(
!
isLicenseFlagSet
)
{
if
(
!
agreed
)
this
.
setState
({
showLicense
:
true
})
this
.
enableShowLicenseAgreement
()
}
else
{
this
.
setState
({
isCheckingLicenseAgreement
:
false
})
}
}
async
checkDbPasswordSet
()
{
const
canConnectToDb
=
await
openDb
()
if
(
canConnectToDb
)
{
this
.
enableShowApp
()
await
saveEncryptionFlag
(
false
)
return
false
}
this
.
setState
({
shouldShowPasswordPrompt
:
true
})
await
saveEncryptionFlag
(
true
)
}
enableShowLicenseAgreement
=
()
=>
{
this
.
setState
({
shouldShowLicenseAgreement
:
true
,
isCheckingLicenseAgreement
:
false
})
}
disableShowLicenseAgreement
=
()
=>
{
this
.
setState
({
shouldShowLicenseAgreement
:
false
})
}
enableShowApp
=
()
=>
{
this
.
setState
({
shouldShowApp
:
true
,
shouldShowPasswordPrompt
:
false
})
}
}
render
()
{
render
()
{
const
whiteScreen
=
<
View
style
=
{{
flex
:
1
}}
><
/View
>
const
{
const
licenseScreen
=
<
License
setLicense
=
{()
=>
{
isCheckingLicenseAgreement
,
this
.
setState
({
showLicense
:
false
})
shouldShowLicenseAgreement
,
}}
/
>
shouldShowPasswordPrompt
,
const
passwordPrompt
=
<
PasswordPrompt
showApp
=
{()
=>
{
shouldShowApp
,
this
.
setState
({
showApp
:
true
})
}
=
this
.
state
}}
/
>
if
(
isCheckingLicenseAgreement
)
{
if
(
this
.
state
.
retrievingLicenseSetting
)
{
return
<
AppLoadingView
/>
return
whiteScreen
}
else
if
(
this
.
state
.
showLicense
)
{
return
licenseScreen
}
else
if
(
!
this
.
state
.
showApp
)
{
return
passwordPrompt
}
else
{
return
<
App
/>
}
}
if
(
shouldShowLicenseAgreement
)
{
return
<
License
setLicense
=
{
this
.
disableShowLicenseAgreement
}
/
>
}
if
(
shouldShowPasswordPrompt
)
{
return
<
PasswordPrompt
enableShowApp
=
{
this
.
enableShowApp
}
/
>
}
return
shouldShowApp
&&
<
App
/>
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
components/password-prompt.js
+
28
−
44
View file @
e4209e28
...
@@ -20,19 +20,6 @@ export default class PasswordPrompt extends Component {
...
@@ -20,19 +20,6 @@ export default class PasswordPrompt extends Component {
this
.
passHashToDb
,
this
.
passHashToDb
,
this
this
)
)
this
.
tryToOpenDb
()
}
async
tryToOpenDb
()
{
const
connected
=
await
openDb
()
if
(
!
connected
)
{
this
.
setState
({
showPasswordPrompt
:
true
})
await
saveEncryptionFlag
(
true
)
return
}
await
saveEncryptionFlag
(
false
)
this
.
props
.
showApp
()
}
}
passHashToDb
=
async
hash
=>
{
passHashToDb
=
async
hash
=>
{
...
@@ -48,7 +35,7 @@ export default class PasswordPrompt extends Component {
...
@@ -48,7 +35,7 @@ export default class PasswordPrompt extends Component {
)
)
return
return
}
}
this
.
props
.
s
howApp
()
this
.
props
.
enableS
howApp
()
}
}
confirmDeletion
=
async
()
=>
{
confirmDeletion
=
async
()
=>
{
...
@@ -72,7 +59,7 @@ export default class PasswordPrompt extends Component {
...
@@ -72,7 +59,7 @@ export default class PasswordPrompt extends Component {
onPress
:
async
()
=>
{
onPress
:
async
()
=>
{
await
deleteDbAndOpenNew
()
await
deleteDbAndOpenNew
()
await
saveEncryptionFlag
(
false
)
await
saveEncryptionFlag
(
false
)
this
.
props
.
s
howApp
()
this
.
props
.
enableS
howApp
()
}
}
}]
}]
)
)
...
@@ -89,35 +76,32 @@ export default class PasswordPrompt extends Component {
...
@@ -89,35 +76,32 @@ export default class PasswordPrompt extends Component {
return
(
return
(
<
View
flex
=
{
1
}
>
<
View
flex
=
{
1
}
>
<
Header
title
=
{
menuTitles
.
PasswordPrompt
.
toLowerCase
()}
/
>
<
Header
title
=
{
menuTitles
.
PasswordPrompt
.
toLowerCase
()}
/
>
{
this
.
state
.
showPasswordPrompt
&&
<
View
style
=
{
styles
.
passwordPromptPage
}
>
<
View
style
=
{
styles
.
passwordPromptPage
}
>
<
TextInput
onChangeText
=
{
val
=>
this
.
setState
({
password
:
val
})}
<
TextInput
style
=
{
styles
.
passwordPromptField
}
onChangeText
=
{
val
=>
this
.
setState
({
password
:
val
})}
secureTextEntry
=
{
true
}
style
=
{
styles
.
passwordPromptField
}
placeholder
=
{
labels
.
enterPassword
}
secureTextEntry
=
{
true
}
/
>
placeholder
=
{
labels
.
enterPassword
}
<
TouchableOpacity
/
>
style
=
{
styles
.
passwordPromptButton
}
<
TouchableOpacity
onPress
=
{()
=>
{
style
=
{
styles
.
passwordPromptButton
}
requestHash
(
'
check-pw
'
,
this
.
state
.
password
)
onPress
=
{()
=>
{
}}
requestHash
(
'
check-pw
'
,
this
.
state
.
password
)
disabled
=
{
!
this
.
state
.
password
}
}}
>
disabled
=
{
!
this
.
state
.
password
}
<
AppText
style
=
{
styles
.
passwordPromptButtonText
}
>
>
{
labels
.
title
}
<
AppText
style
=
{
styles
.
passwordPromptButtonText
}
>
<
/AppText
>
{
labels
.
title
}
<
/TouchableOpacity
>
<
/AppText
>
<
TouchableOpacity
<
/TouchableOpacity
>
onPress
=
{
this
.
confirmDeletion
}
<
TouchableOpacity
>
onPress
=
{
this
.
confirmDeletion
}
<
AppText
style
=
{
styles
.
passwordPromptForgotPasswordText
}
>
>
{
labels
.
forgotPassword
}
<
AppText
style
=
{
styles
.
passwordPromptForgotPasswordText
}
>
<
/AppText
>
{
labels
.
forgotPassword
}
<
/TouchableOpacity
>
<
/AppText
>
<
/View
>
<
/TouchableOpacity
>
<
/View
>
}
<
/View
>
<
/View
>
)
)
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment