Skip to content

Commit

Permalink
Merge pull request #271 from School-of-Company/refactor/270-refactor-…
Browse files Browse the repository at this point in the history
…post-module

🔀 :: (#270) - refactor post module
  • Loading branch information
audgns10 authored Aug 18, 2024
2 parents e4ee22c + b23e2bd commit 1f92cbb
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 105 deletions.
87 changes: 49 additions & 38 deletions feature/post/src/main/java/com/msg/post/PostAddScreen.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.msg.post

import androidx.activity.ComponentActivity
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Column
Expand All @@ -16,15 +17,15 @@ import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusManager
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.msg.design_system.component.button.BitgoeulButton
import com.msg.design_system.component.button.ButtonState
import com.msg.design_system.component.button.DetailSettingButton
Expand All @@ -42,12 +43,20 @@ internal fun PostAddScreenRoute(
onSettingClicked: () -> Unit,
onAddClicked: () -> Unit
) {
val titleValue by viewModel.title.collectAsStateWithLifecycle()
val contentValue by viewModel.content.collectAsStateWithLifecycle()
val isFeedType = viewModel.currentFeedType.value

val typeText = when (isFeedType) {
FeedType.EMPLOYMENT -> "게시글"
FeedType.NOTICE -> "공지사항"
}

PostAddScreen(
onBackClicked = onBackClicked,
onSettingClicked = { title, content ->
viewModel.savedTitle.value = title
viewModel.savedContent.value = content
viewModel.onTitleChange(title)
viewModel.onContentChange(content)
onSettingClicked()
},
onAddClicked = { feedType, title, content ->
Expand All @@ -65,39 +74,37 @@ internal fun PostAddScreenRoute(
content = content
)
}
viewModel.savedContent.value = ""
viewModel.savedTitle.value = ""
viewModel.onContentChange("")
viewModel.onTitleChange("")
viewModel.isEditPage.value = false
onAddClicked()
},
savedTitle = viewModel.savedTitle.value,
savedContent = viewModel.savedContent.value,
feedType = viewModel.currentFeedType.value
title = titleValue,
content = contentValue,
onTitleChange = viewModel::onTitleChange,
onContentChange = viewModel::onContentChange,
maxTitleLength = 100,
typeText = typeText,
feedType = isFeedType,
)
}

