11package com.github.cnrture.quickbackendwizard.generators
22
3- import androidx.compose.foundation.background
43import androidx.compose.foundation.layout.*
54import androidx.compose.foundation.rememberScrollState
65import androidx.compose.foundation.verticalScroll
76import androidx.compose.material.Divider
8- import androidx.compose.material.Switch
9- import androidx.compose.material.SwitchDefaults
107import androidx.compose.runtime.*
118import androidx.compose.ui.Alignment
129import androidx.compose.ui.Modifier
@@ -22,8 +19,7 @@ import com.github.cnrture.quickbackendwizard.theme.QBWTheme
2219@OptIn(ExperimentalLayoutApi ::class )
2320@Composable
2421fun DatabasesContent (moduleBuilder : QBWSpringBootModuleBuilder ) {
25- var selectedDatabase by remember { mutableStateOf(DatabaseType .ALL .first().type) }
26- var isDatabaseEnabled by remember { mutableStateOf(false ) }
22+ var selectedDatabase by remember { mutableStateOf(DatabaseType .MYSQL .type) }
2723 var dbName by remember { mutableStateOf(" " ) }
2824 var dbUsername by remember { mutableStateOf(" " ) }
2925 var dbPassword by remember { mutableStateOf(" " ) }
@@ -47,22 +43,6 @@ fun DatabasesContent(moduleBuilder: QBWSpringBootModuleBuilder) {
4743 ),
4844 )
4945 Spacer (modifier = Modifier .size(8 .dp))
50- Switch (
51- checked = isDatabaseEnabled,
52- onCheckedChange = {
53- isDatabaseEnabled = it
54- if (! it) {
55- selectedDatabase = " "
56- moduleBuilder.selectedDatabase = " "
57- }
58- },
59- colors = SwitchDefaults .colors(
60- checkedThumbColor = QBWTheme .colors.red,
61- uncheckedThumbColor = QBWTheme .colors.lightGray,
62- checkedTrackColor = QBWTheme .colors.red,
63- uncheckedTrackColor = QBWTheme .colors.lightGray.copy(alpha = 0.5f ),
64- ),
65- )
6646 }
6747 QBWText (
6848 text = " Select the database you want to use in your project." ,
@@ -73,125 +53,106 @@ fun DatabasesContent(moduleBuilder: QBWSpringBootModuleBuilder) {
7353 modifier = Modifier .padding(vertical = 8 .dp),
7454 color = QBWTheme .colors.lightGray,
7555 )
76- Box (
77- modifier = Modifier .fillMaxWidth(),
78- ) {
79- Column {
80- QBWText (
81- text = " Database Type" ,
82- color = QBWTheme .colors.red,
83- style = TextStyle (
84- fontSize = 16 .sp,
85- fontWeight = FontWeight .SemiBold ,
86- ),
87- )
88- Spacer (modifier = Modifier .height(12 .dp))
89- FlowRow (
90- modifier = Modifier .fillMaxWidth(),
91- maxItemsInEachRow = 2 ,
56+ Column {
57+ QBWText (
58+ text = " Database Type" ,
59+ color = QBWTheme .colors.red,
60+ style = TextStyle (
61+ fontSize = 16 .sp,
62+ fontWeight = FontWeight .SemiBold ,
63+ ),
64+ )
65+ Spacer (modifier = Modifier .height(12 .dp))
66+ FlowRow (
67+ modifier = Modifier .fillMaxWidth(),
68+ maxItemsInEachRow = 2 ,
69+ ) {
70+ DatabaseType .ALL .forEach { it ->
71+ DatabaseItem (
72+ modifier = Modifier .weight(1f ),
73+ name = it.name,
74+ description = it.description,
75+ type = it.type,
76+ selectedType = selectedDatabase,
77+ onSelect = { type ->
78+ selectedDatabase = type
79+ moduleBuilder.selectedDatabase = type
80+ },
81+ )
82+ }
83+ }
84+ Spacer (modifier = Modifier .height(24 .dp))
85+ Row (
86+ modifier = Modifier .fillMaxWidth(),
87+ horizontalArrangement = Arrangement .spacedBy(16 .dp),
88+ ) {
89+ Column (
90+ modifier = Modifier .weight(1f ),
9291 ) {
93- DatabaseType .ALL .forEach { it ->
94- DatabaseItem (
95- modifier = Modifier .weight(1f ),
96- name = it.name,
97- description = it.description,
98- type = it.type,
99- selectedType = selectedDatabase,
100- isEnabled = isDatabaseEnabled,
101- onSelect = { type ->
102- selectedDatabase = type
103- moduleBuilder.selectedDatabase = type
104- },
105- )
106- }
92+ QBWText (
93+ text = " Database Name" ,
94+ color = QBWTheme .colors.red,
95+ style = TextStyle (
96+ fontSize = 16 .sp,
97+ fontWeight = FontWeight .SemiBold ,
98+ ),
99+ )
100+ Spacer (modifier = Modifier .height(12 .dp))
101+ QBWTextField (
102+ modifier = Modifier .fillMaxWidth(),
103+ placeholder = " (e.g., testdb)" ,
104+ value = dbName,
105+ onValueChange = {
106+ dbName = it
107+ moduleBuilder.dbName = it
108+ },
109+ )
107110 }
108- Spacer (modifier = Modifier .height(24 .dp))
109- Row (
110- modifier = Modifier .fillMaxWidth(),
111- horizontalArrangement = Arrangement .spacedBy(16 .dp),
111+ Column (
112+ modifier = Modifier .weight(1f ),
112113 ) {
113- Column (
114- modifier = Modifier .weight(1f ),
115- ) {
116- QBWText (
117- text = " Database Name" ,
118- color = QBWTheme .colors.red,
119- style = TextStyle (
120- fontSize = 16 .sp,
121- fontWeight = FontWeight .SemiBold ,
122- ),
123- )
124- Spacer (modifier = Modifier .height(12 .dp))
125- QBWTextField (
126- modifier = Modifier .fillMaxWidth(),
127- placeholder = " (e.g., testdb)" ,
128- value = dbName,
129- isEnabled = isDatabaseEnabled,
130- onValueChange = {
131- dbName = it
132- moduleBuilder.dbName = it
133- },
134- )
135- }
136- Column (
137- modifier = Modifier .weight(1f ),
138- ) {
139- QBWText (
140- text = " Database Username" ,
141- color = QBWTheme .colors.red,
142- style = TextStyle (
143- fontSize = 16 .sp,
144- fontWeight = FontWeight .SemiBold ,
145- ),
146- )
147- Spacer (modifier = Modifier .height(12 .dp))
148- QBWTextField (
149- modifier = Modifier .fillMaxWidth(),
150- placeholder = " (e.g., root)" ,
151- value = dbUsername,
152- isEnabled = isDatabaseEnabled,
153- onValueChange = {
154- dbUsername = it
155- moduleBuilder.dbUsername = it
156- },
157- )
158- }
159- Column (
160- modifier = Modifier .weight(1f ),
161- ) {
162- QBWText (
163- text = " Database Password" ,
164- color = QBWTheme .colors.red,
165- style = TextStyle (
166- fontSize = 16 .sp,
167- fontWeight = FontWeight .SemiBold ,
168- ),
169- )
170- Spacer (modifier = Modifier .height(12 .dp))
171- QBWTextField (
172- modifier = Modifier .fillMaxWidth(),
173- placeholder = " (e.g., password)" ,
174- value = dbPassword,
175- isEnabled = isDatabaseEnabled,
176- onValueChange = {
177- dbPassword = it
178- moduleBuilder.dbPassword = it
179- },
180- )
181- }
114+ QBWText (
115+ text = " Database Username" ,
116+ color = QBWTheme .colors.red,
117+ style = TextStyle (
118+ fontSize = 16 .sp,
119+ fontWeight = FontWeight .SemiBold ,
120+ ),
121+ )
122+ Spacer (modifier = Modifier .height(12 .dp))
123+ QBWTextField (
124+ modifier = Modifier .fillMaxWidth(),
125+ placeholder = " (e.g., root)" ,
126+ value = dbUsername,
127+ onValueChange = {
128+ dbUsername = it
129+ moduleBuilder.dbUsername = it
130+ },
131+ )
182132 }
183- }
184- Box (
185- modifier = Modifier
186- .matchParentSize()
187- .background(
188- color = if (isDatabaseEnabled) {
189- QBWTheme .colors.gray.copy(alpha = 0.0f )
190- } else {
191- QBWTheme .colors.gray.copy(alpha = 0.6f )
133+ Column (
134+ modifier = Modifier .weight(1f ),
135+ ) {
136+ QBWText (
137+ text = " Database Password" ,
138+ color = QBWTheme .colors.red,
139+ style = TextStyle (
140+ fontSize = 16 .sp,
141+ fontWeight = FontWeight .SemiBold ,
142+ ),
143+ )
144+ Spacer (modifier = Modifier .height(12 .dp))
145+ QBWTextField (
146+ modifier = Modifier .fillMaxWidth(),
147+ placeholder = " (e.g., password)" ,
148+ value = dbPassword,
149+ onValueChange = {
150+ dbPassword = it
151+ moduleBuilder.dbPassword = it
192152 },
193153 )
194- )
154+ }
155+ }
195156 }
196157 }
197158}
@@ -203,15 +164,13 @@ private fun DatabaseItem(
203164 description : String ,
204165 type : String ,
205166 selectedType : String ,
206- isEnabled : Boolean ,
207167 onSelect : (String ) -> Unit ,
208168) {
209169 QBWRadioButton (
210170 modifier = modifier,
211171 text = name,
212172 description = description,
213- isEnabled = isEnabled,
214- selected = selectedType == type && isEnabled,
173+ selected = selectedType == type,
215174 onClick = { onSelect(type) },
216175 )
217176}
0 commit comments