Skip to content

Commit a9ab921

Browse files
authored
Merge pull request #300 from wespot-bff/feature/flash159483/#299
#299: 짜잘한 버그들 수정
2 parents 032d8f7 + 629a437 commit a9ab921

File tree

21 files changed

+282
-165
lines changed

21 files changed

+282
-165
lines changed

app/src/main/kotlin/com/bff/wespot/main/component/RestrictionBottomSheet.kt

Lines changed: 76 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ import androidx.compose.foundation.layout.fillMaxWidth
99
import androidx.compose.foundation.layout.padding
1010
import androidx.compose.material3.ExperimentalMaterial3Api
1111
import androidx.compose.material3.Text
12-
import androidx.compose.material3.rememberModalBottomSheetState
1312
import androidx.compose.runtime.Composable
13+
import androidx.compose.runtime.getValue
14+
import androidx.compose.runtime.mutableStateOf
15+
import androidx.compose.runtime.remember
1416
import androidx.compose.runtime.rememberCoroutineScope
17+
import androidx.compose.runtime.setValue
1518
import androidx.compose.ui.Modifier
1619
import androidx.compose.ui.platform.LocalContext
1720
import androidx.compose.ui.res.stringResource
@@ -25,7 +28,6 @@ import com.bff.wespot.main.model.RestrictionContent
2528
import com.bff.wespot.main.state.MainUiState
2629
import com.bff.wespot.navigation.Navigator
2730
import com.bff.wespot.ui.component.WSBottomSheet
28-
import kotlinx.coroutines.launch
2931

