Коммит 3e138bae создал по автору Radch-enko's avatar Radch-enko
Просмотр файлов

Refactor: simplify settings initialization and remove redundant navigation logic

- Integrated `CheckSettingsUseCase` in `RootComponent` for settings validation during initialization.
- Removed `onSettings` callback and associated navigation logic in `MainComponent`.
- Updated `RoomsResult` to calculate room index based on settings.
- Eliminated `isSettings` state and redundant settings handling in `State` and `MainScreen`.
- Improved `SettingsManager` initialization to prevent redundant assignments.
владелец a5e9ce5d
......@@ -3,6 +3,7 @@ package band.effective.office.tablet.root
import band.effective.office.tablet.core.domain.model.EventInfo
import band.effective.office.tablet.core.domain.model.RoomInfo
import band.effective.office.tablet.core.domain.model.Slot
import band.effective.office.tablet.core.domain.useCase.CheckSettingsUseCase
import band.effective.office.tablet.core.domain.useCase.ResourceDisposerUseCase
import band.effective.office.tablet.core.ui.common.ModalWindow
import band.effective.office.tablet.feature.bookingEditor.presentation.BookingEditorComponent
......@@ -18,7 +19,6 @@ import com.arkivanov.decompose.router.slot.dismiss
import com.arkivanov.decompose.router.stack.ChildStack
import com.arkivanov.decompose.router.stack.StackNavigation
import com.arkivanov.decompose.router.stack.childStack
import com.arkivanov.decompose.router.stack.push
import com.arkivanov.decompose.router.stack.replaceAll
import com.arkivanov.decompose.value.Value
import kotlinx.serialization.Serializable
......@@ -33,6 +33,7 @@ class RootComponent(
private val modalNavigation = SlotNavigation<ModalWindowsConfig>()
private val resourceDisposerUseCase: ResourceDisposerUseCase by inject()
private val checkSettingsUseCase: CheckSettingsUseCase by inject()
val modalWindowSlot = childSlot(
source = modalNavigation,
......@@ -42,7 +43,11 @@ class RootComponent(
val childStack: Value<ChildStack<*, Child>> = childStack(
source = navigation,
initialConfiguration = Config.Main,
initialConfiguration = if (checkSettingsUseCase().isEmpty()) {
Config.Settings
} else {
Config.Main
},
handleBackButton = true,
serializer = kotlinx.serialization.serializer<Config>(),
childFactory = ::createChild,
......@@ -60,7 +65,6 @@ class RootComponent(
Child.MainChild(
MainComponent(
componentContext = componentContext,
onSettings = { navigation.push(Config.Settings) },
onFastBooking = ::handleFastBookingIntent,
onOpenFreeRoomModal = ::handleFreeRoomIntent,
openBookingDialog = ::openBookingDialog,
......
......@@ -10,7 +10,9 @@ class SettingsManager(private val settings: Settings) {
private var currentInstance: SettingsManager? = null
fun init(settings: Settings) {
currentInstance = SettingsManager(settings)
if(currentInstance == null) {
currentInstance = SettingsManager(settings)
}
}
fun current(): SettingsManager {
......
......@@ -48,7 +48,6 @@ import org.koin.core.component.inject
@OptIn(ExperimentalTime::class)
class MainComponent(
private val componentContext: ComponentContext,
val onSettings: () -> Unit,
val onFastBooking: (minDuration: Int, selectedRoom: RoomInfo, rooms: List<RoomInfo>) -> Unit,
val onOpenFreeRoomModal: (currentEvent: EventInfo, roomName: String) -> Unit,
private val openBookingDialog: (event: EventInfo, room: String) -> Unit,
......@@ -91,11 +90,6 @@ class MainComponent(
* Initializes the component, checking settings and setting up timers and event listeners.
*/
private fun initializeComponent() {
// Check if settings are configured
if (checkSettingsUseCase().isEmpty()) {
onSettings()
}
// Load initial room data
loadRooms()
......@@ -322,11 +316,17 @@ class MainComponent(
indexSelectRoom = 0
)
is Either.Success<List<RoomInfo>> -> RoomsResult(
isSuccess = true,
roomList = result.data,
indexSelectRoom = state.value.indexSelectRoom,
)
is Either.Success<List<RoomInfo>> -> {
val selectedRoomName = checkSettingsUseCase()
val roomIndex =
result.data.indexOfFirst { it.name == selectedRoomName }
.coerceAtLeast(0)
RoomsResult(
isSuccess = true,
roomList = result.data,
indexSelectRoom = roomIndex,
)
}
else -> RoomsResult(
isSuccess = false,
......
......@@ -43,10 +43,6 @@ fun MainScreen(component: MainComponent) {
onOpenDateTimePickerModalRequest = {}, // TODO
)
}
state.isSettings -> {
component.onSettings()
}
}
}
}
......@@ -10,7 +10,6 @@ data class State(
val isError: Boolean,
val isDisconnect: Boolean,
val updatedEvent: Any,
val isSettings: Boolean,
val roomList: List<RoomInfo>,
val indexSelectRoom: Int,
val timeToNextEvent: Int,
......@@ -24,7 +23,6 @@ data class State(
isData = false,
isError = false,
isDisconnect = false,
isSettings = false,
updatedEvent = Any(),
roomList = listOf(),
indexSelectRoom = 0,
......
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать