Guest User

Untitled

a guest
Jan 29th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. import react.*
  2. import react.dom.*
  3.  
  4. interface GithubComponentState : RState {
  5. var username: String
  6. var password: String
  7. var logged: Boolean
  8. }
  9.  
  10. class GithubComponent : RComponent<RProps, GithubComponentState>() {
  11.  
  12. init {
  13. state.logged = false
  14. }
  15.  
  16. override fun RBuilder.render() {
  17.  
  18. if (!state.logged) {
  19. fieldSet {
  20. label { +"Username: " }
  21. input {
  22. [...]
  23. }
  24.  
  25. label { +"Password: " }
  26. input {
  27. [...]
  28. }
  29.  
  30. button {
  31. +"Login"
  32. attrs.onClickFunction = {
  33. val gh = GitHub(User(state.username, state.password))
  34. gh.getUser()
  35. .then {
  36. setState {
  37. logged = true
  38. }
  39. }
  40. }
  41. }
  42. }
  43. } else {
  44. button {
  45. +"Logout"
  46. attrs.onClickFunction = {
  47. setState { logged = false }
  48. }
  49. }
  50. }
  51.  
  52. }
  53. }
  54.  
  55. fun RBuilder.github() = child(GithubComponent::class) {
  56. }
Add Comment
Please, Sign In to add comment