@Composable
internal fun PostAddScreen(
modifier: Modifier = Modifier,
focusManager: FocusManager = LocalFocusManager.current,
scrollState: ScrollState = rememberScrollState(),
onBackClicked: () -> Unit,
onSettingClicked: (title: String, content: String) -> Unit,
onAddClicked: (feedType: FeedType, title: String, content: String) -> Unit,
savedTitle: String,
savedContent: String,
feedType: FeedType
title: String,
content: String,
onTitleChange: (String) -> Unit,
onContentChange: (String) -> Unit,
maxTitleLength: Int,
feedType: FeedType,
typeText: String
) {
val title = remember { mutableStateOf(savedTitle) }
val content = remember { mutableStateOf(savedContent) }

val maxTitleLength = 100

val scrollState = rememberScrollState()

val typeText = when (feedType) {
FeedType.EMPLOYMENT -> "게시글"
FeedType.NOTICE -> "공지사항"
}
BitgoeulAndroidTheme { colors, typography ->
Surface(
modifier = modifier
Expand Down Expand Up @@ -129,11 +136,11 @@ internal fun PostAddScreen(
) {
BasicTextField(
modifier = modifier.fillMaxWidth(),
value = title.value,
onValueChange = { if (it.length <= maxTitleLength) title.value = it },
value = title,
onValueChange = { if (it.length <= maxTitleLength) onTitleChange(it) },
textStyle = typography.titleSmall,
decorationBox = { innerTextField ->
if (title.value.isEmpty()) Text(
if (title.isEmpty()) Text(
text = "$typeText 제목 (100자 이내)",
style = typography.titleSmall,
color = colors.G1
Expand All @@ -143,18 +150,18 @@ internal fun PostAddScreen(
)
Spacer(modifier = modifier.height(16.dp))
HorizontalDivider(
modifier = Modifier.fillMaxWidth(),
modifier = modifier.fillMaxWidth(),
thickness = 1.dp,
color = colors.G9
)
Spacer(modifier = Modifier.height(16.dp))
Spacer(modifier = modifier.height(16.dp))
BasicTextField(
modifier = modifier.fillMaxWidth(),
value = content.value,
onValueChange = { if (it.length <= maxTitleLength) content.value = it },
value = content,
onValueChange = { if (it.length <= maxTitleLength) onContentChange(it) },
textStyle = typography.bodySmall,
decorationBox = { innerTextField ->
if (content.value.isEmpty()) Text(
if (content.isEmpty()) Text(
text = "본문 입력 (1000자 이내)",
style = typography.bodySmall,
color = colors.G1
Expand All @@ -169,7 +176,7 @@ internal fun PostAddScreen(
.padding(horizontal = 28.dp)
) {
HorizontalDivider(
modifier = Modifier.fillMaxWidth(),
modifier = modifier.fillMaxWidth(),
thickness = 1.dp,
color = colors.G9
)
Expand All @@ -178,15 +185,15 @@ internal fun PostAddScreen(
modifier = modifier.fillMaxWidth(),
type = typeText
) {
onSettingClicked(title.value, content.value)
onSettingClicked(title, content)
}
Spacer(modifier = modifier.height(8.dp))
BitgoeulButton(
modifier = modifier.fillMaxWidth(),
text = "$typeText 추가",
state = if (title.value.isNotEmpty() && content.value.isNotEmpty()) ButtonState.Enable else ButtonState.Disable
state = if (title.isNotEmpty() && content.isNotEmpty()) ButtonState.Enable else ButtonState.Disable
) {
onAddClicked(feedType, title.value, content.value)
onAddClicked(feedType, title, content)
}
Spacer(modifier = modifier.height(16.dp))
}
Expand All @@ -202,9 +209,13 @@ fun PostAddScreenPre() {
onBackClicked = {},
onSettingClicked = { _, _ -> },
onAddClicked = { _, _, _ -> },
savedTitle = "",
savedContent = "",
feedType = FeedType.NOTICE,
focusManager = LocalFocusManager.current
focusManager = LocalFocusManager.current,
title = "제목",
content = "내용",
onTitleChange = {},
onContentChange = {},
maxTitleLength = 100,
typeText = "공지사항"
)
}
24 changes: 11 additions & 13 deletions feature/post/src/main/java/com/msg/post/PostDetailScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.msg.post

import com.msg.model.enumdata.Authority
import androidx.activity.ComponentActivity
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
Expand All @@ -19,7 +20,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
Expand Down Expand Up @@ -96,16 +97,15 @@ private suspend fun getDetailPost(
@Composable
internal fun PostDetailScreen(
modifier: Modifier = Modifier,
scrollState: ScrollState = rememberScrollState(),
data: GetDetailPostEntity,
id: UUID,
role: Authority = Authority.ROLE_USER,
onDeleteClicked: (UUID) -> Unit,
onEditClicked: () -> Unit,
onBackClicked: () -> Unit
) {
val scrollState = rememberScrollState()

val isDialogShow = remember { mutableStateOf(false) }
val (isDialogShow, setIsDialogShow) = rememberSaveable { mutableStateOf(false) }

BitgoeulAndroidTheme { colors, typography ->
Box {
Expand Down Expand Up @@ -176,21 +176,19 @@ internal fun PostDetailScreen(
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
if (role == Authority.ROLE_ADMIN) {
Row(
modifier = Modifier.weight(0.45f)
) {
Row(modifier = modifier.weight(0.45f)) {
NegativeBitgoeulButton(
modifier = Modifier.fillMaxWidth(),
modifier = modifier.fillMaxWidth(),
text = "삭제하기"
) {
isDialogShow.value = true
setIsDialogShow(true)
}
}
Row(
modifier = Modifier.weight(0.45f)
modifier = modifier.weight(0.45f)
) {
BitgoeulButton(
modifier = Modifier.fillMaxWidth(),
modifier = modifier.fillMaxWidth(),
text = "수정하기"
) {
onEditClicked()
Expand All @@ -202,8 +200,8 @@ internal fun PostDetailScreen(
title = "게시글을 삭제하시겠습니까?",
negativeAction = "삭제",
content = data.title,
isVisible = isDialogShow.value,
onQuit = { isDialogShow.value = false },
isVisible = isDialogShow,
onQuit = { setIsDialogShow(false) },
onActionClicked = { onDeleteClicked(id) }
)
}
Expand Down
10 changes: 0 additions & 10 deletions feature/post/src/main/java/com/msg/post/PostDetailSettingScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.msg.post
import androidx.activity.ComponentActivity
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand All @@ -12,12 +11,9 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusManager
Expand Down Expand Up @@ -60,12 +56,6 @@ internal fun PostDetailSettingScreen(
onClickAddButton: () -> Unit,
onValueChanged: (index: Int, item: String) -> Unit
) {
val scrollState = rememberScrollState()
val interactionSource = remember { MutableInteractionSource() }

val addedLinks = links
val count = remember { mutableIntStateOf(links.count()) }

BitgoeulAndroidTheme { colors, typography ->
Column(
modifier = modifier
Expand Down
Loading

0 comments on commit 1f92cbb

Please sign in to comment.