Skip to content

Commit

Permalink
Fix sidebar showing admin screen to all users (#1401)
Browse files Browse the repository at this point in the history
  • Loading branch information
MV-GH authored Feb 24, 2024
1 parent 61e384b commit 200c375
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
9 changes: 1 addition & 8 deletions app/src/main/java/com/jerboa/ui/components/common/AppBars.kt
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,7 @@ fun BottomAppBarAll(
NavigationBar(
modifier = modifier,
) {
// Hide tabs according to permissions
val tabs = when (userViewType) {
UserViewType.Normal -> NavTab.entries.filter { it.userViewType == UserViewType.Normal }
UserViewType.AdminOrMod -> NavTab.entries.filter { it.userViewType != UserViewType.AdminOnly }
UserViewType.AdminOnly -> NavTab.entries
}

for (tab in tabs) {
for (tab in NavTab.getEntries(userViewType)) {
val selected = tab == selectedTab
val iconBadgeCount = when (tab) {
NavTab.Inbox -> unreadCounts
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/java/com/jerboa/ui/components/drawer/Drawer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.viewmodel.compose.viewModel
import com.jerboa.R
import com.jerboa.datatypes.UserViewType
import com.jerboa.datatypes.getDisplayName
import com.jerboa.datatypes.samplePerson
import com.jerboa.db.entity.Account
Expand Down Expand Up @@ -92,6 +93,7 @@ fun Drawer(
showBottomNav: Boolean,
closeDrawer: () -> Unit,
onSelectTab: (NavTab) -> Unit,
userViewType: UserViewType,
) {
var showAccountAddMode by rememberSaveable { mutableStateOf(false) }

Expand Down Expand Up @@ -124,6 +126,7 @@ fun Drawer(
closeDrawer = closeDrawer,
onSelectTab = onSelectTab,
onSwitchAnon = onSwitchAnon,
userViewType = userViewType,
)
}

Expand All @@ -147,6 +150,7 @@ fun DrawerContent(
closeDrawer: () -> Unit,
onSelectTab: (NavTab) -> Unit,
onSwitchAnon: () -> Unit,
userViewType: UserViewType,
) {
AnimatedVisibility(
visible = showAccountAddMode,
Expand Down Expand Up @@ -177,6 +181,7 @@ fun DrawerContent(
showBottomNav = showBottomNav,
onSelectTab = onSelectTab,
closeDrawer = closeDrawer,
userViewType = userViewType,
)
}

Expand All @@ -194,6 +199,7 @@ fun DrawerItemsMain(
showBottomNav: Boolean,
closeDrawer: () -> Unit,
onSelectTab: (NavTab) -> Unit,
userViewType: UserViewType,
) {
val listState = rememberLazyListState()

Expand Down Expand Up @@ -238,7 +244,7 @@ fun DrawerItemsMain(
}

if (!showBottomNav) {
items(NavTab.entries) {
items(NavTab.getEntries(userViewType)) {
IconAndTextDrawerItem(
text = stringResource(it.textId),
icon = it.iconOutlined,
Expand Down Expand Up @@ -314,6 +320,7 @@ fun DrawerItemsMainPreview() {
showBottomNav = false,
closeDrawer = {},
onSelectTab = {},
userViewType = UserViewType.Normal,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import com.jerboa.api.ApiState
import com.jerboa.closeDrawer
import com.jerboa.datatypes.UserViewType
import com.jerboa.db.entity.isAnon
import com.jerboa.db.entity.isReady
import com.jerboa.feat.BlurNSFW
Expand All @@ -34,6 +35,7 @@ fun MainDrawer(
onSelectTab: (NavTab) -> Unit,
blurNSFW: BlurNSFW,
showBottomNav: Boolean,
userViewType: UserViewType,
) {
val account = getCurrentAccount(accountViewModel)

Expand Down Expand Up @@ -108,5 +110,6 @@ fun MainDrawer(
showBottomNav = showBottomNav,
onSelectTab = onSelectTab,
closeDrawer = { closeDrawer(scope, drawerState) },
userViewType = userViewType,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ enum class NavTab(
userViewType = UserViewType.Normal,
needsLogin = true,
),
;

companion object {
fun getEntries(userViewType: UserViewType) =
when (userViewType) {
UserViewType.Normal -> NavTab.entries.filter { it.userViewType == UserViewType.Normal }
UserViewType.AdminOrMod -> NavTab.entries.filter { it.userViewType != UserViewType.AdminOnly }
UserViewType.AdminOnly -> NavTab.entries
}
}
}

@OptIn(
Expand Down Expand Up @@ -210,6 +220,7 @@ fun BottomNavActivity(
onCommunityClick = appState::toCommunity,
onSettingsClick = appState::toSettings,
onClickLogin = appState::toLogin,
userViewType = account.userViewType(),
)
},
)
Expand Down

0 comments on commit 200c375

Please sign in to comment.