Skip to content

Commit

Permalink
refactor: remove copy post bottom sheet (#64)
Browse files Browse the repository at this point in the history
* remove CopyPostBottomSheet

* remove associated NotificationCenterEvent

* update community detail

* update multi-community

* update post detail

* update post list

* update user detail
  • Loading branch information
AkesiSeli authored Nov 2, 2024
1 parent a8921b4 commit e987f46
Show file tree
Hide file tree
Showing 17 changed files with 251 additions and 319 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,6 @@ sealed interface NotificationCenterEvent {

data object ResetInbox : NotificationCenterEvent

data class CopyText(
val value: String,
) : NotificationCenterEvent

data class ChangedLikedType(
val value: Boolean,
) : NotificationCenterEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ interface CommunityDetailMviModel :
val value: Boolean,
) : Intent

data class Copy(
val value: String,
) : Intent

data object WillOpenDetail : Intent

data object UnhideCommunity : Intent
Expand Down Expand Up @@ -176,10 +172,6 @@ interface CommunityDetailMviModel :
val index: Int,
) : Effect

data class TriggerCopy(
val text: String,
) : Effect

data object Back : Effect
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ import com.livefast.eattrash.raccoonforlemmy.core.commonui.lemmyui.OptionId
import com.livefast.eattrash.raccoonforlemmy.core.commonui.lemmyui.PostCard
import com.livefast.eattrash.raccoonforlemmy.core.commonui.lemmyui.PostCardPlaceholder
import com.livefast.eattrash.raccoonforlemmy.core.commonui.lemmyui.di.getFabNestedScrollConnection
import com.livefast.eattrash.raccoonforlemmy.core.commonui.modals.CopyPostBottomSheet
import com.livefast.eattrash.raccoonforlemmy.core.commonui.modals.CustomModalBottomSheet
import com.livefast.eattrash.raccoonforlemmy.core.commonui.modals.CustomModalBottomSheetItem
import com.livefast.eattrash.raccoonforlemmy.core.commonui.modals.SelectLanguageDialog
Expand Down Expand Up @@ -208,6 +207,7 @@ class CommunityDetailScreen(
var shareBottomSheetUrls by remember { mutableStateOf<List<String>?>(null) }
var sortBottomSheetOpened by remember { mutableStateOf(false) }
var defaultSortBottomSheetOpened by remember { mutableStateOf(false) }
var copyPostBottomSheet by remember { mutableStateOf<PostModel?>(null) }

LaunchedEffect(model) {
model.effects
Expand Down Expand Up @@ -240,10 +240,6 @@ class CommunityDetailScreen(
}
}

is CommunityDetailMviModel.Effect.TriggerCopy -> {
clipboardManager.setText(AnnotatedString(text = effect.text))
}

is CommunityDetailMviModel.Effect.Failure -> {
snackbarHostState.showSnackbar(effect.message ?: genericError)
}
Expand Down Expand Up @@ -1306,20 +1302,9 @@ class CommunityDetailScreen(
post.text.takeIf { it.isNotBlank() },
).distinct()
if (texts.size == 1) {
model.reduce(
CommunityDetailMviModel.Intent.Copy(
texts.first(),
),
)
clipboardManager.setText(AnnotatedString(texts.first()))
} else {
val screen =
CopyPostBottomSheet(
post.title,
post.text,
)
navigationCoordinator.showBottomSheet(
screen,
)
copyPostBottomSheet = post
}
}

Expand Down Expand Up @@ -1629,5 +1614,40 @@ class CommunityDetailScreen(
},
)
}

copyPostBottomSheet?.also { post ->
val titleCanBeCopied = post.title.isNotBlank()
val textCanBeCopied = post.text.isNotBlank()
val texts = mutableListOf<String>()
val values = mutableListOf<CustomModalBottomSheetItem>()
if (titleCanBeCopied) {
texts += post.title
values += CustomModalBottomSheetItem(label = LocalStrings.current.copyTitle)
}
if (textCanBeCopied) {
texts += post.text
values += CustomModalBottomSheetItem(label = LocalStrings.current.copyText)
if (titleCanBeCopied) {
texts +=
buildString {
append(post.title)
append("\n")
append(post.text)
}
values += CustomModalBottomSheetItem(label = LocalStrings.current.copyBoth)
}
}
CustomModalBottomSheet(
title = LocalStrings.current.communityDetailBlock,
items = values,
onSelected = { index ->
copyPostBottomSheet = null
if (index != null) {
val text = texts[index]
clipboardManager.setText(AnnotatedString(text))
}
},
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,6 @@ class CommunityDetailViewModel(
.onEach { evt ->
shareHelper.share(evt.url)
}.launchIn(this)
notificationCenter
.subscribe(NotificationCenterEvent.CopyText::class)
.onEach {
emitEffect(CommunityDetailMviModel.Effect.TriggerCopy(it.value))
}.launchIn(this)

uiState
.map { it.searchText }
Expand Down Expand Up @@ -364,10 +359,6 @@ class CommunityDetailViewModel(
}

is CommunityDetailMviModel.Intent.SetSearch -> updateSearchText(intent.value)
is CommunityDetailMviModel.Intent.Copy ->
screenModelScope.launch {
emitEffect(CommunityDetailMviModel.Effect.TriggerCopy(intent.value))
}

CommunityDetailMviModel.Intent.WillOpenDetail -> {
val state = postPaginationManager.extractState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,34 @@ interface MultiCommunityMviModel :

data object HapticIndication : Intent

data class UpVotePost(val id: Long, val feedback: Boolean = false) : Intent
data class UpVotePost(
val id: Long,
val feedback: Boolean = false,
) : Intent

data class DownVotePost(val id: Long, val feedback: Boolean = false) : Intent
data class DownVotePost(
val id: Long,
val feedback: Boolean = false,
) : Intent

data class SavePost(val id: Long, val feedback: Boolean = false) : Intent
data class SavePost(
val id: Long,
val feedback: Boolean = false,
) : Intent

data class MarkAsRead(val id: Long) : Intent
data class MarkAsRead(
val id: Long,
) : Intent

data class Hide(val id: Long) : Intent
data class Hide(
val id: Long,
) : Intent

data object ClearRead : Intent

data class Share(val url: String) : Intent

data class Copy(val value: String) : Intent
data class Share(
val url: String,
) : Intent

data object WillOpenDetail : Intent
}
Expand Down Expand Up @@ -68,7 +81,5 @@ interface MultiCommunityMviModel :

sealed interface Effect {
data object BackToTop : Effect

data class TriggerCopy(val text: String) : Effect
}
}
Loading

0 comments on commit e987f46

Please sign in to comment.