|
@@ -16,38 +16,56 @@ import androidx.compose.foundation.shape.RoundedCornerShape
|
|
|
import androidx.compose.material.icons.Icons
|
|
|
import androidx.compose.material.icons.filled.KeyboardArrowLeft
|
|
|
import androidx.compose.material3.Button
|
|
|
-import androidx.compose.material3.ButtonColors
|
|
|
import androidx.compose.material3.ButtonDefaults
|
|
|
+import androidx.compose.material3.CircularProgressIndicator
|
|
|
import androidx.compose.material3.Icon
|
|
|
import androidx.compose.material3.MaterialTheme
|
|
|
import androidx.compose.material3.Text
|
|
|
import androidx.compose.material3.TextField
|
|
|
import androidx.compose.runtime.Composable
|
|
|
+import androidx.compose.runtime.getValue
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
import androidx.compose.runtime.remember
|
|
|
+import androidx.compose.runtime.setValue
|
|
|
import androidx.compose.ui.Alignment
|
|
|
import androidx.compose.ui.Modifier
|
|
|
import androidx.compose.ui.graphics.Brush
|
|
|
import androidx.compose.ui.graphics.Color
|
|
|
import androidx.compose.ui.input.pointer.pointerInput
|
|
|
+import androidx.compose.ui.platform.LocalContext
|
|
|
import androidx.compose.ui.platform.LocalFocusManager
|
|
|
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
|
|
import androidx.compose.ui.text.font.FontWeight
|
|
|
import androidx.compose.ui.text.style.TextAlign
|
|
|
-import androidx.compose.ui.tooling.preview.Preview
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
+import com.example.tomatoandpotatoapp.ViewModelsPack.SupabaseAuthViewModel
|
|
|
+import androidx.lifecycle.viewmodel.compose.viewModel
|
|
|
+import androidx.navigation.NavController
|
|
|
+import com.example.tomatoandpotatoapp.data.models.UserState
|
|
|
+import com.example.tomatoandpotatoapp.navigationPack.Screens
|
|
|
|
|
|
-@Preview(showBackground = true)
|
|
|
+//@Preview(showBackground = true)
|
|
|
@Composable
|
|
|
-fun Authorization() {
|
|
|
+fun Authorization(
|
|
|
+ viewModel: SupabaseAuthViewModel = viewModel(),
|
|
|
+ navController: NavController
|
|
|
+) {
|
|
|
+
|
|
|
+ val context = LocalContext.current
|
|
|
+ val userState by viewModel.userState
|
|
|
+ val f = remember { mutableStateOf(false) }
|
|
|
+
|
|
|
+ var userEmail by remember { mutableStateOf("") }
|
|
|
+ var userPassword by remember { mutableStateOf("") }
|
|
|
+
|
|
|
+ var currentUserState by remember { mutableStateOf("") }
|
|
|
|
|
|
val keyboardController = LocalSoftwareKeyboardController.current
|
|
|
val focusManager = LocalFocusManager.current
|
|
|
- val userEmail = remember { mutableStateOf("") }
|
|
|
- val userPassword = remember { mutableStateOf("") }
|
|
|
-
|
|
|
- val emailFlag = remember { mutableStateOf(false) }
|
|
|
+ val emailFlag = remember {
|
|
|
+ mutableStateOf(false)
|
|
|
+ }
|
|
|
|
|
|
Box(modifier = Modifier.fillMaxSize()) {
|
|
|
|
|
@@ -76,7 +94,7 @@ fun Authorization() {
|
|
|
) {
|
|
|
Button(
|
|
|
onClick = {
|
|
|
- /*TODO*/
|
|
|
+ navController.navigate(Screens.ChoiceScreen.route)
|
|
|
},
|
|
|
modifier = Modifier
|
|
|
.padding(start = 13.dp, top = 34.dp)
|
|
@@ -139,8 +157,8 @@ fun Authorization() {
|
|
|
placeholder = {
|
|
|
Text(text = "Введите логин")
|
|
|
},
|
|
|
- value = userEmail.value,
|
|
|
- onValueChange = { userEmail.value = it }
|
|
|
+ value = userEmail,
|
|
|
+ onValueChange = { userEmail = it }
|
|
|
)
|
|
|
|
|
|
TextField(
|
|
@@ -151,8 +169,8 @@ fun Authorization() {
|
|
|
placeholder = {
|
|
|
Text(text = "Введите пароль")
|
|
|
},
|
|
|
- value = userPassword.value,
|
|
|
- onValueChange = {userPassword.value = it}
|
|
|
+ value = userPassword,
|
|
|
+ onValueChange = { userPassword = it }
|
|
|
)
|
|
|
|
|
|
Spacer(modifier = Modifier.height(15.dp))
|
|
@@ -172,7 +190,8 @@ fun Authorization() {
|
|
|
text = "Вход",
|
|
|
fontSize = 20.sp,
|
|
|
fontWeight = FontWeight.W700,
|
|
|
- color = Color.White)
|
|
|
+ color = Color.White
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
|
|
@@ -182,5 +201,26 @@ fun Authorization() {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+ if (f.value) {
|
|
|
+ when (userState) {
|
|
|
+ is UserState.Loading -> {
|
|
|
+ CircularProgressIndicator()
|
|
|
+ }
|
|
|
+
|
|
|
+ is UserState.Success -> {
|
|
|
+ val message = (userState as UserState.Success).message
|
|
|
+ currentUserState = message
|
|
|
+ viewModel.selectPeople()
|
|
|
+ navController.navigate(Screens.AppNavigation.route)
|
|
|
+ f.value = false
|
|
|
+ }
|
|
|
+
|
|
|
+ is UserState.Error -> {
|
|
|
+ val message = (userState as UserState.Error).message
|
|
|
+ currentUserState = message
|
|
|
+ f.value = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|