@@ -10,101 +10,64 @@ import react.dom.button
10
10
import react.dom.div
11
11
import react.dom.h3
12
12
import react.dom.p
13
+ import com.jarroyo.sharedcode.di.InjectorCommon
14
+ import com.jarroyo.sharedcode.domain.model.CurrentWeather
15
+ import com.jarroyo.sharedcode.domain.model.Location
16
+ import com.jarroyo.sharedcode.presentation.WeatherPresenter
17
+ import com.jarroyo.sharedcode.presentation.WeatherView
18
+ import org.w3c.dom.HTMLButtonElement
19
+ import org.w3c.dom.HTMLInputElement
20
+ import org.w3c.dom.HTMLParagraphElement
21
+ import kotlin.browser.document
13
22
14
- class Application : RComponent <ApplicationProps , RState >() {
23
+ class Application : RComponent <ApplicationProps , RState >(), WeatherView {
15
24
16
- // lateinit var mPresenter: WeatherPresenter
25
+ lateinit var mPresenter: WeatherPresenter
17
26
18
27
override fun RBuilder.render () {
19
- div(classes = " container" ) {
20
- div(classes = " header clearfix" ) {
21
- h3 { + " Kotlin Multiplatform Example" }
22
- }
23
- child(hello(), props = props)
24
- }
28
+ initPresenter()
29
+ configView()
30
+ }
25
31
26
- // getData()
32
+ private fun initPresenter () {
33
+ mPresenter = InjectorCommon .provideWeatherPresenter()
34
+ mPresenter.attachView(this )
27
35
}
28
36
29
- private fun getData () {
30
- GlobalScope .launch {
31
- val weatherApi: WeatherApi by kotlin.lazy { WeatherApi () }
32
- // WeatherRepository(weatherApi).getCurrentWeather(Location("Andorra"), success ={}, failure = {} )
37
+ private fun configView (){
38
+
39
+ val buttonGetWeather = document.getElementById(" buttonGetWeather" ) as HTMLButtonElement
40
+ buttonGetWeather.onclick = {
41
+ val locationTextArea = document.getElementById(" locationTextArea" ) as HTMLInputElement
42
+ val locationName = locationTextArea.value
43
+
44
+ if (! locationName.isNullOrEmpty()) {
45
+ mPresenter.getCurrentWeather(Location (locationName))
46
+ } else {
47
+ val descriptionLabel = document.getElementById(" descriptionLabel" ) as HTMLParagraphElement
48
+ descriptionLabel.textContent = " Enter a location to GetWeather"
49
+ }
33
50
}
34
51
}
35
52
36
- private fun initPresenter ( ) {
37
- // mPresenter = InjectorCommon.provideWeatherPresenter( )
38
- // mPresenter.attachView(this)
39
- //
40
- // mPresenter.getCurrentWeather(Location("Andorra"))
53
+ override fun onSuccessGetCurrentWeather ( currentWeather : CurrentWeather ) {
54
+ console.log(currentWeather )
55
+ val tempMaxLabel = document.getElementById( " tempMaxLabel " ) as HTMLParagraphElement
56
+ val tempMinLabel = document.getElementById( " tempMinLabel " ) as HTMLParagraphElement
57
+ val descriptionLabel = document.getElementById( " descriptionLabel " ) as HTMLParagraphElement
41
58
59
+ tempMaxLabel.textContent = " Temp. Max ${currentWeather.main?.temp_max.toString()} ºC"
60
+ tempMinLabel.textContent = " Temp. Min ${currentWeather.main?.temp_min.toString()} ºC"
61
+ descriptionLabel.textContent = " Description: ${currentWeather.weather?.get(0 )?.description} "
42
62
}
43
63
44
- // override fun onSuccessGetCurrentWeather(currentWeather: CurrentWeather) {
45
- // //Platform.runLater {
46
- // // tempMaxLabel.text = "Temp. Max ${currentWeather.main?.temp_max.toString()} ºC"
47
- // // tempMinLabel.text = "Temp. Min ${currentWeather.main?.temp_min.toString()} ºC"
48
- // // descriptionLabel.text = "Description: ${currentWeather.weather?.get(0)?.description}"
49
- // //}
50
- // }
51
- //
52
- // override fun onErrorGetCurrentWeather(throwable: Throwable) {
53
- // }
54
- //
55
- // override fun showHideLoading(visible: Boolean) {
56
- // }
57
- //
58
- // private fun showDialog(title: String, header: String = "", content: String = "") {
59
- // //Platform.runLater {
60
- // // val alert = Alert(AlertType.WARNING)
61
- // // alert.title = title
62
- // // alert.headerText = header
63
- // // alert.contentText = content
64
- //
65
- // // alert.showAndWait()
66
- // //}
67
- // }
68
- //
69
- // private fun refreshLocationList(locationModelList: List<LocationModel>) {
70
- // // Platform.runLater {
71
- // // var locationListParsed = arrayListOf<Location>()
72
- //
73
- // // for (locationModel in locationModelList) {
74
- // // var location = Location(locationModel.city_name, locationModel.country ?: "Uknown")
75
- // // locationListParsed.add(location)
76
- // // }
77
- //
78
- // // if (locationListParsed.isNotEmpty()) {
79
- // // val cityName = locationListParsed?.last().cityName
80
- //
81
- // // val array = arrayOfNulls<Location>(locationListParsed.size)
82
- // // listView.items.clear()
83
- // // listView.items.addAll(locationListParsed.toArray(array))
84
- // // listView.refresh()
85
- // // }
86
- //
87
- // //}
88
- // }
89
- }
64
+ override fun onErrorGetCurrentWeather (throwable : Throwable ) {
65
+ }
90
66
91
- fun hello () = functionalComponent<ApplicationProps > { props ->
92
- val (name, setName) = useState(null as String? )
93
-
94
- div {
95
- p { + if (name == null ) " Search your weather" else " Hello, $name " }
96
- button(classes = " btn btn-primary" ) {
97
- + " Fetch"
98
- attrs {
99
- onClickFunction = {
100
- GlobalScope .launch {
101
- console.log(props)
102
- // val name = props.networkRepository.getGreeting("web")
103
- // setName(name.message)
104
- }
105
- }
106
- }
107
- }
67
+ override fun showHideLoading (visible : Boolean ) {
68
+ }
69
+
70
+ private fun showDialog (title : String , header : String = "", content : String = "") {
108
71
}
109
72
}
110
73
0 commit comments