Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide downvote button on comments and posts when disabled #502

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
6 changes: 6 additions & 0 deletions app/src/main/java/com/jerboa/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ class MainActivity : ComponentActivity() {
communityListViewModel = communityListViewModel,
appSettingsViewModel = appSettingsViewModel,
showVotingArrowsInListView = appSettings?.showVotingArrowsInListView ?: true,
siteViewModel = siteViewModel,
)
}
// Only necessary for community deeplinks
Expand Down Expand Up @@ -228,6 +229,7 @@ class MainActivity : ComponentActivity() {
postEditViewModel = postEditViewModel,
appSettingsViewModel = appSettingsViewModel,
showVotingArrowsInListView = appSettings?.showVotingArrowsInListView ?: true,
siteViewModel = siteViewModel,
)
}
composable(
Expand Down Expand Up @@ -269,6 +271,7 @@ class MainActivity : ComponentActivity() {
postEditViewModel = postEditViewModel,
appSettingsViewModel = appSettingsViewModel,
showVotingArrowsInListView = appSettings?.showVotingArrowsInListView ?: true,
siteViewModel = siteViewModel,
)
}
// Necessary for deep links
Expand Down Expand Up @@ -311,6 +314,7 @@ class MainActivity : ComponentActivity() {
postEditViewModel = postEditViewModel,
appSettingsViewModel = appSettingsViewModel,
showVotingArrowsInListView = appSettings?.showVotingArrowsInListView ?: true,
siteViewModel = siteViewModel,
)
}
composable(
Expand Down Expand Up @@ -439,6 +443,7 @@ class MainActivity : ComponentActivity() {
showCollapsedCommentContent = appSettings?.showCollapsedCommentContent ?: false,
showActionBarByDefault = appSettings?.showCommentActionBarByDefault ?: false,
showVotingArrowsInListView = appSettings?.showVotingArrowsInListView ?: true,
siteViewModel = siteViewModel,
)
}
composable(
Expand Down Expand Up @@ -472,6 +477,7 @@ class MainActivity : ComponentActivity() {
showCollapsedCommentContent = appSettings?.showCollapsedCommentContent ?: false,
showActionBarByDefault = appSettings?.showCommentActionBarByDefault ?: true,
showVotingArrowsInListView = appSettings?.showVotingArrowsInListView ?: true,
siteViewModel = siteViewModel,
)
}
composable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ fun LazyListScope.commentNodeItem(
account: Account?,
isCollapsedByParent: Boolean,
showActionBar: (commentId: Int) -> Boolean,
enableDownVotes: Boolean,
) {
val commentView = node.commentView
val commentId = commentView.comment.id
Expand Down Expand Up @@ -336,6 +337,7 @@ fun LazyListScope.commentNodeItem(
toggleActionBar(commentId)
},
account = account,
enableDownVotes = enableDownVotes,
)
}
}
Expand Down Expand Up @@ -383,6 +385,7 @@ fun LazyListScope.commentNodeItem(
isCollapsedByParent = isCollapsedByParent || !isExpanded(commentId),
showCollapsedCommentContent = showCollapsedCommentContent,
showActionBar = showActionBar,
enableDownVotes = enableDownVotes,
)
}
}
Expand Down Expand Up @@ -477,6 +480,7 @@ fun PostAndCommunityContextHeaderPreview() {
@Composable
fun CommentFooterLine(
commentView: CommentView,
enableDownVotes: Boolean,
instantScores: InstantScores,
onUpvoteClick: (commentView: CommentView) -> Unit,
onDownvoteClick: (commentView: CommentView) -> Unit,
Expand Down Expand Up @@ -550,14 +554,16 @@ fun CommentFooterLine(
showNumber = (instantScores.downvotes != 0),
account = account,
)
VoteGeneric(
myVote = instantScores.myVote,
votes = instantScores.downvotes,
item = commentView,
type = VoteType.Downvote,
onVoteClick = onDownvoteClick,
account = account,
)
if (enableDownVotes) {
VoteGeneric(
myVote = instantScores.myVote,
votes = instantScores.downvotes,
item = commentView,
type = VoteType.Downvote,
onVoteClick = onDownvoteClick,
account = account,
)
}
ActionBarButton(
icon = if (commentView.saved) { Icons.Filled.Bookmark } else {
Icons.Outlined.BookmarkBorder
Expand Down Expand Up @@ -617,6 +623,7 @@ fun CommentNodesPreview() {
isCollapsedByParent = false,
showCollapsedCommentContent = false,
showActionBarByDefault = true,
enableDownVotes = true,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ fun CommentNodes(
showCollapsedCommentContent: Boolean,
isCollapsedByParent: Boolean,
showActionBarByDefault: Boolean,
enableDownVotes: Boolean,
) {
// Holds the un-expanded comment ids
val unExpandedComments = remember { mutableStateListOf<Int>() }
Expand Down Expand Up @@ -84,6 +85,7 @@ fun CommentNodes(
showActionBar = { commentId ->
showActionBarByDefault xor commentsWithToggledActionBar.contains(commentId)
},
enableDownVotes = enableDownVotes,
)
}
}
Expand Down Expand Up @@ -114,6 +116,7 @@ fun LazyListScope.commentNodeItems(
showCollapsedCommentContent: Boolean,
isCollapsedByParent: Boolean,
showActionBar: (commentId: Int) -> Boolean,
enableDownVotes: Boolean,
) {
nodes.forEach { node ->
commentNodeItem(
Expand Down Expand Up @@ -142,6 +145,7 @@ fun LazyListScope.commentNodeItems(
showCollapsedCommentContent = showCollapsedCommentContent,
isCollapsedByParent = isCollapsedByParent,
showActionBar = showActionBar,
enableDownVotes = enableDownVotes,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.jerboa.ui.components.common.getCurrentAccount
import com.jerboa.ui.components.common.getPostViewMode
import com.jerboa.ui.components.community.list.CommunityListViewModel
import com.jerboa.ui.components.home.HomeViewModel
import com.jerboa.ui.components.home.SiteViewModel
import com.jerboa.ui.components.post.PostListings
import com.jerboa.ui.components.post.edit.PostEditViewModel

Expand All @@ -50,6 +51,7 @@ fun CommunityActivity(
postEditViewModel: PostEditViewModel,
appSettingsViewModel: AppSettingsViewModel,
showVotingArrowsInListView: Boolean,
siteViewModel: SiteViewModel,
) {
Log.d("jerboa", "got to community activity")

Expand Down Expand Up @@ -226,6 +228,7 @@ fun CommunityActivity(
taglines = null,
postViewMode = getPostViewMode(appSettingsViewModel),
showVotingArrowsInListView = showVotingArrowsInListView,
enableDownVotes = siteViewModel.siteRes?.site_view?.local_site?.enable_downvotes ?: true,
)
},
floatingActionButtonPosition = FabPosition.End,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ fun MainPostListingsContent(
},
account = account,
showVotingArrowsInListView = showVotingArrowsInListView,
enableDownVotes = siteViewModel.siteRes?.site_view?.local_site?.enable_downvotes ?: true,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import com.jerboa.ui.components.common.getPostViewMode
import com.jerboa.ui.components.common.simpleVerticalScrollbar
import com.jerboa.ui.components.community.CommunityLink
import com.jerboa.ui.components.home.HomeViewModel
import com.jerboa.ui.components.home.SiteViewModel
import com.jerboa.ui.components.post.PostListings
import com.jerboa.ui.components.post.edit.PostEditViewModel
import com.jerboa.ui.theme.MEDIUM_PADDING
Expand All @@ -63,6 +64,7 @@ fun PersonProfileActivity(
postEditViewModel: PostEditViewModel,
appSettingsViewModel: AppSettingsViewModel,
showVotingArrowsInListView: Boolean,
siteViewModel: SiteViewModel,
) {
Log.d("jerboa", "got to person activity")

Expand Down Expand Up @@ -144,6 +146,7 @@ fun PersonProfileActivity(
postEditViewModel = postEditViewModel,
appSettingsViewModel = appSettingsViewModel,
showVotingArrowsInListView = showVotingArrowsInListView,
enableDownVotes = siteViewModel.siteRes?.site_view?.local_site?.enable_downvotes ?: true,
)
},
bottomBar = {
Expand Down Expand Up @@ -198,6 +201,7 @@ fun UserTabs(
padding: PaddingValues,
appSettingsViewModel: AppSettingsViewModel,
showVotingArrowsInListView: Boolean,
enableDownVotes: Boolean,
) {
val tabTitles = if (savedMode) {
listOf(UserTab.Posts.name, UserTab.Comments.name)
Expand Down Expand Up @@ -398,6 +402,7 @@ fun UserTabs(
taglines = null,
postViewMode = getPostViewMode(appSettingsViewModel),
showVotingArrowsInListView = showVotingArrowsInListView,
enableDownVotes = enableDownVotes,
)
}
UserTab.Comments.ordinal -> {
Expand Down Expand Up @@ -534,6 +539,7 @@ fun UserTabs(
moderators = listOf(),
isCollapsedByParent = false,
showActionBarByDefault = appSettingsViewModel.appSettings.value?.showCommentActionBarByDefault ?: true,
enableDownVotes = enableDownVotes,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ import com.jerboa.ui.components.comment.reply.ReplyItem
import com.jerboa.ui.components.common.SimpleTopAppBar
import com.jerboa.ui.components.common.getCurrentAccount
import com.jerboa.ui.components.common.simpleVerticalScrollbar
import com.jerboa.ui.components.home.SiteViewModel
import com.jerboa.ui.components.post.edit.PostEditViewModel

@Composable
fun PostActivity(
postViewModel: PostViewModel,
siteViewModel: SiteViewModel,
accountViewModel: AccountViewModel,
commentEditViewModel: CommentEditViewModel,
commentReplyViewModel: CommentReplyViewModel,
Expand Down Expand Up @@ -80,6 +82,7 @@ fun PostActivity(
val depth = getDepthFromComment(firstComment)
val commentParentId = getCommentParentId(firstComment)
val showContextButton = depth != null && depth > 0
val enableDownVotes = siteViewModel.siteRes?.site_view?.local_site?.enable_downvotes ?: true
Scaffold(
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
Expand Down Expand Up @@ -209,6 +212,7 @@ fun PostActivity(
account = account,
postViewMode = PostViewMode.Card,
showVotingArrowsInListView = showVotingArrowsInListView,
enableDownVotes = enableDownVotes,
)
}
item(key = "${postView.post.id}_is_comment_view") {
Expand Down Expand Up @@ -298,8 +302,7 @@ fun PostActivity(
},
onReportClick = { commentView ->
navController.navigate(
"commentReport/${commentView.comment
.id}",
"commentReport/${commentView.comment.id}",
)
},
onCommentLinkClick = { commentView ->
Expand All @@ -310,7 +313,6 @@ fun PostActivity(
commentView = it,
account = account,
ctx = ctx,

)
},
onBlockCreatorClick = {
Expand All @@ -333,6 +335,7 @@ fun PostActivity(
showActionBar = { commentId ->
showActionBarByDefault xor commentsWithToggledActionBar.contains(commentId)
},
enableDownVotes = enableDownVotes,
)
}
}
Expand Down
Loading