Skip to content
Projects
Groups
Snippets
Help
Sign in / Register
Toggle navigation
Minds Mobile
Project overview
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
203
Merge Requests
13
Security & Compliance
Packages
Analytics
Wiki
Snippets
Members
Collapse sidebar
Close sidebar
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Minds
Minds Mobile
Commits
6dde3241
Commit
6dde3241
authored
7 minutes ago
by
Martin Santangelo
Browse files
Options
Download
(fix) settings and feature flags loading logic
parent
9ce74b65
fix/settings-feature-flag-loading-logic
No related merge requests found
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
40 additions
and
63 deletions
+40
-63
App.js
View file @
6dde3241
...
...
@@ -76,9 +76,10 @@ sqliteStorageProviderService.get();
apiService
.
clearCookies
();
const
mindsSettingsPromise
=
mindsService
.
getSettings
();
// On app login (runs if the user login or if it is already logged in)
sessionService
.
onLogin
(
async
()
=>
{
stores
.
mindsServiceStore
.
clear
();
const
user
=
sessionService
.
getUser
();
Sentry
.
configureScope
(
scope
=>
{
...
...
@@ -88,11 +89,9 @@ sessionService.onLogin(async () => {
logService
.
info
(
'
[App] Getting minds settings and onboarding progress
'
);
// load minds settings and boosted content
await
Promise
.
all
([
mindsSe
rvice
.
getSettings
()
,
boostedContentService
.
load
()]);
await
Promise
.
all
([
mindsSe
ttingsPromise
,
boostedContentService
.
load
()]);
logService
.
info
(
'
[App] updatting features
'
);
// reload fatures on login
await
featureService
.
updateFeatures
();
// register device token into backend on login
...
...
@@ -153,7 +152,6 @@ sessionService.onLogout(() => {
stores
.
notifications
.
clearLocal
();
stores
.
groupsBar
.
clearLocal
();
translationService
.
purgeLanguagesCache
();
stores
.
mindsServiceStore
.
clear
()
});
// disable yellow boxes
...
...
@@ -193,10 +191,6 @@ export default class App extends Component<Props, State> {
constructor
(
props
)
{
super
(
props
);
/*if (props.features) {
featureService.injectFeatures(JSON.parse(props.features));
}*/
if
(
!
Text
.
defaultProps
)
{
Text
.
defaultProps
=
{};
}
...
...
@@ -325,7 +319,7 @@ export default class App extends Component<Props, State> {
);
const
tosModal
=
(
<
TosModal
user
=
{
stores
.
user
}
key
=
"
tosModal
"
mindsServiceStore
=
{
stores
.
mindsServiceStore
}
/
>
<
TosModal
user
=
{
stores
.
user
}
key
=
"
tosModal
"
/>
)
return
[
app
,
keychainModal
,
blockchainTransactionModal
,
tosModal
];
...
...
This diff is collapsed.
AppStores.js
View file @
6dde3241
...
...
@@ -28,8 +28,6 @@ import groupsBar from './src/groups/GroupsBarStore';
import
sessionService
from
'
./src/common/services/session.service
'
;
import
logService
from
'
./src/common/services/log.service
'
;
import
SubscriptionRequestStore
from
'
./src/channel/subscription/SubscriptionRequestStore
'
;
import
MindsServiceStore
from
'
./src/common/stores/MindsServiceStore
'
;
/**
* App stores
...
...
@@ -62,7 +60,6 @@ const stores = {
hashtag
:
new
hashtag
(),
onboarding
:
new
onboarding
(),
groupsBar
:
new
groupsBar
(),
mindsServiceStore
:
new
MindsServiceStore
(),
};
/**
...
...
This diff is collapsed.
__tests__/auth/LoginScreen.js
View file @
6dde3241
...
...
@@ -7,7 +7,6 @@ import featuresService from '../../src/common/services/features.service';
import
LoginScreen
from
'
../../src/auth/LoginScreen
'
;
jest
.
mock
(
'
../../src/auth/AuthService
'
);
jest
.
mock
(
'
../../src/common/stores/MindsServiceStore
'
);
jest
.
mock
(
'
../../src/auth/LoginForm
'
,
()
=>
'
LoginForm
'
);
jest
.
mock
(
'
../../src/auth/ForgotPassword
'
,
()
=>
'
ForgotPassword
'
);
...
...
@@ -15,7 +14,6 @@ jest.mock('../../src/common/components/VideoBackground', () => 'VideoBackground'
// Note: test renderer must be required after react-native.
import
renderer
from
'
react-test-renderer
'
;
import
MindsServiceStore
from
'
../../src/common/stores/MindsServiceStore
'
describe
(
'
LoginScreen component
'
,
()
=>
{
...
...
@@ -24,17 +22,15 @@ describe('LoginScreen component', () => {
});
it
(
'
should renders correctly
'
,
()
=>
{
const
mindsServiceStore
=
new
MindsServiceStore
();
const
loginScreen
=
renderer
.
create
(
<
LoginScreen
mindsServiceStore
=
{
mindsServiceStore
}
/
>
<
LoginScreen
/>
).
toJSON
();
expect
(
loginScreen
).
toMatchSnapshot
();
});
it
(
'
should shows login form component
'
,
async
()
=>
{
const
mindsServiceStore
=
new
MindsServiceStore
();
const
wrapper
=
shallow
(
<
LoginScreen
hopFeatures
=
{
true
}
mindsServiceStore
=
{
mindsServiceStore
}
/
>
<
LoginScreen
hopFeatures
=
{
true
}
/
>
);
// search login form
...
...
@@ -46,14 +42,13 @@ describe('LoginScreen component', () => {
});
it
(
'
should shows forgot password component if the user press the button
'
,
async
()
=>
{
const
mindsServiceStore
=
new
MindsServiceStore
();
const
navigation
=
{
push
:
jest
.
fn
()
};
const
wrapper
=
shallow
(
<
LoginScreen
navigation
=
{
navigation
}
hopFeatures
=
{
true
}
mindsServiceStore
=
{
mindsServiceStore
}
/
>
<
LoginScreen
navigation
=
{
navigation
}
hopFeatures
=
{
true
}
/
>
);
// search login form
...
...
This diff is collapsed.
src/auth/LoginScreen.js
View file @
6dde3241
...
...
@@ -2,15 +2,11 @@ import React, {
Component
}
from
'
react
'
;
import
{
StackActions
,
NavigationActions
}
from
'
react-navigation
'
;
import
FastImage
from
'
react-native-fast-image
'
;
import
{
StyleSheet
,
ScrollView
,
View
,
KeyboardAvoidingView
,
Button
,
Keyboard
,
Animated
,
Platform
,
...
...
@@ -20,11 +16,9 @@ import * as Animatable from 'react-native-animatable';
import
LoginForm
from
'
./LoginForm
'
;
import
VideoBackground
from
'
../common/components/VideoBackground
'
;
import
{
CommonStyle
}
from
'
../styles/Common
'
;
import
{
ComponentsStyle
}
from
'
../styles/Components
'
;
import
logService
from
'
../common/services/log.service
'
;
import
featuresService
from
'
../common/services/features.service
'
;
import
CenteredLoading
from
'
../common/components/CenteredLoading
'
;
import
{
inject
}
from
'
mobx-react/native
'
;
const
LOGO_HEIGHT
=
100
;
const
LOGO_HEIGHT_SMALL
=
50
;
...
...
@@ -32,7 +26,6 @@ const LOGO_HEIGHT_SMALL = 50;
/**
* Login screen
*/
@
inject
(
'
mindsServiceStore
'
)
export
default
class
LoginScreen
extends
Component
{
state
=
{
...
...
@@ -54,7 +47,7 @@ export default class LoginScreen extends Component {
async
componentDidMount
()
{
if
(
!
this
.
props
.
hopFeatures
)
{
await
featuresService
.
updateFeatures
(
this
.
props
.
mindsServiceStore
);
await
featuresService
.
updateFeatures
();
if
(
featuresService
.
has
(
'
homepage-december-2019
'
))
{
this
.
props
.
navigation
.
navigate
(
'
LoginNew
'
);
}
...
...
This diff is collapsed.
src/common/services/features.service.js
View file @
6dde3241
...
...
@@ -13,7 +13,6 @@ import i18n from './i18n.service';
* Feature service
*/
class
FeaturesService
{
/**
* Local config features are available without inicialization
*/
...
...
@@ -24,17 +23,15 @@ class FeaturesService {
* Update features from minds services
*/
@
action
async
updateFeatures
(
mindsServiceStore
=
null
)
{
async
updateFeatures
()
{
let
settings
;
if
(
mindsServiceStore
)
{
settings
=
await
mindsServiceStore
.
getSettings
();
}
else
{
settings
=
await
mindsService
.
getSettings
();
}
settings
=
await
mindsService
.
getSettings
();
const
features
=
settings
.
features
;
Object
.
assign
(
features
,
MINDS_FEATURES
);
this
.
features
=
features
;
this
.
loaded
=
true
;
}
...
...
@@ -44,7 +41,7 @@ class FeaturesService {
const
features
=
this
.
features
;
Object
.
assign
(
features
,
otherFeatures
);
this
.
features
=
features
;
}
...
...
This diff is collapsed.
src/common/services/minds.service.js
View file @
6dde3241
import
api
from
'
./api.service
'
;
import
{
Alert
}
from
'
react-native
'
;
import
AsyncStorage
from
'
@react-native-community/async-storage
'
;
import
i18n
from
'
./i18n
.service
'
;
import
featuresService
from
'
./features
.service
'
;
/**
* Minds Service
*/
class
MindsService
{
settings
;
promise
;
/**
* Lazy load default settings
*/
loadDefault
=
()
=>
require
(
"
../../../settings/default.json
"
);
loadDefault
=
()
=>
require
(
'
../../../settings/default.json
'
);
/**
* Update the settings from the server
*/
async
update
()
{
const
settings
=
await
api
.
get
(
'
api/v1/minds/config
'
);
await
AsyncStorage
.
setItem
(
'
@MindsSettings
'
,
JSON
.
stringify
(
settings
));
this
.
settings
=
settings
;
// update the features based on the settings
featuresService
.
updateFeatures
();
}
/**
* Get settings
*/
getSettings
()
{
if
(
!
this
.
promise
||
this
.
settings
)
{
this
.
promise
=
this
.
_getSettings
();
}
return
this
.
promise
;
}
/**
* Get settings
*/
async
getSettings
()
{
async
_
getSettings
()
{
let
settings
;
if
(
!
this
.
settings
)
{
try
{
settings
=
JSON
.
parse
(
await
AsyncStorage
.
getItem
(
'
@MindsSettings
'
));
if
(
!
settings
)
throw
Error
(
'
No settings stored
'
);
if
(
!
settings
)
{
throw
Error
(
'
No settings stored
'
);
}
}
catch
{
settings
=
this
.
loadDefault
();
await
AsyncStorage
.
setItem
(
'
@MindsSettings
'
,
JSON
.
stringify
(
settings
));
}
this
.
settings
=
settings
;
await
this
.
update
();
// update the features based on the settings
featuresService
.
updateFeatures
();
this
.
update
();
}
return
this
.
settings
;
...
...
This diff is collapsed.
src/common/stores/MindsServiceStore.js
deleted
100644 → 0
View file @
9ce74b65
import
mindsService
from
"
../services/minds.service
"
;
export
default
class
MindsServiceStore
{
promise
;
async
getSettings
()
{
if
(
!
this
.
promise
)
{
this
.
promise
=
mindsService
.
getSettings
();
}
return
this
.
promise
;
}
clear
()
{
this
.
promise
=
null
;
}
}
This diff is collapsed.
src/tos/TosModal.js
View file @
6dde3241
...
...
@@ -19,7 +19,6 @@ import apiService from '../common/services/api.service';
/**
* Tos Modal
*/
@
inject
(
'
mindsServiceStore
'
)
@
observer
export
default
class
TosModal
extends
PureComponent
{
...
...
@@ -34,7 +33,7 @@ export default class TosModal extends PureComponent {
*/
async
componentDidMount
()
{
try
{
const
settings
=
await
this
.
props
.
mindsServiceStor
e
.
getSettings
();
const
settings
=
await
mindsServic
e
.
getSettings
();
if
(
settings
.
last_accepted_tos
)
{
this
.
setState
({
last_accepted_tos
:
settings
.
last_accepted_tos
});
}
...
...
This diff is collapsed.
Please
register
or
sign in
to comment