booking fix

This commit is contained in:
solovushka56
2025-12-11 20:03:13 +03:00
parent 87bbfcc96c
commit 2af2c36ab2
5 changed files with 16 additions and 30 deletions

View File

@@ -4,7 +4,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class BookingInfoResponse(
val dates: Map<String, List<PlaceInfo>>
val dates: Map<String, List<PlaceInfo>>? = null // can be nil because web api
)
@Serializable

View File

@@ -93,7 +93,7 @@ fun BookScreen(
}
is BookState.Data -> {
if (currentState.error != null && currentState.dates.isEmpty()) {
if (currentState.error != null) {
Scaffold(
topBar = {
TopAppBar(
@@ -185,17 +185,6 @@ private fun Content(
.fillMaxSize()
.verticalScroll(rememberScrollState())
) {
if (state.error != null) {
Text(
text = state.error,
color = MaterialTheme.colorScheme.error,
modifier = Modifier
.testTag(TestIds.Book.ERROR)
.fillMaxWidth()
.padding(bottom = 16.dp),
textAlign = TextAlign.Center
)
}
ScrollableTabRow(
selectedTabIndex = state.selectedDateIndex,

View File

@@ -17,7 +17,6 @@ import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
class BookViewModel(private val bookRepo: BookRepository) : ViewModel() {
private val _uiState = MutableStateFlow<BookState>(BookState.Loading)
val uiState: StateFlow<BookState> = _uiState.asStateFlow()
@@ -72,7 +71,9 @@ class BookViewModel(private val bookRepo: BookRepository) : ViewModel() {
bookRepo.getAvailableBookings().fold(
onSuccess = { response ->
val dateItems = response.dates.entries
val datesMap = response.dates ?: emptyMap()
val dateItems = datesMap.entries
.filter { (_, places) -> places.isNotEmpty() }
.sortedBy { (date, _) -> parseDate(date) }
.map { (dateString, places) ->
@@ -103,7 +104,7 @@ class BookViewModel(private val bookRepo: BookRepository) : ViewModel() {
onFailure = { error ->
_uiState.update {
BookState.Data(
error = error.message ?: "data load err"
error = error.message ?: "Ошибка загрузки данных"
)
}
}
@@ -134,7 +135,7 @@ class BookViewModel(private val bookRepo: BookRepository) : ViewModel() {
onFailure = { error ->
_uiState.update {
state.copy(
error = error.message ?: "book error"
error = error.message ?: "Ошибка бронирования"
)
}
}
@@ -142,14 +143,14 @@ class BookViewModel(private val bookRepo: BookRepository) : ViewModel() {
} else {
_uiState.update {
state.copy(
error = "place !selected"
error = "Место не выбрано"
)
}
}
} else {
_uiState.update {
state.copy(
error = "select place for booking"
error = "Выберите место для бронирования"
)
}
}
@@ -183,7 +184,6 @@ sealed interface BookAction {
object NavigateBackWithRefresh : BookAction
}
class BookViewModelFactory(private val context: Context) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
if (modelClass.isAssignableFrom(BookViewModel::class.java)) {

View File

@@ -168,7 +168,6 @@ fun MainScreen(
}
}
// Кнопки действий
Row(
modifier = Modifier
.fillMaxWidth()
@@ -205,7 +204,6 @@ fun MainScreen(
Spacer(modifier = Modifier.height(8.dp))
// Заголовок списка бронирований
if (currentState.bookings.isNotEmpty()) {
Text(
text = "Мои бронирования:",
@@ -226,7 +224,6 @@ fun MainScreen(
}
}
// Список бронирований
LazyColumn(
modifier = Modifier
.fillMaxWidth()

View File

@@ -16,11 +16,10 @@ import java.time.format.DateTimeFormatter
import ru.myitschool.work.data.repo.AuthRepository
import ru.myitschool.work.data.repo.MainRepository
class MainViewModel(private val authRepo: AuthRepository,
private val mainRepo: MainRepository)
: ViewModel() {
class MainViewModel(
private val authRepo: AuthRepository,
private val mainRepo: MainRepository
) : ViewModel() {
private val _uiState = MutableStateFlow<MainState>(MainState.Loading)
val uiState: StateFlow<MainState> = _uiState.asStateFlow()
@@ -54,7 +53,6 @@ class MainViewModel(private val authRepo: AuthRepository,
}
}
is MainIntent.ItemClick -> {
}
}
}
@@ -89,7 +87,9 @@ class MainViewModel(private val authRepo: AuthRepository,
onFailure = { error ->
_uiState.update {
MainState.Data(
error = error.message ?: "data load err"
userName = authRepo.getUserInfo()?.name ?: "",
userPhotoUrl = authRepo.getUserInfo()?.photo,
error = error.message ?: "data load error"
)
}
}