diff --git a/feature/management/src/main/java/com/wap/wapp/feature/management/ManagementEventCard.kt b/feature/management/src/main/java/com/wap/wapp/feature/management/ManagementEventCard.kt index de1d41c1..e28ec3d7 100644 --- a/feature/management/src/main/java/com/wap/wapp/feature/management/ManagementEventCard.kt +++ b/feature/management/src/main/java/com/wap/wapp/feature/management/ManagementEventCard.kt @@ -41,6 +41,7 @@ internal fun ManagementEventCard( colors = CardDefaults.cardColors( containerColor = WappTheme.colors.black25, ), + modifier = Modifier.padding(horizontal = 8.dp), ) { Column( verticalArrangement = Arrangement.spacedBy(16.dp), diff --git a/feature/management/src/main/java/com/wap/wapp/feature/management/ManagementScreen.kt b/feature/management/src/main/java/com/wap/wapp/feature/management/ManagementScreen.kt index 6f68c01e..69a61d1c 100644 --- a/feature/management/src/main/java/com/wap/wapp/feature/management/ManagementScreen.kt +++ b/feature/management/src/main/java/com/wap/wapp/feature/management/ManagementScreen.kt @@ -1,3 +1,4 @@ + package com.wap.wapp.feature.management import android.content.Context @@ -5,12 +6,15 @@ import android.widget.Toast import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.padding +import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Scaffold import androidx.compose.material3.SnackbarHost import androidx.compose.material3.SnackbarHostState +import androidx.compose.material3.Text +import androidx.compose.material3.TopAppBar +import androidx.compose.material3.TopAppBarDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @@ -19,8 +23,10 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel +import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.wap.designsystem.WappTheme import com.wap.designsystem.component.WappMainTopBar import com.wap.wapp.core.commmon.extensions.toSupportingText @@ -37,11 +43,33 @@ internal fun ManagementRoute( viewModel: ManagementViewModel = hiltViewModel(), ) { var isShowDialog by rememberSaveable { mutableStateOf(false) } + val snackBarHostState = remember { SnackbarHostState() } + val surveyFormsState by viewModel.surveyFormList.collectAsStateWithLifecycle() + val eventsState by viewModel.eventList.collectAsStateWithLifecycle() val context = LocalContext.current + LaunchedEffect(true) { + viewModel.errorFlow.collectLatest { throwable -> + snackBarHostState.showSnackbar( + message = throwable.toSupportingText(), + ) + } + } + + LaunchedEffect(true) { + viewModel.managerState.collectLatest { managerState -> + when (managerState) { + ManagerState.Init -> {} + ManagerState.NonManager -> { isShowDialog = true } + ManagerState.Manager -> viewModel.getEventSurveyList() + } + } + } + ManagementScreen( - viewModel = viewModel, - showManageCodeDialog = { isShowDialog = true }, + snackBarHostState = snackBarHostState, + surveyFormsState = surveyFormsState, + eventsState = eventsState, navigateToEventRegistration = navigateToEventRegistration, navigateToSurveyRegistration = navigateToSurveyRegistration, navigateToSurveyCheck = navigateToSurveyCheck, @@ -58,73 +86,53 @@ internal fun ManagementRoute( } } +@OptIn(ExperimentalMaterial3Api::class) @Composable internal fun ManagementScreen( - viewModel: ManagementViewModel, - showManageCodeDialog: () -> Unit, + snackBarHostState: SnackbarHostState, + surveyFormsState: ManagementViewModel.SurveyFormsState, + eventsState: ManagementViewModel.EventsState, navigateToEventEdit: (String, String) -> Unit, navigateToEventRegistration: () -> Unit, navigateToSurveyRegistration: () -> Unit, navigateToSurveyCheck: (String) -> Unit, ) { - val snackBarHostState = remember { SnackbarHostState() } - val surveysState by viewModel.surveyList.collectAsState() - val eventsState by viewModel.eventList.collectAsState() - - LaunchedEffect(true) { - viewModel.managerState.collectLatest { managerState -> - when (managerState) { - ManagerState.Init -> {} - ManagerState.NonManager -> showManageCodeDialog() - ManagerState.Manager -> viewModel.getEventSurveyList() - } - } - - viewModel.errorFlow.collectLatest { throwable -> - snackBarHostState.showSnackbar( - message = throwable.toSupportingText(), - ) - } - } Scaffold( containerColor = WappTheme.colors.backgroundBlack, - contentWindowInsets = WindowInsets(0.dp), snackbarHost = { SnackbarHost(snackBarHostState) }, ) { paddingValues -> + WappMainTopBar( + titleRes = R.string.management, + contentRes = R.string.management_content, + ) + Column( modifier = Modifier.padding(paddingValues), ) { - WappMainTopBar( - titleRes = R.string.management, - contentRes = R.string.management_content, - ) - - ManagementEventContent( + ManagementEventCard( eventsState = eventsState, onCardClicked = navigateToEventEdit, onAddEventButtonClicked = navigateToEventRegistration, - modifier = Modifier.padding(horizontal = 8.dp), ) - ManagementSurveyContent( - surveysState = surveysState, + ManagementSurveyCard( + surveyFormsState = surveyFormsState, onCardClicked = navigateToSurveyCheck, onAddSurveyButtonClicked = navigateToSurveyRegistration, - modifier = Modifier - .padding(top = 20.dp) - .padding(horizontal = 8.dp), ) } } } @Composable -internal fun ManagementCardColor(currentIndex: Int): Color = - if (currentIndex % 2 == 0) { +internal fun ManagementCardColor(currentIndex: Int): Color { + return if (currentIndex % 2 == 0) { WappTheme.colors.black82 } else { WappTheme.colors.black42 } +} -private fun showToast(text: String, context: Context) = +private fun showToast(text: String, context: Context) { Toast.makeText(context, text, Toast.LENGTH_SHORT).show() +} diff --git a/feature/management/src/main/java/com/wap/wapp/feature/management/ManagementSurveyCard.kt b/feature/management/src/main/java/com/wap/wapp/feature/management/ManagementSurveyCard.kt index b94af7f8..c4ffce4f 100644 --- a/feature/management/src/main/java/com/wap/wapp/feature/management/ManagementSurveyCard.kt +++ b/feature/management/src/main/java/com/wap/wapp/feature/management/ManagementSurveyCard.kt @@ -43,7 +43,9 @@ internal fun ManagementSurveyCard( colors = CardDefaults.cardColors( containerColor = WappTheme.colors.black25, ), - modifier = Modifier.padding(top = 20.dp), + modifier = Modifier + .padding(top = 20.dp) + .padding(horizontal = 8.dp), ) { Column( verticalArrangement = Arrangement.spacedBy(16.dp),