корректное отображение при регистрации
This commit is contained in:
parent
c0b94141a3
commit
30f50e94c7
@ -59,7 +59,7 @@ class RestCinemaRepository(
|
|||||||
order.sessions.filter { session ->
|
order.sessions.filter { session ->
|
||||||
session.id == sessionFromCinemaRemote.id &&
|
session.id == sessionFromCinemaRemote.id &&
|
||||||
session.cinemaId == sessionFromCinemaRemote.cinemaId &&
|
session.cinemaId == sessionFromCinemaRemote.cinemaId &&
|
||||||
session.cinema.name == cinemaWithSessions.name
|
session.dateTime == sessionFromCinemaRemote.dateTime
|
||||||
}
|
}
|
||||||
}.sumOf { session -> session.count },
|
}.sumOf { session -> session.count },
|
||||||
uid
|
uid
|
||||||
|
@ -41,7 +41,11 @@ class RestUserRepository(
|
|||||||
val cinema = service.getCinema(it.session.cinemaId)
|
val cinema = service.getCinema(it.session.cinemaId)
|
||||||
it.toSessionFromCart(
|
it.toSessionFromCart(
|
||||||
it.session.maxCount - service.getOrders().flatMap { order ->
|
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()
|
}.sumOf { session -> session.count }, cinema.toCinema()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ fun Navhost(
|
|||||||
composable(Screen.CinemaList.route) { CinemaList(navController) }
|
composable(Screen.CinemaList.route) { CinemaList(navController) }
|
||||||
composable(Screen.OrderList.route) { OrderList(navController) }
|
composable(Screen.OrderList.route) { OrderList(navController) }
|
||||||
composable(Screen.Cart.route) { Cart() }
|
composable(Screen.Cart.route) { Cart() }
|
||||||
composable(Screen.UserProfile.route) { UserProfile(isDarkTheme, dataStore, navController) }
|
composable(Screen.UserProfile.route) { UserProfile(isDarkTheme, dataStore) }
|
||||||
composable(
|
composable(
|
||||||
Screen.CinemaEdit.route,
|
Screen.CinemaEdit.route,
|
||||||
arguments = listOf(navArgument("id") { type = NavType.IntType })
|
arguments = listOf(navArgument("id") { type = NavType.IntType })
|
||||||
|
@ -18,6 +18,7 @@ import androidx.compose.material3.Switch
|
|||||||
import androidx.compose.material3.SwitchDefaults
|
import androidx.compose.material3.SwitchDefaults
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.MutableState
|
import androidx.compose.runtime.MutableState
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.livedata.observeAsState
|
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.text.input.PasswordVisualTransformation
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import androidx.navigation.NavController
|
|
||||||
import com.example.myapplication.LiveStore
|
import com.example.myapplication.LiveStore
|
||||||
import com.example.myapplication.composeui.navigation.Screen
|
|
||||||
import com.example.myapplication.datastore.DataStoreManager
|
import com.example.myapplication.datastore.DataStoreManager
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@ -42,7 +41,6 @@ import kotlinx.coroutines.launch
|
|||||||
fun UserProfile(
|
fun UserProfile(
|
||||||
isDarkTheme: MutableState<Boolean>,
|
isDarkTheme: MutableState<Boolean>,
|
||||||
dataStoreManager: DataStoreManager,
|
dataStoreManager: DataStoreManager,
|
||||||
navController: NavController,
|
|
||||||
viewModel: UserProfileViewModel = viewModel(factory = AppViewModelProvider.Factory),
|
viewModel: UserProfileViewModel = viewModel(factory = AppViewModelProvider.Factory),
|
||||||
) {
|
) {
|
||||||
var isRegistration by remember { mutableStateOf(false) }
|
var isRegistration by remember { mutableStateOf(false) }
|
||||||
@ -52,11 +50,14 @@ fun UserProfile(
|
|||||||
if (errorStringId == null || errorStringId == 0) "" else stringResource(errorStringId)
|
if (errorStringId == null || errorStringId == 0) "" else stringResource(errorStringId)
|
||||||
val user = LiveStore.user.observeAsState()
|
val user = LiveStore.user.observeAsState()
|
||||||
|
|
||||||
|
LaunchedEffect(errorStringId) {
|
||||||
|
if (errorStringId == 0) {
|
||||||
|
isRegistration = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
LazyColumn {
|
LazyColumn {
|
||||||
item {
|
item {
|
||||||
if (errorStringId == 0) {
|
|
||||||
navController.navigate(Screen.CinemaList.route)
|
|
||||||
}
|
|
||||||
if (user.value != null) {
|
if (user.value != null) {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@ -174,7 +175,11 @@ fun UserProfile(
|
|||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Button(
|
Button(
|
||||||
onClick = { coroutine.launch { viewModel.signIn(dataStoreManager) } },
|
onClick = {
|
||||||
|
coroutine.launch {
|
||||||
|
viewModel.signIn(dataStoreManager)
|
||||||
|
}
|
||||||
|
},
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(8.dp)
|
.padding(8.dp)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.example.myapplication.database.entities.composeui
|
package com.example.myapplication.database.entities.composeui
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
@ -35,11 +36,11 @@ class UserProfileViewModel(
|
|||||||
errorId = R.string.err_04
|
errorId = R.string.err_04
|
||||||
} else {
|
} else {
|
||||||
dataStoreManager.setLogin(userUiState.details.login)
|
dataStoreManager.setLogin(userUiState.details.login)
|
||||||
errorId = 0
|
Log.d("UserProfileViewModel", "sign in success")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
userUiState = UserUiState(
|
userUiState = UserUiState(
|
||||||
details = userUiState.details,
|
details = UserDetails(),
|
||||||
errorId = errorId
|
errorId = errorId
|
||||||
)
|
)
|
||||||
}, actionError = {
|
}, actionError = {
|
||||||
@ -60,10 +61,6 @@ class UserProfileViewModel(
|
|||||||
errorId = R.string.err_03
|
errorId = R.string.err_03
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
userUiState = UserUiState(
|
|
||||||
details = userUiState.details,
|
|
||||||
errorId = errorId
|
|
||||||
)
|
|
||||||
if (errorId == null) {
|
if (errorId == null) {
|
||||||
userRepository.insertUser(userUiState.details.toUser())
|
userRepository.insertUser(userUiState.details.toUser())
|
||||||
val toast = Toast.makeText(
|
val toast = Toast.makeText(
|
||||||
@ -72,7 +69,12 @@ class UserProfileViewModel(
|
|||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
)
|
)
|
||||||
toast.show()
|
toast.show()
|
||||||
|
errorId = 0
|
||||||
}
|
}
|
||||||
|
userUiState = UserUiState(
|
||||||
|
details = userUiState.details,
|
||||||
|
errorId = errorId
|
||||||
|
)
|
||||||
}, actionError = {
|
}, actionError = {
|
||||||
errorId = R.string.err_06
|
errorId = R.string.err_06
|
||||||
userUiState = UserUiState(
|
userUiState = UserUiState(
|
||||||
|
@ -17,12 +17,6 @@
|
|||||||
"password": "qqq",
|
"password": "qqq",
|
||||||
"role": 0,
|
"role": 0,
|
||||||
"id": 3
|
"id": 3
|
||||||
},
|
|
||||||
{
|
|
||||||
"login": "qweq",
|
|
||||||
"password": "qweq",
|
|
||||||
"role": 0,
|
|
||||||
"id": 4
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"userssessions": [
|
"userssessions": [
|
||||||
|
@ -8,7 +8,7 @@ module.exports = (req, res, next) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const { startDate, endDate } = req.query;
|
const { startDate, endDate } = req.query;
|
||||||
const { sessions, orders } = require('./data.json');
|
const { cinemas, sessions, orders } = require('./data.json');
|
||||||
|
|
||||||
const start = new Date(startDate);
|
const start = new Date(startDate);
|
||||||
const end = new Date(endDate);
|
const end = new Date(endDate);
|
||||||
@ -42,8 +42,9 @@ module.exports = (req, res, next) => {
|
|||||||
};
|
};
|
||||||
}, { totalTicketsSold: 0, revenue: 0 });
|
}, { totalTicketsSold: 0, revenue: 0 });
|
||||||
|
|
||||||
|
const cinema = cinemas.find(cinema => cinema.id === session.cinemaId)
|
||||||
return {
|
return {
|
||||||
cinema_name: relevantOrders[0].sessions[0].cinema.name,
|
cinema_name: cinema ? cinema.name : "Unknown",
|
||||||
current_ticket_date_time: session.dateTime,
|
current_ticket_date_time: session.dateTime,
|
||||||
current_ticket_price: session.price,
|
current_ticket_price: session.price,
|
||||||
max_ticket_quantity: session.maxCount,
|
max_ticket_quantity: session.maxCount,
|
||||||
|
Loading…
Reference in New Issue
Block a user