Creation Experience and OnResume Life Cycle

 

This is the lesson code:


Experience UserProfile {
    String username as Label
    String points as Label
    String profileImg as Image
    
    Decision logOut action("UserProfileContext.logout") label("log out")
    Decision signUp action("UserProfileContext.deleteAccount") label("delete account")

    OnResume {
        UserProfile exp = broker.ui.getDataSource()
        exp.username = "Hi, " + loggedUser.name
        exp.points = "Your total score is: " + loggedUser.score.toString()

        if (loggedUser.profilePicUrl == null) {
            exp.profileImg = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRYrWO_3_FvPaYpbloqAHPYY_crj3eCjsYv4yvPXWn_NRiCiQGGIw" //placeholder avatar
        } else {
            exp.profileImg = loggedUser.profilePicUrl 
        }
    }
}

Model User {
    String name
    String password
    Integer score value(0)
    String profilePicUrl
}

Module Accounts {
    void navigateToMainMenu () {
        Welcome welcomeDataSource = Welcome()
        welcomeDataSource.greetings = "Welcome " + loggedUser.name + " to the treasure hunt app!"
        broker.ui.present("appmenu", welcomeDataSource, UserProfile(), CreateTreasure())
    }
}

> Next