mirror of
https://github.com/LiveFastEatTrashRaccoon/RaccoonForLemmy.git
synced 2025-02-03 13:37:34 +01:00
fix(common-ui): delete option in post detail
This commit is contained in:
parent
f96afd1d62
commit
970299fdac
@ -33,7 +33,7 @@ interface PostDetailMviModel :
|
||||
val canFetchMore: Boolean = true,
|
||||
val sortType: SortType = SortType.New,
|
||||
val comments: List<CommentModel> = emptyList(),
|
||||
val currentUserId: Int? = 0,
|
||||
val currentUserId: Int? = null,
|
||||
val swipeActionsEnabled: Boolean = true,
|
||||
)
|
||||
|
||||
|
@ -293,7 +293,7 @@ class PostDetailScreen(
|
||||
saved = statePost.saved,
|
||||
date = statePost.publishDate,
|
||||
options = buildList {
|
||||
if (post.creator?.id == uiState.currentUserId) {
|
||||
if (statePost.creator?.id == uiState.currentUserId) {
|
||||
add(stringResource(MR.strings.comment_action_delete))
|
||||
}
|
||||
},
|
||||
|
@ -41,14 +41,19 @@ class PostDetailViewModel(
|
||||
mvi.updateState {
|
||||
it.copy(
|
||||
sortType = sortType,
|
||||
post = post,
|
||||
)
|
||||
}
|
||||
mvi.scope?.launch {
|
||||
if (uiState.value.currentUserId == null) {
|
||||
val auth = identityRepository.authToken.value.orEmpty()
|
||||
val user = siteRepository.getCurrentUser(auth)
|
||||
mvi.updateState { it.copy(currentUserId = user?.id ?: 0) }
|
||||
val p = postsRepository.get(id = post.id, auth = auth) ?: post
|
||||
mvi.updateState {
|
||||
it.copy(
|
||||
currentUserId = user?.id ?: 0,
|
||||
post = p,
|
||||
)
|
||||
}
|
||||
}
|
||||
if (mvi.uiState.value.comments.isEmpty()) {
|
||||
refresh()
|
||||
|
@ -60,6 +60,11 @@ class PostsRepository(
|
||||
dto.map { it.toModel() }
|
||||
}.getOrElse { emptyList() }
|
||||
|
||||
suspend fun get(id: Int, auth: String? = null): PostModel? = runCatching {
|
||||
val dto = services.post.get(auth, id).body()?.postView
|
||||
dto?.toModel()
|
||||
}.getOrNull()
|
||||
|
||||
fun asUpVoted(post: PostModel, voted: Boolean) = post.copy(
|
||||
myVote = if (voted) 1 else 0,
|
||||
score = when {
|
||||
|
Loading…
x
Reference in New Issue
Block a user