Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ スケジュール一覧画面から詳細画面への画面遷移を実装 #123

Merged
merged 4 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/ios/Modules/Sources/Navigation/RootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ public struct RootView: View {
)
.navigationBarBackButtonHidden(true)
case .scheduleList:
ComposeScheduleListScreen()
ComposeScheduleListScreen(
onScheduleItemClick: { scheduleId in
stateMachine.dispatch(intent: .routing(.scheduleDetail(scheduleId: scheduleId)))
}
)
case .scheduleDetail(let scheduleId):
ComposeScheduleDetailScreen(scheduleId: scheduleId)
case .settings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public struct ComposeScheduleDetailScreen: UIViewControllerRepresentable {
id: scheduleId,
fetchParticipantScheduleById: Container.shared.get(
type: FetchParticipantScheduleByIdUseCase.self),
participate: Container.shared.get(type: ParticipateUseCase.self),
userMessageStateHolder: Container.shared.get(type: UserMessageStateHolder.self),
dateTimeFormatter: Container.shared.get(type: CommonNitoDateFormatter.self)
)
Expand Down
11 changes: 9 additions & 2 deletions app/ios/Modules/Sources/Schedule/ComposeScheduleListScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import SwiftUI
import UIKit

public struct ComposeScheduleListScreen: UIViewControllerRepresentable {
public init() {}
private let onScheduleItemClick: (String) -> Void

public init(
onScheduleItemClick: @escaping (String) -> Void
) {
self.onScheduleItemClick = onScheduleItemClick
}

public func makeUIViewController(context: Context) -> UIViewController {
return ScheduleListScreen_iosKt.ScheduleListRouteViewController(
Expand All @@ -13,7 +19,8 @@ public struct ComposeScheduleListScreen: UIViewControllerRepresentable {
type: GetParticipantScheduleListUseCase.self),
userMessageStateHolder: Container.shared.get(type: UserMessageStateHolder.self),
dateFormatter: Container.shared.get(type: CommonNitoDateFormatter.self)
)
),
onScheduleItemClick: onScheduleItemClick
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ fun NitoNavHost(
)
},
)
scheduleListScreen()
scheduleListScreen(
onScheduleItemClick = navigator::navigateToScheduleDetail,
)
scheduleDetailScreen()
settingsScreen(
onSignedOut = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import kotlinx.serialization.Serializable

@Serializable
internal data class NetworkParticipantDeclaration(
val scheduleId: Long,
val memberId: Long,
val scheduleId: String,
val userId: String,
val comment: String,
)

internal fun ParticipantDeclaration.toNetworkModel(): NetworkParticipantDeclaration =
NetworkParticipantDeclaration(
scheduleId = scheduleId.toLong(),
memberId = memberId.toLong(),
scheduleId = scheduleId,
userId = memberId,
comment = comment,
)
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.Check
import androidx.compose.material.icons.filled.Send
import androidx.compose.material3.CircularProgressIndicator
Expand Down Expand Up @@ -123,11 +122,6 @@ private fun ScheduleDetailScreen(
text = "スケジュール詳細",
)
},
navigationIcon = {
IconButton(onClick = { }) {
Icon(Icons.Default.ArrowBack, contentDescription = "Back")
}
},
)
},
snackbarHost = { SnackbarHost(snackbarHostState) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package club.nito.feature.schedule.detail

import club.nito.core.common.NitoDateFormatter
import club.nito.core.domain.FetchParticipantScheduleByIdUseCase
import club.nito.core.domain.ParticipateUseCase
import club.nito.core.domain.model.ParticipantSchedule
import club.nito.core.model.FetchSingleContentResult
import club.nito.core.model.schedule.ScheduleId
Expand All @@ -18,6 +19,7 @@ import moe.tlaster.precompose.viewmodel.viewModelScope
public class ScheduleDetailStateMachine(
id: ScheduleId,
fetchParticipantScheduleById: FetchParticipantScheduleByIdUseCase,
private val participate: ParticipateUseCase,
public val userMessageStateHolder: UserMessageStateHolder,
private val dateTimeFormatter: NitoDateFormatter,
) : StateMachine(),
Expand Down Expand Up @@ -52,7 +54,9 @@ public class ScheduleDetailStateMachine(
viewModelScope.launch {
when (intent) {
is ScheduleDetailIntent.ClickParticipate -> {
showConfirmParticipateSchedule.emit(intent.schedule)
participate(intent.schedule.id, "")
val scheduledAt = dateTimeFormatter.formatDateTime(intent.schedule.scheduledAt)
userMessageStateHolder.showMessage("$scheduledAt に参加登録しました 🎉")
}

is ScheduleDetailIntent.ClickParticipateSchedule -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public val scheduleFeatureModule: Module = module {
ScheduleDetailStateMachine(
id = id,
fetchParticipantScheduleById = get(),
participate = get(),
userMessageStateHolder = get(),
dateTimeFormatter = get(),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package club.nito.feature.schedule.list

public sealed class ScheduleListEvent {
public data class NavigateToScheduleDetail(val scheduleId: String) : ScheduleListEvent()
/**
* Navigate to schedule detail screen
*/
public data class OnScheduleItemClick(val scheduleId: String) : ScheduleListEvent()
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.ui.Modifier
import club.nito.core.designsystem.component.CenterAlignedTopAppBar
import club.nito.core.designsystem.component.Scaffold
import club.nito.core.designsystem.component.Text
import club.nito.core.model.schedule.ScheduleId
import club.nito.core.ui.ConfirmParticipateDialog
import club.nito.core.ui.koinStateMachine
import club.nito.core.ui.message.SnackbarMessageEffect
Expand All @@ -23,11 +24,12 @@ import club.nito.feature.schedule.component.ScheduleListSection
@Composable
public fun ScheduleListRoute(
stateMachine: ScheduleListStateMachine = koinStateMachine(ScheduleListStateMachine::class),
onScheduleItemClick: (ScheduleId) -> Unit = {},
) {
stateMachine.event.collectAsState(initial = null).value?.let {
LaunchedEffect(it.hashCode()) {
when (it) {
is ScheduleListEvent.NavigateToScheduleDetail -> {}
is ScheduleListEvent.OnScheduleItemClick -> onScheduleItemClick(it.scheduleId)
}
stateMachine.consume(it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class ScheduleListStateMachine(
viewModelScope.launch {
when (intent) {
is ScheduleListIntent.ClickShowConfirmParticipateDialog -> {
showConfirmParticipateSchedule.emit(intent.schedule)
_events.emit(_events.value + ScheduleListEvent.OnScheduleItemClick(intent.schedule.id))
}

is ScheduleListIntent.ClickParticipateSchedule -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package club.nito.feature.schedule.list

import club.nito.core.model.schedule.ScheduleId
import moe.tlaster.precompose.navigation.NavOptions
import moe.tlaster.precompose.navigation.Navigator
import moe.tlaster.precompose.navigation.RouteBuilder
Expand All @@ -10,10 +11,14 @@ public fun Navigator.navigateToScheduleList(navOptions: NavOptions? = null) {
this.navigate(scheduleNavigationRoute, navOptions)
}

public fun RouteBuilder.scheduleListScreen() {
public fun RouteBuilder.scheduleListScreen(
onScheduleItemClick: (ScheduleId) -> Unit = {},
) {
scene(
route = scheduleNavigationRoute,
) {
ScheduleListRoute()
ScheduleListRoute(
onScheduleItemClick = onScheduleItemClick,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ package club.nito.feature.schedule.list

import androidx.compose.ui.window.ComposeUIViewController
import club.nito.core.designsystem.theme.NitoTheme
import club.nito.core.model.schedule.ScheduleId
import platform.UIKit.UIViewController

@Suppress("FunctionName")
public fun ScheduleListRouteViewController(
stateMachine: ScheduleListStateMachine,
onScheduleItemClick: (ScheduleId) -> Unit = {},
): UIViewController = ComposeUIViewController {
NitoTheme {
ScheduleListRoute(
stateMachine = stateMachine,
onScheduleItemClick = onScheduleItemClick,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import club.nito.core.model.schedule.ScheduleId

public sealed class TopScreenEvent {
/**
* Navigate to schedule list screen
* Navigate to schedule detail screen
*/
public data class OnRecentScheduleClicked(val scheduleId: ScheduleId) : TopScreenEvent()

Expand Down