Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,9 @@ internal fun MainScreen(
SharedTransitionLayout {
Scaffold(
snackbarHost = {
SnackbarHost(
hostState = snackBarHostState,
modifier = Modifier.navigationBarsPadding()
)
if (!bottomSheetController.isVisible) {
SnackbarHost(hostState = snackBarHostState)
}
}
) {
Box {
Expand Down Expand Up @@ -295,7 +294,13 @@ internal fun MainScreen(
sheetState = bottomSheetState,
dragHandle = null
) {
bottomSheetController.sheetContent()
Box {
bottomSheetController.sheetContent()
SnackbarHost(
hostState = snackBarHostState,
modifier = Modifier.align(Alignment.BottomCenter)
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fun PostScreen(
val commentState = postViewModel.postComments.observeAsState()
val commentText = remember { mutableStateOf(TextFieldValue("")) }
val showMentionSearchView = remember { mutableStateOf(false) }
val commentFocusRequester = FocusRequester()
val commentFocusRequester = remember { FocusRequester() }

// comment option
val onClickCommentDelete: (Long) -> Unit = { commentId ->
Expand Down Expand Up @@ -180,11 +180,30 @@ fun PostScreen(
val onClickCancelReply: () -> Unit = {
clearComment()
}
val postCommentCreateSuccess by postViewModel.postCommentCreateSuccess.observeAsState(Event(false))
if (postCommentCreateSuccess.getContentIfNotHandled() == true) {
clearComment()
keyboardController?.hide()
postViewModel.requestPostComment(postId)

val postCommentCreateState by postViewModel.postCommentCreateState.observeAsState()
LaunchedEffect(postCommentCreateState) {
postCommentCreateState?.status?.let { state ->
when (state) {
Status.LOADING -> {
coroutineScope.launch {
snackBarHostState.showSnackbar(context.getString(R.string.loading_default_message))
}
}

Status.SUCCESS -> {
clearComment()
keyboardController?.hide()
postViewModel.requestPostComment(postId)
}

Status.ERROR -> {
coroutineScope.launch {
snackBarHostState.showSnackbar(context.getString(R.string.network_error_dialog_default_message))
}
}
}
}
}

BackHandler(enabled = loadingVisible) {}
Expand Down Expand Up @@ -454,7 +473,7 @@ private fun PreviewPostScreen() {
userSearchKeyword = userSearchKeyword,
showMentionSearchView = showMentionSearchView,
userResults = userResults,
commentFocusRequester = FocusRequester(),
commentFocusRequester = remember { FocusRequester() },
onClickPostComment = { },
onClickProfile = { },
onClickPost = { },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,30 @@ fun CommentBottomSheetDialog(
val onClickCancelReply: () -> Unit = {
clearComment()
}
val postCommentCreateSuccess by postViewModel.postCommentCreateSuccess.observeAsState(Event(false))
if (postCommentCreateSuccess.getContentIfNotHandled() == true) {
clearComment()
keyboardController?.hide()
postViewModel.requestPostComment(postId)

val postCommentCreateState by postViewModel.postCommentCreateState.observeAsState()
LaunchedEffect(postCommentCreateState) {
postCommentCreateState?.status?.let { state ->
when (state) {
Status.LOADING -> {
coroutineScope.launch {
snackBarHostState.showSnackbar(context.getString(R.string.loading_default_message))
}
}

Status.SUCCESS -> {
clearComment()
keyboardController?.hide()
postViewModel.requestPostComment(postId)
}

Status.ERROR -> {
coroutineScope.launch {
snackBarHostState.showSnackbar(context.getString(R.string.network_error_dialog_default_message))
}
}
}
}
}

Surface(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class PostViewModel @Inject constructor(
private val _postDeleteSuccess = MutableSharedFlow<Status>()
val postDeleteSuccess = _postDeleteSuccess.asSharedFlow()

private val _postCommentCreateSuccess = MutableLiveData<Event<Boolean>>()
val postCommentCreateSuccess get() = _postCommentCreateSuccess
private val _postCommentCreateState = MutableLiveData<Resource<Boolean>>()
val postCommentCreateState: LiveData<Resource<Boolean>> get() = _postCommentCreateState

private val _postCommentDeleteSuccess = MutableLiveData<Event<Boolean>>()
val postCommentDeleteSuccess get() = _postCommentDeleteSuccess
Expand Down Expand Up @@ -241,37 +241,41 @@ class PostViewModel @Inject constructor(
}

fun requestCreatePostComment(contents: String, postId: Long, mentionedUser: List<SearchUser>) {
if (contents.isEmpty()) return
if (contents.isEmpty() || _postCommentCreateState.value?.status == Status.LOADING) return

viewModelScope.launch {
_postCommentCreateState.postValue(Resource.loading(null))
val mentionList = getMentionList(contents, mentionedUser)
requestCreatePostCommentUseCase(contents = contents, postId = postId, mentionList = mentionList).let { response ->
when (response) {
is NetworkResponse.Success -> {
_postCommentCreateSuccess.postValue(Event(true))
_postCommentCreateState.postValue(Resource.success(true))
}

else -> {
_postCommentCreateSuccess.postValue(Event(false))
_postCommentCreateState.postValue(Resource.error("댓글 작성 실패", false))
}
}
}
}
}

fun requestCreatePostCommentReply(reply: Pair<Long, Comment>, contents: String, postId: Long, mentionedUser: List<SearchUser>) {
if (contents.isEmpty()) return
if (contents.isEmpty() || _postCommentCreateState.value?.status == Status.LOADING) return

viewModelScope.launch {
_postCommentCreateState.postValue(Resource.loading(null))
val mentionList = getMentionList(contents, mentionedUser).toMutableList()
val (parentCommentId, comment) = reply
mentionList.add(MentionUser(comment.memberId, comment.nickname)) // 언급된 유저 리스트에 원본 댓글 유저 추가 (팔로우하지 않아도 답글 가능하므로 따로 추가)
requestCreatePostCommentReplyUseCase(commentId = parentCommentId, contents = contents, postId = postId, mentionList = mentionList).let { response ->
when (response) {
is NetworkResponse.Success -> {
_postCommentCreateSuccess.postValue(Event(true))
_postCommentCreateState.postValue(Resource.success(true))
}

else -> {
_postCommentCreateSuccess.postValue(Event(false))
_postCommentCreateState.postValue(Resource.error("답글 작성 실패", false))
}
}
}
Expand Down