1
1
package `in`.jitinsharma.asg.conf.ui
2
2
3
3
import `in`.jitinsharma.asg.conf.model.Country
4
- import `in`.jitinsharma.asg.conf.redux.actions.*
5
- import `in`.jitinsharma.asg.conf.redux.state.AppState
6
- import `in`.jitinsharma.asg.conf.redux.state.FilterState
7
4
import `in`.jitinsharma.asg.conf.utils.ThemedPreview
5
+ import `in`.jitinsharma.asg.conf.viewmodel.FilterScreenUiState
8
6
import androidx.compose.foundation.background
9
7
import androidx.compose.foundation.clickable
10
8
import androidx.compose.foundation.layout.*
@@ -22,33 +20,41 @@ import androidx.compose.ui.text.font.FontWeight
22
20
import androidx.compose.ui.tooling.preview.Preview
23
21
import androidx.compose.ui.unit.dp
24
22
import androidx.compose.ui.window.Dialog
25
- import org.koin.java.KoinJavaComponent.getKoin
26
- import org.rekotlin.Store
27
23
28
24
@Composable
29
25
fun FilterDialog (
30
- filterState : FilterState
26
+ filterScreenUiState : FilterScreenUiState ,
27
+ onDismissRequest : () -> Unit ,
28
+ onFilterRequest : (cfpFilterChecked: Boolean , selectedCountries: List <Country >) -> Unit
31
29
) {
32
- if (filterState.displayDialog) {
33
- val store = remember { getKoin().get<Store <AppState >>() }
34
- store.dispatch(LoadCountries ())
35
- Dialog (onDismissRequest = { store.dispatch(HideDialog ()) }) {
36
- FiltersScreen (
37
- cfpFilterChecked = filterState.cfpFilterChecked,
38
- selectedCountries = filterState.selectedCountries,
39
- countyList = filterState.countryList
40
- )
30
+ // if (filterState.displayDialog) {
31
+ // val store = remember { getKoin().get<Store<AppState>>() }
32
+ // store.dispatch(LoadCountries())
33
+ Dialog (onDismissRequest = { onDismissRequest() }) {
34
+ when (filterScreenUiState) {
35
+ is FilterScreenUiState .Success -> {
36
+ FiltersScreen (
37
+ cfpFilterChecked = filterScreenUiState.cfpFilterChecked,
38
+ selectedCountries = filterScreenUiState.selectedCountries.toMutableList(),
39
+ countyList = filterScreenUiState.countryList,
40
+ onDismiss = onDismissRequest,
41
+ onApply = onFilterRequest
42
+ )
43
+ }
41
44
}
42
45
}
46
+ // }
43
47
}
44
48
45
49
@Composable
46
50
fun FiltersScreen (
47
51
cfpFilterChecked : Boolean = false,
48
52
selectedCountries : MutableList <Country >,
49
- countyList : List <Country >?
53
+ countyList : List <Country >? ,
54
+ onDismiss : () -> Unit ,
55
+ onApply : (cfpFilterChecked: Boolean , selectedCountries: List <Country >) -> Unit
50
56
) {
51
- val store = remember { getKoin().get<Store <AppState >>() }
57
+ // val store = remember { getKoin().get<Store<AppState>>() }
52
58
Card (backgroundColor = themeColors.secondary) {
53
59
Column (modifier = Modifier .wrapContentSize()) {
54
60
Box (
@@ -94,7 +100,10 @@ fun FiltersScreen(
94
100
onCheckedChange = {
95
101
cfpFilterCheckState.value = cfpFilterCheckState.value.not ()
96
102
},
97
- colors = CheckboxConstants .defaultColors(checkedColor = themeColors.primary)
103
+ colors = CheckboxDefaults .colors(
104
+ checkedColor = MaterialTheme .colors.primary,
105
+ uncheckedColor = MaterialTheme .colors.primary
106
+ )
98
107
)
99
108
Text (
100
109
text = " Cfp Open" ,
@@ -124,7 +133,7 @@ fun FiltersScreen(
124
133
Box (
125
134
Modifier .clickable(
126
135
indication = rememberRippleIndication(),
127
- onClick = { store.dispatch( HideDialog () ) })
136
+ onClick = { onDismiss( ) })
128
137
) {
129
138
Text (
130
139
text = " CANCEL" ,
@@ -140,17 +149,7 @@ fun FiltersScreen(
140
149
Box (
141
150
Modifier .clickable(
142
151
indication = rememberRippleIndication(),
143
- onClick = {
144
- store.dispatch(SetCFPFilterCheck (cfpFilterCheckState.value))
145
- store.dispatch(SetSelectedCountries (selectedCountries))
146
- store.dispatch(HideDialog ())
147
- store.dispatch(
148
- FilterConferences (
149
- cfpFilterCheckState.value,
150
- selectedCountries
151
- )
152
- )
153
- })
152
+ onClick = { onApply(cfpFilterCheckState.value, selectedCountries) })
154
153
) {
155
154
Text (
156
155
text = " APPLY" ,
@@ -217,7 +216,10 @@ fun CountryList(
217
216
selectedCountries.remove(country)
218
217
}
219
218
},
220
- colors = CheckboxConstants .defaultColors(checkedColor = themeColors.primary)
219
+ colors = CheckboxDefaults .colors(
220
+ checkedColor = MaterialTheme .colors.primary,
221
+ uncheckedColor = MaterialTheme .colors.primary
222
+ )
221
223
)
222
224
Text (
223
225
text = country.name,
@@ -245,7 +247,9 @@ fun FilterScreenPreview() {
245
247
Country (" Japan" ),
246
248
Country (" Poland" )
247
249
),
248
- selectedCountries = mutableListOf ()
250
+ selectedCountries = mutableListOf (),
251
+ onDismiss = {},
252
+ onApply = { _, _ -> }
249
253
)
250
254
}
251
255
}
0 commit comments