Side panel now is a single big list with local branches and stashes expanded by default

This commit is contained in:
Abdelilah El Aissaoui 2022-06-26 18:46:48 +02:00
parent 64764c556d
commit 6599f2f861
7 changed files with 52 additions and 25 deletions

View File

@ -38,16 +38,6 @@ fun Remotes(
var showEditRemotesDialog by remember { mutableStateOf(false) }
val isExpanded by remotesViewModel.isExpanded.collectAsState()
val itemsCount = remember(remotes) {
val allBranches = remotes.filter { remoteView ->
remoteView.isExpanded // Only include in the branches count the nodes expanded
}.map { remoteView ->
remoteView.remoteInfo.branchesList
}.flatten()
allBranches.count() + remotes.count()
}
if (showEditRemotesDialog) {
EditRemotesDialog(
remotesViewModel = remotesViewModel,
@ -61,7 +51,6 @@ fun Remotes(
title = "Remotes",
icon = painterResource("cloud.svg"),
items = remotes,
itemsCountForMaxHeight = itemsCount,
isExpanded = isExpanded,
onExpand = { remotesViewModel.onExpand() },
contextItems = {

View File

@ -17,6 +17,7 @@ import androidx.compose.ui.unit.sp
import app.extensions.handMouseClickable
import app.git.DiffEntryType
import app.theme.*
import app.ui.components.ScrollableColumn
import app.ui.dialogs.AuthorDialog
import app.ui.dialogs.NewBranchDialog
import app.ui.dialogs.StashWithMessageDialog
@ -176,10 +177,7 @@ fun MainContentView(
Row {
HorizontalSplitPane {
first(minSize = 250.dp) {
Column(
modifier = Modifier
.fillMaxHeight()
) {
ScrollableColumn(modifier = Modifier.fillMaxHeight( )) {
Branches(
branchesViewModel = tabViewModel.branchesViewModel,
)

View File

@ -0,0 +1,43 @@
package app.ui.components
import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import app.theme.scrollbarHover
import app.theme.scrollbarNormal
@Composable
fun ScrollableColumn(
modifier: Modifier,
state: ScrollState = rememberScrollState(0),
content: @Composable ColumnScope.() -> Unit
) {
Box(
modifier = modifier,
) {
Column(
content = content,
modifier = Modifier
.verticalScroll(state)
)
VerticalScrollbar(
modifier = Modifier
.align(Alignment.CenterEnd)
.fillMaxHeight()
.padding(end = 2.dp),
style = LocalScrollbarStyle.current.copy(
unhoverColor = MaterialTheme.colors.scrollbarNormal,
hoverColor = MaterialTheme.colors.scrollbarHover,
),
adapter = rememberScrollbarAdapter(
scrollState = state
),
)
}
}

View File

@ -4,6 +4,7 @@ import androidx.compose.foundation.ContextMenuArea
import androidx.compose.foundation.ContextMenuItem
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.lazy.items
@ -23,13 +24,10 @@ fun <T> SideMenuPanel(
items: List<T>,
isExpanded: Boolean = false,
onExpand: () -> Unit,
itemsCountForMaxHeight: Int = items.count(),
itemContent: @Composable (T) -> Unit,
headerHoverIcon: @Composable (() -> Unit)? = null,
contextItems: () -> List<ContextMenuItem> = { emptyList() },
) {
val maxHeight = remember(items) { maxSidePanelHeight(itemsCountForMaxHeight) }
VerticalExpandable(
isExpanded = isExpanded,
onExpand = onExpand,
@ -46,13 +44,12 @@ fun <T> SideMenuPanel(
}
},
) {
ScrollableLazyColumn(
Column(
modifier = Modifier
.fillMaxWidth()
.heightIn(max = maxHeight.dp)
.background(MaterialTheme.colors.background)
) {
items(items) { item ->
for (item in items) {
itemContent(item)
}
}

View File

@ -15,7 +15,7 @@ class BranchesViewModel @Inject constructor(
private val remoteOperationsManager: RemoteOperationsManager,
private val tabState: TabState,
private val appPreferences: AppPreferences,
) : ExpandableViewModel() {
) : ExpandableViewModel(true) {
private val _branches = MutableStateFlow<List<Ref>>(listOf())
val branches: StateFlow<List<Ref>>
get() = _branches

View File

@ -3,8 +3,8 @@ package app.viewmodels
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
abstract class ExpandableViewModel {
private val _isExpanded = MutableStateFlow(true)
abstract class ExpandableViewModel(expandedDefault: Boolean = false) {
private val _isExpanded = MutableStateFlow(expandedDefault)
val isExpanded: StateFlow<Boolean> = _isExpanded
fun onExpand() {

View File

@ -13,7 +13,7 @@ import javax.inject.Inject
class StashesViewModel @Inject constructor(
private val stashManager: StashManager,
private val tabState: TabState,
) : ExpandableViewModel() {
) : ExpandableViewModel(true) {
private val _stashStatus = MutableStateFlow<StashStatus>(StashStatus.Loaded(listOf()))
val stashStatus: StateFlow<StashStatus>
get() = _stashStatus