корректное отображение при регистрации

This commit is contained in:
dasha 2023-12-18 22:00:26 +04:00
parent c0b94141a3
commit 30f50e94c7
7 changed files with 30 additions and 24 deletions

View File

@ -59,7 +59,7 @@ class RestCinemaRepository(
order.sessions.filter { session ->
session.id == sessionFromCinemaRemote.id &&
session.cinemaId == sessionFromCinemaRemote.cinemaId &&
session.cinema.name == cinemaWithSessions.name
session.dateTime == sessionFromCinemaRemote.dateTime
}
}.sumOf { session -> session.count },
uid

View File

@ -41,7 +41,11 @@ class RestUserRepository(
val cinema = service.getCinema(it.session.cinemaId)
it.toSessionFromCart(
it.session.maxCount - service.getOrders().flatMap { order ->
order.sessions.filter { session -> session.id == it.id }
order.sessions.filter { session ->
session.id == it.id &&
session.dateTime == it.session.dateTime &&
session.cinemaId == it.session.cinemaId
}
}.sumOf { session -> session.count }, cinema.toCinema()
)
}

View File

@ -163,7 +163,7 @@ fun Navhost(
composable(Screen.CinemaList.route) { CinemaList(navController) }
composable(Screen.OrderList.route) { OrderList(navController) }
composable(Screen.Cart.route) { Cart() }
composable(Screen.UserProfile.route) { UserProfile(isDarkTheme, dataStore, navController) }
composable(Screen.UserProfile.route) { UserProfile(isDarkTheme, dataStore) }
composable(
Screen.CinemaEdit.route,
arguments = listOf(navArgument("id") { type = NavType.IntType })

View File

@ -18,6 +18,7 @@ import androidx.compose.material3.Switch
import androidx.compose.material3.SwitchDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
@ -32,9 +33,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController
import com.example.myapplication.LiveStore
import com.example.myapplication.composeui.navigation.Screen
import com.example.myapplication.datastore.DataStoreManager
import kotlinx.coroutines.launch
@ -42,7 +41,6 @@ import kotlinx.coroutines.launch
fun UserProfile(
isDarkTheme: MutableState<Boolean>,
dataStoreManager: DataStoreManager,
navController: NavController,
viewModel: UserProfileViewModel = viewModel(factory = AppViewModelProvider.Factory),
) {
var isRegistration by remember { mutableStateOf(false) }
@ -52,11 +50,14 @@ fun UserProfile(
if (errorStringId == null || errorStringId == 0) "" else stringResource(errorStringId)
val user = LiveStore.user.observeAsState()
LaunchedEffect(errorStringId) {
if (errorStringId == 0) {
isRegistration = false
}
}
LazyColumn {
item {
if (errorStringId == 0) {
navController.navigate(Screen.CinemaList.route)
}
if (user.value != null) {
Column(
modifier = Modifier
@ -174,7 +175,11 @@ fun UserProfile(
)
} else {
Button(
onClick = { coroutine.launch { viewModel.signIn(dataStoreManager) } },
onClick = {
coroutine.launch {
viewModel.signIn(dataStoreManager)
}
},
modifier = Modifier
.fillMaxWidth()
.padding(8.dp)

View File

@ -1,5 +1,6 @@
package com.example.myapplication.database.entities.composeui
import android.util.Log
import android.widget.Toast
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
@ -35,11 +36,11 @@ class UserProfileViewModel(
errorId = R.string.err_04
} else {
dataStoreManager.setLogin(userUiState.details.login)
errorId = 0
Log.d("UserProfileViewModel", "sign in success")
}
}
userUiState = UserUiState(
details = userUiState.details,
details = UserDetails(),
errorId = errorId
)
}, actionError = {
@ -60,10 +61,6 @@ class UserProfileViewModel(
errorId = R.string.err_03
}
}
userUiState = UserUiState(
details = userUiState.details,
errorId = errorId
)
if (errorId == null) {
userRepository.insertUser(userUiState.details.toUser())
val toast = Toast.makeText(
@ -72,7 +69,12 @@ class UserProfileViewModel(
Toast.LENGTH_SHORT
)
toast.show()
errorId = 0
}
userUiState = UserUiState(
details = userUiState.details,
errorId = errorId
)
}, actionError = {
errorId = R.string.err_06
userUiState = UserUiState(

View File

@ -17,12 +17,6 @@
"password": "qqq",
"role": 0,
"id": 3
},
{
"login": "qweq",
"password": "qweq",
"role": 0,
"id": 4
}
],
"userssessions": [

View File

@ -8,7 +8,7 @@ module.exports = (req, res, next) => {
try {
const { startDate, endDate } = req.query;
const { sessions, orders } = require('./data.json');
const { cinemas, sessions, orders } = require('./data.json');
const start = new Date(startDate);
const end = new Date(endDate);
@ -42,8 +42,9 @@ module.exports = (req, res, next) => {
};
}, { totalTicketsSold: 0, revenue: 0 });
const cinema = cinemas.find(cinema => cinema.id === session.cinemaId)
return {
cinema_name: relevantOrders[0].sessions[0].cinema.name,
cinema_name: cinema ? cinema.name : "Unknown",
current_ticket_date_time: session.dateTime,
current_ticket_price: session.price,
max_ticket_quantity: session.maxCount,