forked from Olympic/NTO-2025-Android-TeamTask
booking fix
This commit is contained in:
@@ -4,7 +4,7 @@ import kotlinx.serialization.Serializable
|
|||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class BookingInfoResponse(
|
data class BookingInfoResponse(
|
||||||
val dates: Map<String, List<PlaceInfo>>
|
val dates: Map<String, List<PlaceInfo>>? = null // can be nil because web api
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ fun BookScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
is BookState.Data -> {
|
is BookState.Data -> {
|
||||||
if (currentState.error != null && currentState.dates.isEmpty()) {
|
if (currentState.error != null) {
|
||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = {
|
topBar = {
|
||||||
TopAppBar(
|
TopAppBar(
|
||||||
@@ -185,17 +185,6 @@ private fun Content(
|
|||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.verticalScroll(rememberScrollState())
|
.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(
|
ScrollableTabRow(
|
||||||
selectedTabIndex = state.selectedDateIndex,
|
selectedTabIndex = state.selectedDateIndex,
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import java.text.SimpleDateFormat
|
|||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
|
|
||||||
class BookViewModel(private val bookRepo: BookRepository) : ViewModel() {
|
class BookViewModel(private val bookRepo: BookRepository) : ViewModel() {
|
||||||
private val _uiState = MutableStateFlow<BookState>(BookState.Loading)
|
private val _uiState = MutableStateFlow<BookState>(BookState.Loading)
|
||||||
val uiState: StateFlow<BookState> = _uiState.asStateFlow()
|
val uiState: StateFlow<BookState> = _uiState.asStateFlow()
|
||||||
@@ -72,7 +71,9 @@ class BookViewModel(private val bookRepo: BookRepository) : ViewModel() {
|
|||||||
|
|
||||||
bookRepo.getAvailableBookings().fold(
|
bookRepo.getAvailableBookings().fold(
|
||||||
onSuccess = { response ->
|
onSuccess = { response ->
|
||||||
val dateItems = response.dates.entries
|
val datesMap = response.dates ?: emptyMap()
|
||||||
|
|
||||||
|
val dateItems = datesMap.entries
|
||||||
.filter { (_, places) -> places.isNotEmpty() }
|
.filter { (_, places) -> places.isNotEmpty() }
|
||||||
.sortedBy { (date, _) -> parseDate(date) }
|
.sortedBy { (date, _) -> parseDate(date) }
|
||||||
.map { (dateString, places) ->
|
.map { (dateString, places) ->
|
||||||
@@ -103,7 +104,7 @@ class BookViewModel(private val bookRepo: BookRepository) : ViewModel() {
|
|||||||
onFailure = { error ->
|
onFailure = { error ->
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
BookState.Data(
|
BookState.Data(
|
||||||
error = error.message ?: "data load err"
|
error = error.message ?: "Ошибка загрузки данных"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,7 +135,7 @@ class BookViewModel(private val bookRepo: BookRepository) : ViewModel() {
|
|||||||
onFailure = { error ->
|
onFailure = { error ->
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
state.copy(
|
state.copy(
|
||||||
error = error.message ?: "book error"
|
error = error.message ?: "Ошибка бронирования"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -142,14 +143,14 @@ class BookViewModel(private val bookRepo: BookRepository) : ViewModel() {
|
|||||||
} else {
|
} else {
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
state.copy(
|
state.copy(
|
||||||
error = "place !selected"
|
error = "Место не выбрано"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
state.copy(
|
state.copy(
|
||||||
error = "select place for booking"
|
error = "Выберите место для бронирования"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -183,7 +184,6 @@ sealed interface BookAction {
|
|||||||
object NavigateBackWithRefresh : BookAction
|
object NavigateBackWithRefresh : BookAction
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class BookViewModelFactory(private val context: Context) : ViewModelProvider.Factory {
|
class BookViewModelFactory(private val context: Context) : ViewModelProvider.Factory {
|
||||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||||
if (modelClass.isAssignableFrom(BookViewModel::class.java)) {
|
if (modelClass.isAssignableFrom(BookViewModel::class.java)) {
|
||||||
|
|||||||
@@ -168,7 +168,6 @@ fun MainScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Кнопки действий
|
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
@@ -205,7 +204,6 @@ fun MainScreen(
|
|||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
|
||||||
// Заголовок списка бронирований
|
|
||||||
if (currentState.bookings.isNotEmpty()) {
|
if (currentState.bookings.isNotEmpty()) {
|
||||||
Text(
|
Text(
|
||||||
text = "Мои бронирования:",
|
text = "Мои бронирования:",
|
||||||
@@ -226,7 +224,6 @@ fun MainScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Список бронирований
|
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
|
|||||||
@@ -16,11 +16,10 @@ import java.time.format.DateTimeFormatter
|
|||||||
import ru.myitschool.work.data.repo.AuthRepository
|
import ru.myitschool.work.data.repo.AuthRepository
|
||||||
import ru.myitschool.work.data.repo.MainRepository
|
import ru.myitschool.work.data.repo.MainRepository
|
||||||
|
|
||||||
|
class MainViewModel(
|
||||||
|
private val authRepo: AuthRepository,
|
||||||
class MainViewModel(private val authRepo: AuthRepository,
|
private val mainRepo: MainRepository
|
||||||
private val mainRepo: MainRepository)
|
) : ViewModel() {
|
||||||
: ViewModel() {
|
|
||||||
private val _uiState = MutableStateFlow<MainState>(MainState.Loading)
|
private val _uiState = MutableStateFlow<MainState>(MainState.Loading)
|
||||||
val uiState: StateFlow<MainState> = _uiState.asStateFlow()
|
val uiState: StateFlow<MainState> = _uiState.asStateFlow()
|
||||||
|
|
||||||
@@ -54,7 +53,6 @@ class MainViewModel(private val authRepo: AuthRepository,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
is MainIntent.ItemClick -> {
|
is MainIntent.ItemClick -> {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,7 +87,9 @@ class MainViewModel(private val authRepo: AuthRepository,
|
|||||||
onFailure = { error ->
|
onFailure = { error ->
|
||||||
_uiState.update {
|
_uiState.update {
|
||||||
MainState.Data(
|
MainState.Data(
|
||||||
error = error.message ?: "data load err"
|
userName = authRepo.getUserInfo()?.name ?: "",
|
||||||
|
userPhotoUrl = authRepo.getUserInfo()?.photo,
|
||||||
|
error = error.message ?: "data load error"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user