3032
@OptIn(ExperimentalMaterial3Api::class)
3133
@Composable
@@ -35,91 +37,88 @@ internal fun RestrictionBottomSheet(
3537
navigator: Navigator,
3638
) {
3739
val context = LocalContext.current
38-
val bottomSheetState = rememberModalBottomSheetState()
40+
var showBottomSheet by remember {
41+
mutableStateOf(true)
42+
}
3943
val coroutineScope = rememberCoroutineScope()
4044

41-
WSBottomSheet(
42-
sheetState = bottomSheetState,
43-
closeSheet = {
44-
coroutineScope.launch {
45-
bottomSheetState.hide()
46-
}
47-
},
48-
) {
49-
Column(
50-
modifier = Modifier.padding(28.dp),
51-
verticalArrangement = Arrangement.spacedBy(6.dp),
45+
if (showBottomSheet) {
46+
WSBottomSheet(
47+
closeSheet = {
48+
showBottomSheet = false
49+
},
5250
) {
53-
Text(
54-
text = stringResource(content.title),
55-
style = StaticTypeScale.Default.body1,
56-
modifier = Modifier.padding(bottom = 10.dp),
57-
color = WeSpotThemeManager.colors.txtTitleColor,
58-
)
51+
Column(
52+
modifier = Modifier.padding(28.dp),
53+
verticalArrangement = Arrangement.spacedBy(6.dp),
54+
) {
55+
Text(
56+
text = stringResource(content.title),
57+
style = StaticTypeScale.Default.body1,
58+
modifier = Modifier.padding(bottom = 10.dp),
59+
color = WeSpotThemeManager.colors.txtTitleColor,
60+
)
5961

60-
BulletPoint(text = stringResource(content.body1))
62+
BulletPoint(text = stringResource(content.body1))
6163

62-
BulletPoint(
63-
text = stringResource(
64-
content.body2,
65-
state.restriction.toKoreanDate(),
66-
),
67-
)
68-
69-
BulletPoint(text = stringResource(content.body3))
64+
BulletPoint(
65+
text = stringResource(
66+
content.body2,
67+
state.restriction.toKoreanDate(),
68+
),
69+
)
7070

71-
if (content.body4 != null) {
72-
BulletPoint(text = stringResource(content.body4))
73-
}
71+
BulletPoint(text = stringResource(content.body3))
7472

75-
if (content.buttonNumber == 1) {
76-
WSButton(
77-
onClick = {
78-
coroutineScope.launch {
79-
bottomSheetState.hide()
80-
}
81-
},
82-
text = stringResource(com.bff.wespot.auth.R.string.confirm),
83-
paddingValues = PaddingValues(
84-
start = 0.dp,
85-
end = 0.dp,
86-
top = 24.dp,
87-
bottom = 10.dp,
88-
),
89-
) {
90-
it.invoke()
73+
if (content.body4 != null) {
74+
BulletPoint(text = stringResource(content.body4))
9175
}
92-
} else {
93-
Row(
94-
modifier = Modifier
95-
.fillMaxWidth()
96-
.padding(top = 20.dp),
97-
horizontalArrangement = Arrangement.spacedBy(10.dp),
98-
) {
99-
Box(modifier = Modifier.weight(1f)) {
100-
WSButton(
101-
onClick = {
102-
coroutineScope.launch {
103-
bottomSheetState.hide()
104-
}
105-
},
106-
buttonType = WSButtonType.Secondary,
107-
text = stringResource(R.string.close),
108-
paddingValues = PaddingValues(0.dp),
109-
) {
110-
it()
111-
}
76+
77+
if (content.buttonNumber == 1) {
78+
WSButton(
79+
onClick = {
80+
showBottomSheet = false
81+
},
82+
text = stringResource(com.bff.wespot.auth.R.string.confirm),
83+
paddingValues = PaddingValues(
84+
start = 0.dp,
85+
end = 0.dp,
86+
top = 24.dp,
87+
bottom = 10.dp,
88+
),
89+
) {
90+
it.invoke()
11291
}
92+
} else {
93+
Row(
94+
modifier = Modifier
95+
.fillMaxWidth()
96+
.padding(top = 20.dp),
97+
horizontalArrangement = Arrangement.spacedBy(10.dp),
98+
) {
99+
Box(modifier = Modifier.weight(1f)) {
100+
WSButton(
101+
onClick = {
102+
showBottomSheet = false
103+
},
104+
buttonType = WSButtonType.Secondary,
105+
text = stringResource(R.string.close),
106+
paddingValues = PaddingValues(0.dp),
107+
) {
108+
it()
109+
}
110+
}
113111

114-
Box(modifier = Modifier.weight(1f)) {
115-
WSButton(
116-
onClick = {
117-
navigator.navigateToWebLink(context, state.kakaoChannel)
118-
},
119-
text = stringResource(com.bff.wespot.R.string.one_on_one),
120-
paddingValues = PaddingValues(0.dp),
121-
) {
122-
it()
112+
Box(modifier = Modifier.weight(1f)) {
113+
WSButton(
114+
onClick = {
115+
navigator.navigateToWebLink(context, state.kakaoChannel)
116+
},
117+
text = stringResource(com.bff.wespot.R.string.one_on_one),
118+
paddingValues = PaddingValues(0.dp),
119+
) {
120+
it()
121+
}
123122
}
124123
}
125124
}

core/model/src/main/kotlin/com/bff/wespot/model/community/PostDetail.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ data class PostDetail(
3131
val type: String,
3232
val icon: IconType,
3333
val text: RichTextType,
34+
val isSelected: Boolean,
3435
)
3536
}
3637

data-remote/src/main/kotlin/com/bff/wespot/data/remote/model/community/PostDetailDto.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ data class PostDetailDto(
4040
val type: String,
4141
val icon: IconTypeDto,
4242
val text: RichTextTypeDto,
43+
val isSelected: Boolean,
4344
)
4445
}
4546

@@ -133,6 +134,7 @@ private fun PostDetailDto.PostDetailContentDto.HeaderSectionDto.ButtonDto.toDoma
133134
type = type,
134135
icon = icon.toDomain(),
135136
text = text.toDomain(),
137+
isSelected = isSelected,
136138
)
137139

138140
private fun PostDetailDto.PostDetailContentDto.InfoSectionDto.toDomain() =

feature/community/presentation/src/main/java/com/bff/wespot/community/all/CommunityAllViewModel.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@ class CommunityAllViewModel @Inject constructor(
5151
}
5252

5353
is CommunityAllAction.OnScrapClick -> {
54-
onScrapClick(action.id)
54+
onScrapClick(action.id, action.isCurrentlyScrapped)
5555
}
5656

5757
is CommunityAllAction.OnReactionClick -> {
5858
onReactionClick(action.reaction, action.id)
5959
}
60+
6061
is CommunityAllAction.NavigateToDetailComments -> {
6162
postSideEffect(CommunityAllSideEffect.NavigateToDetail(action.id, true))
6263
}
@@ -76,11 +77,11 @@ class CommunityAllViewModel @Inject constructor(
7677
}
7778
}
7879

79-
private fun onScrapClick(postId: String) = intent {
80-
val isCurrentlyScrapped = state.scrappedPosts.contains(postId)
80+
private fun onScrapClick(postId: String, isCurrentlyScrapped: Boolean) = intent {
81+
val isInToggleSet = state.scrappedPosts.contains(postId)
8182
reduce {
8283
state.copy(
83-
scrappedPosts = if (isCurrentlyScrapped) {
84+
scrappedPosts = if (isInToggleSet) {
8485
state.scrappedPosts - postId
8586
} else {
8687
state.scrappedPosts + postId
@@ -93,7 +94,7 @@ class CommunityAllViewModel @Inject constructor(
9394
if (!result) {
9495
reduce {
9596
state.copy(
96-
scrappedPosts = if (isCurrentlyScrapped) {
97+
scrappedPosts = if (isInToggleSet) {
9798
state.scrappedPosts + postId
9899
} else {
99100
state.scrappedPosts - postId
@@ -110,10 +111,10 @@ class CommunityAllViewModel @Inject constructor(
110111
) = intent {
111112
when (reaction) {
112113
is FooterSectionUiModel.ReactionUiModel.LikeUiModel -> {
113-
val isCurrentlyLiked = state.likedPosts.contains(postId)
114+
val isInToggleSet = state.likedPosts.contains(postId)
114115
reduce {
115116
state.copy(
116-
likedPosts = if (isCurrentlyLiked) {
117+
likedPosts = if (isInToggleSet) {
117118
state.likedPosts - postId
118119
} else {
119120
state.likedPosts + postId
@@ -126,7 +127,7 @@ class CommunityAllViewModel @Inject constructor(
126127
if (!result) {
127128
reduce {
128129
state.copy(
129-
likedPosts = if (isCurrentlyLiked) {
130+
likedPosts = if (isInToggleSet) {
130131
state.likedPosts + postId
131132
} else {
132133
state.likedPosts - postId

feature/community/presentation/src/main/java/com/bff/wespot/community/all/screen/AllPostsScreen.kt

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,28 +48,37 @@ fun AllPostsScreen(
4848
reactions = item.content.footerSection.reactions.map { reaction ->
4949
when (reaction) {
5050
is PostItemUiModel.PostContentUiModel.FooterSectionUiModel.ReactionUiModel.LikeUiModel -> {
51-
val isLiked = uiState.likedPosts.contains(item.id)
52-
val currentCount =
53-
reaction.count.text.toIntOrNull() ?: 0
54-
val wasLikedBefore = reaction.selected
51+
val isLikedLocally =
52+
uiState.likedPosts.contains(item.id)
53+
val actualSelected = if (isLikedLocally) {
54+
!reaction.selected
55+
} else {
56+
reaction.selected
57+
}
5558

56-
val newCount = when {
57-
isLiked && !wasLikedBefore -> currentCount + 1
58-
!isLiked && wasLikedBefore -> currentCount - 1
59+
val serverSelected = reaction.selected
60+
val currentCount = reaction.count.text.toIntOrNull() ?: 0
61+
val adjustedCount = when {
62+
isLikedLocally && serverSelected -> currentCount - 1
63+
isLikedLocally && !serverSelected -> currentCount + 1
5964
else -> currentCount
6065
}
6166

6267
reaction.copy(
63-
selected = isLiked,
64-
count = reaction.count.copy(text = newCount.toString()),
68+
selected = actualSelected,
69+
count = reaction.count.copy(text = adjustedCount.toString()),
6570
)
6671
}
6772

6873
else -> reaction
6974
}
7075
},
7176
scrap = item.content.footerSection.scrap.copy(
72-
selected = uiState.scrappedPosts.contains(item.id),
77+
selected = if (uiState.scrappedPosts.contains(item.id)) {
78+
!item.content.footerSection.scrap.selected
79+
} else {
80+
item.content.footerSection.scrap.selected
81+
},
7382
),
7483
),
7584
)
@@ -83,6 +92,7 @@ fun AllPostsScreen(
8392
is PostItemUiModel.PostContentUiModel.FooterSectionUiModel.ReactionUiModel.ChatUiModel -> {
8493
action(CommunityAllAction.NavigateToDetailComments(item.id))
8594
}
95+
8696
else -> {
8797
action(
8898
CommunityAllAction.OnReactionClick(
@@ -103,7 +113,10 @@ fun AllPostsScreen(
103113
},
104114
scrapClick = {
105115
action(
106-
CommunityAllAction.OnScrapClick(item.id),
116+
CommunityAllAction.OnScrapClick(
117+
id = item.id,
118+
isCurrentlyScrapped = updatedContent.footerSection.scrap.selected,
119+
),
107120
)
108121
},
109122
)

feature/community/presentation/src/main/java/com/bff/wespot/community/all/state/CommunityAllAction.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ sealed interface CommunityAllAction {
2222

2323
data class OnScrapClick(
2424
val id: String,
25+
val isCurrentlyScrapped: Boolean,
2526
) : CommunityAllAction
2627

2728
data class NavigateToDetailComments(

0 commit comments

Comments
 (0)