Skip to content

Commit

Permalink
♻️ schedule モジュールに explicitApi を追加
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsutakein committed Nov 23, 2023
1 parent e8c75b2 commit 06dc426
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 23 deletions.
2 changes: 2 additions & 0 deletions feature/schedule/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ plugins {
android.namespace = "club.nito.feature.schedule"

kotlin {
explicitApi()

sourceSets {
commonMain {
dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package club.nito.feature.schedule

sealed class ScheduleListEvent {
data class NavigateToScheduleDetail(val scheduleId: String) : ScheduleListEvent()
public sealed class ScheduleListEvent {
public data class NavigateToScheduleDetail(val scheduleId: String) : ScheduleListEvent()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package club.nito.feature.schedule

import club.nito.core.domain.model.ParticipantSchedule

sealed class ScheduleListIntent {
data class ClickShowConfirmParticipateDialog(val schedule: ParticipantSchedule) : ScheduleListIntent()
data class ClickParticipateSchedule(val schedule: ParticipantSchedule) : ScheduleListIntent()
data object ClickDismissConfirmParticipateDialog : ScheduleListIntent()
public sealed class ScheduleListIntent {
public data class ClickShowConfirmParticipateDialog(val schedule: ParticipantSchedule) : ScheduleListIntent()
public data class ClickParticipateSchedule(val schedule: ParticipantSchedule) : ScheduleListIntent()
public data object ClickDismissConfirmParticipateDialog : ScheduleListIntent()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import club.nito.core.common.NitoDateTimeFormatter
import club.nito.core.domain.model.ParticipantSchedule
import club.nito.core.model.FetchMultipleContentResult

data class ScheduleListScreenUiState(
public data class ScheduleListScreenUiState(
val dateTimeFormatter: NitoDateTimeFormatter,
val scheduleList: FetchMultipleContentResult<ParticipantSchedule>,
val confirmParticipateDialog: ConfirmParticipateDialogUiState,
)

sealed class ConfirmParticipateDialogUiState {
data class Show(val schedule: ParticipantSchedule) : ConfirmParticipateDialogUiState()
data object Hide : ConfirmParticipateDialogUiState()
public sealed class ConfirmParticipateDialogUiState {
public data class Show(val schedule: ParticipantSchedule) : ConfirmParticipateDialogUiState()
public data object Hide : ConfirmParticipateDialogUiState()
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import moe.tlaster.precompose.viewmodel.viewModelScope

class ScheduleListViewModel internal constructor(
public class ScheduleListViewModel internal constructor(
getParticipantScheduleListUseCase: GetParticipantScheduleListUseCase,
val userMessageStateHolder: UserMessageStateHolder,
public val userMessageStateHolder: UserMessageStateHolder,
private val dateTimeFormatter: NitoDateTimeFormatter,
) : StateMachine(),
UserMessageStateHolder by userMessageStateHolder {
Expand All @@ -30,7 +30,7 @@ class ScheduleListViewModel internal constructor(
initialValue = FetchMultipleContentResult.Loading,
)

val uiState: StateFlow<ScheduleListScreenUiState> = buildUiState(
public val uiState: StateFlow<ScheduleListScreenUiState> = buildUiState(
showConfirmParticipateSchedule,
scheduleList,
) { showConfirmParticipateSchedule, scheduleList ->
Expand All @@ -44,25 +44,30 @@ class ScheduleListViewModel internal constructor(
}

private val _events = MutableStateFlow<List<ScheduleListEvent>>(emptyList())
val event: Flow<ScheduleListEvent?> = _events.map { it.firstOrNull() }
public val event: Flow<ScheduleListEvent?> = _events.map { it.firstOrNull() }

fun dispatch(intent: ScheduleListIntent) {
public fun dispatch(intent: ScheduleListIntent) {
viewModelScope.launch {
when (intent) {
is ScheduleListIntent.ClickShowConfirmParticipateDialog -> showConfirmParticipateSchedule.emit(intent.schedule)
is ScheduleListIntent.ClickShowConfirmParticipateDialog -> {
showConfirmParticipateSchedule.emit(intent.schedule)
}

is ScheduleListIntent.ClickParticipateSchedule -> {
showConfirmParticipateSchedule.emit(null)

val scheduledAt = dateTimeFormatter.formatDateTimeString(intent.schedule.scheduledAt)
userMessageStateHolder.showMessage("$scheduledAt に参加登録しました 🎉")
}

ScheduleListIntent.ClickDismissConfirmParticipateDialog -> showConfirmParticipateSchedule.emit(null)
ScheduleListIntent.ClickDismissConfirmParticipateDialog -> {
showConfirmParticipateSchedule.emit(null)
}
}
}
}

fun consume(event: ScheduleListEvent) {
public fun consume(event: ScheduleListEvent) {
viewModelScope.launch {
_events.emit(_events.value.filterNot { it == event })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import moe.tlaster.precompose.navigation.NavOptions
import moe.tlaster.precompose.navigation.Navigator
import moe.tlaster.precompose.navigation.RouteBuilder

const val scheduleNavigationRoute = "schedule_route"
public const val scheduleNavigationRoute: String = "schedule_route"

fun Navigator.navigateToSchedule(navOptions: NavOptions? = null) {
public fun Navigator.navigateToSchedule(navOptions: NavOptions? = null) {
this.navigate(scheduleNavigationRoute, navOptions)
}

fun RouteBuilder.scheduleScreen() {
public fun RouteBuilder.scheduleScreen() {
scene(
route = scheduleNavigationRoute,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import club.nito.core.ui.message.SnackbarMessageEffect
import club.nito.feature.schedule.component.ScheduleListSection

@Composable
fun ScheduleRoute(
public fun ScheduleRoute(
viewModel: ScheduleListViewModel = koinStateMachine(),
) {
viewModel.event.collectAsState(initial = null).value?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import club.nito.feature.schedule.ScheduleListViewModel
import org.koin.core.module.Module
import org.koin.dsl.module

val scheduleFeatureModule: Module = module {
public val scheduleFeatureModule: Module = module {
factory {
ScheduleListViewModel(
getParticipantScheduleListUseCase = get(),
Expand Down

0 comments on commit 06dc426

Please sign in to comment.