Skip to content

Commit e741a4d

Browse files
authored
Merge pull request #33 from Nexters/feature/block-create-gathering-when-no-gatherings
홈 화면에서 랜덤 제안 생성 시 모임이 없으면 팝업을 볼 수 있습니다.
2 parents 76e71f7 + 470190d commit e741a4d

File tree

4 files changed

+86
-6
lines changed

4 files changed

+86
-6
lines changed

feature/home/src/main/java/com/plottwist/feature/home/HomeContract.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ sealed class HomeSideEffect {
3939
data class NavigateToWebViewScreen(
4040
val encodedUrl: String
4141
) : HomeSideEffect()
42+
data object ShowNoGatheringsPopup: HomeSideEffect()
4243
}
4344

4445
enum class LoginState {

feature/home/src/main/java/com/plottwist/feature/home/HomeScreen.kt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@ import androidx.compose.foundation.layout.requiredWidth
1313
import androidx.compose.foundation.layout.size
1414
import androidx.compose.foundation.rememberScrollState
1515
import androidx.compose.foundation.verticalScroll
16+
import androidx.compose.material3.AlertDialog
1617
import androidx.compose.material3.Icon
1718
import androidx.compose.material3.IconButton
1819
import androidx.compose.material3.Text
20+
import androidx.compose.material3.TextButton
1921
import androidx.compose.runtime.Composable
22+
import androidx.compose.runtime.LaunchedEffect
2023
import androidx.compose.runtime.getValue
24+
import androidx.compose.runtime.mutableStateOf
25+
import androidx.compose.runtime.remember
26+
import androidx.compose.runtime.setValue
2127
import androidx.compose.ui.Alignment
2228
import androidx.compose.ui.Modifier
2329
import androidx.compose.ui.graphics.vector.ImageVector
@@ -31,14 +37,18 @@ import androidx.compose.ui.unit.dp
3137
import androidx.hilt.navigation.compose.hiltViewModel
3238
import com.plottwist.core.designsystem.R
3339
import com.plottwist.core.designsystem.component.TukTopAppBar
40+
import com.plottwist.core.designsystem.foundation.TukColorTokens.CoralRed500
3441
import com.plottwist.core.designsystem.foundation.TukColorTokens.Gray800
42+
import com.plottwist.core.designsystem.foundation.type.TukPretendardTypography
3543
import com.plottwist.core.designsystem.foundation.type.TukSerifTypography
3644
import com.plottwist.core.domain.model.Gatherings
3745
import com.plottwist.core.ui.component.StableImage
3846
import com.plottwist.feature.home.component.HomeBottomSheet
47+
import com.plottwist.feature.home.component.HomeBottomSheetAction
3948
import com.plottwist.feature.home.component.HomeBottomSheetState
4049
import com.plottwist.feature.home.component.HomeContent
4150
import com.plottwist.feature.home.component.HomeCreateGatheringPreview
51+
import kotlinx.coroutines.delay
4252
import org.orbitmvi.orbit.compose.collectAsState
4353
import org.orbitmvi.orbit.compose.collectSideEffect
4454

@@ -55,6 +65,15 @@ fun HomeScreen(
5565
) {
5666
val context = LocalContext.current
5767
val state by viewModel.collectAsState()
68+
var isShownNoGatheringsPopup by remember { mutableStateOf(false) }
69+
var homeBottomSheetAction: HomeBottomSheetAction by remember {
70+
mutableStateOf(HomeBottomSheetAction.IDLE)
71+
}
72+
73+
LaunchedEffect(homeBottomSheetAction) {
74+
delay(200)
75+
homeBottomSheetAction = HomeBottomSheetAction.IDLE
76+
}
5877

5978
viewModel.collectSideEffect { sideEffect ->
6079
when (sideEffect) {
@@ -84,6 +103,10 @@ fun HomeScreen(
84103
is HomeSideEffect.NavigateToWebViewScreen -> {
85104
navigateToWebView(sideEffect.encodedUrl)
86105
}
106+
107+
HomeSideEffect.ShowNoGatheringsPopup -> {
108+
isShownNoGatheringsPopup = !isShownNoGatheringsPopup
109+
}
87110
}
88111
}
89112

@@ -94,6 +117,7 @@ fun HomeScreen(
94117
whatLabel = state.whatLabel,
95118
loginState = state.loginState,
96119
gatherings = state.gatherings,
120+
homeBottomSheetAction = homeBottomSheetAction,
97121
onMyPageClick = {
98122
viewModel.handleAction(HomeAction.ClickMyPage)
99123
},
@@ -122,6 +146,35 @@ fun HomeScreen(
122146
viewModel.handleAction(HomeAction.ClickProposals)
123147
}
124148
)
149+
150+
if(isShownNoGatheringsPopup) {
151+
AlertDialog(
152+
text = {
153+
Text(
154+
text = "아직 만들어진 모임이 없어요.\n" +
155+
"우리, 먼저 모임부터 만들어볼까요?",
156+
style = TukPretendardTypography.body14R
157+
)
158+
},
159+
onDismissRequest = {
160+
isShownNoGatheringsPopup = false
161+
},
162+
confirmButton = {
163+
TextButton(
164+
onClick = {
165+
isShownNoGatheringsPopup = false
166+
homeBottomSheetAction = HomeBottomSheetAction.COLLAPSE
167+
}
168+
) {
169+
Text(
170+
text = "확인",
171+
style = TukPretendardTypography.body14M,
172+
color = CoralRed500
173+
)
174+
}
175+
},
176+
)
177+
}
125178
}
126179

127180
@Composable
@@ -131,6 +184,7 @@ private fun HomeScreen(
131184
whenLabel: String,
132185
whereLabel: String,
133186
whatLabel: String,
187+
homeBottomSheetAction: HomeBottomSheetAction,
134188
onWhenRefreshClick: () -> Unit,
135189
onWhereRefreshClick: () -> Unit,
136190
onWhatRefreshClick: () -> Unit,
@@ -192,6 +246,7 @@ private fun HomeScreen(
192246
whatLabel = whatLabel,
193247
sheetPeekHeight = BOTTOM_SHEET_PEEK_HEIGHT.dp,
194248
sheetFullHeight = BOTTOM_SHEET_FULL_HEIGHT.dp,
249+
homeBottomSheetAction = homeBottomSheetAction,
195250
onWhenRefreshClick = onWhenRefreshClick,
196251
onWhereRefreshClick = onWhereRefreshClick,
197252
onWhatRefreshClick = onWhatRefreshClick,
@@ -303,6 +358,7 @@ fun HomeScreenPreview(modifier: Modifier = Modifier) {
303358
whenLabel = "",
304359
whereLabel = "",
305360
whatLabel = "",
361+
homeBottomSheetAction = HomeBottomSheetAction.IDLE,
306362
onWhenRefreshClick = { },
307363
onWhereRefreshClick = { },
308364
onWhatRefreshClick = { },

feature/home/src/main/java/com/plottwist/feature/home/HomeViewModel.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,17 @@ class HomeViewModel @Inject constructor(
142142
private fun handleProposeClick() = intent {
143143
when (state.loginState) {
144144
LoginState.LoggedIn -> {
145-
postSideEffect(
146-
HomeSideEffect.NavigateToCreateProposalScreen(
147-
whereLabel = state.whereLabel,
148-
whenLabel = state.whenLabel,
149-
whatLabel = state.whatLabel
145+
if(state.gatherings.gatheringOverviews.isNotEmpty()) {
146+
postSideEffect(
147+
HomeSideEffect.NavigateToCreateProposalScreen(
148+
whereLabel = state.whereLabel,
149+
whenLabel = state.whenLabel,
150+
whatLabel = state.whatLabel
151+
)
150152
)
151-
)
153+
} else {
154+
postSideEffect(HomeSideEffect.ShowNoGatheringsPopup)
155+
}
152156
}
153157

154158
else -> {

feature/home/src/main/java/com/plottwist/feature/home/component/HomeBottomSheet.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ fun HomeBottomSheet(
5151
whatLabel: String,
5252
sheetPeekHeight: Dp,
5353
sheetFullHeight: Dp,
54+
homeBottomSheetAction: HomeBottomSheetAction,
5455
onChangedState: (HomeBottomSheetState) -> Unit,
5556
onWhenRefreshClick: () -> Unit,
5657
onWhereRefreshClick: () -> Unit,
@@ -63,6 +64,7 @@ fun HomeBottomSheet(
6364
whenLabel = whenLabel,
6465
whereLabel = whereLabel,
6566
whatLabel = whatLabel,
67+
homeBottomSheetAction = homeBottomSheetAction,
6668
onWhenRefreshClick = onWhenRefreshClick,
6769
onWhereRefreshClick = onWhereRefreshClick,
6870
onWhatRefreshClick = onWhatRefreshClick,
@@ -81,6 +83,7 @@ fun DraggableBottomSheet(
8183
whatLabel: String,
8284
sheetPeekHeight: Dp,
8385
sheetFullHeight: Dp,
86+
homeBottomSheetAction: HomeBottomSheetAction,
8487
onChangedState: (HomeBottomSheetState) -> Unit,
8588
onWhenRefreshClick: () -> Unit,
8689
onWhereRefreshClick: () -> Unit,
@@ -116,6 +119,18 @@ fun DraggableBottomSheet(
116119
}
117120
}
118121

122+
LaunchedEffect(homeBottomSheetAction) {
123+
when(homeBottomSheetAction) {
124+
HomeBottomSheetAction.EXPAND -> {
125+
offsetY.animateTo(0f)
126+
}
127+
HomeBottomSheetAction.COLLAPSE -> {
128+
offsetY.animateTo(sheetFullPx - sheetPeekPx)
129+
}
130+
else -> Unit
131+
}
132+
}
133+
119134
Box(
120135
modifier = modifier.fillMaxSize(),
121136
contentAlignment = Alignment.BottomCenter
@@ -250,3 +265,7 @@ fun DragHandle(
250265
enum class HomeBottomSheetState {
251266
EXPANDED, CHANGING, COLLAPSED
252267
}
268+
269+
enum class HomeBottomSheetAction {
270+
EXPAND, COLLAPSE, IDLE
271+
}

0 commit comments

Comments
 (0)