Hi
I am going crazy with this new Storage service that returns Promises…
For examle, how do you convert this code (Ionic 1)
$scope.isUser = UserService.getUser() ? true : false;
$scope.userTemp = storageService.get("userTemp ") ? true : false;
$scope.data.showLoginClose = ($scope.isUser || $scope.userTemp || !$rootScope.isMobile );
if ($scope.isUser) {
$scope.user = UserService.getUser();
switch ($scope.user.authVia) {
case 'google':
$scope.googleLoginButtonShow = false;
$scope.googleLogoutButtonShow = true;
$scope.facebookLoginButtonShow = false;
$scope.facebookLogoutButtonShow = false;
break;
case 'FB':
$scope.googleLoginButtonShow = false;
$scope.googleLogoutButtonShow = false;
$scope.facebookLoginButtonShow = false;
$scope.facebookLogoutButtonShow = true;
break;
default:
}
}
if ( $rootScope.isMobile && !$scope.isUser && storageService.get('onboardingDone') === 'yes' ) {
$scope.modal.show();
}
to ionic 2 using Storage ?
Here’s my take, but I am not happy with it, it’s long and complicated, I need help writing something cleaner:
let isUser: boolean;
let userTemp: boolean;
let that = this;
this.storage.ready().then(() => {
this.storage.get('userTemp')
.then((val) => {
userTemp = true ;
continueShit(userTemp);
})
.catch( (e) => {
userTemp = false ;
continueShit(userTemp);
})
});
function continueShit(userTemp){
let isUser = that.UserService.getUser() ? true : false;
that.data.showLoginClose = (isUser || userTemp || !that.isCordova.f() );
if (isUser) {
let user = that.UserService.getUser();
switch (user.authVia) {
case 'google':
that.googleLoginButtonShow = false;
that.googleLogoutButtonShow = true;
that.facebookLoginButtonShow = false;
that.facebookLogoutButtonShow = false;
break;
case 'FB':
that.googleLoginButtonShow = false;
that.googleLogoutButtonShow = false;
that.facebookLoginButtonShow = false;
that.facebookLogoutButtonShow = true;
break;
default:
}
}
that.storage.get('onboardingDone').then( (val) => {
if (val === "yes" && that.isCordova.f() && !isUser ){
that.navCtrl.push(LogoutPage);
}
})
}