Creation of the crossmenu component and implementation

Here is the lesson code:


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

Application {
    Array treasureScores
    User loggedUser
    
    OnInit {
        treasureScores = [10, 20, 30, 50, 100]

        loggedUser = Accounts.getLocalPersistedUser()
        
        if (loggedUser != null) {
            Accounts.navigateToMainMenu()
            
        } else {
            broker.ui.push("Login")
        }
    }
}

RuleContext LoginContext {
    Rule login {
        Login loginExp = broker.ui.getDataSource()
        User user = Accounts.performLogin(loginExp.username, loginExp.password)

        if (user != null) {
            Accounts.setLoggedUser(user)
            Accounts.navigateToMainMenu()
        }
    }
}

Experience CreateTreasure {
    String name label("Treasure name") as TextField
    Double latitude label("latitude") as TextField
    Double longitude label("longitude") as TextField
    Array points value([])  as Select
    Array treasureLocationInMap as MapView

    Decision createNewTreasure action("CreateTreasureContext.createTreasure") label("Create Treasure")

    OnResume {
        CreateTreasure ct = broker.ui.getDataSource()
        ct.points = treasureScores
        ct.treasureLocationInMap = []
    }
}

> Next