Side menu items expand state is now stored in the viewModels to restore it's value after changing tabs
This commit is contained in:
parent
8650b1a43c
commit
855b57196d
@ -26,6 +26,7 @@ fun Branches(
|
|||||||
) {
|
) {
|
||||||
val branches by branchesViewModel.branches.collectAsState()
|
val branches by branchesViewModel.branches.collectAsState()
|
||||||
val currentBranchState = branchesViewModel.currentBranch.collectAsState()
|
val currentBranchState = branchesViewModel.currentBranch.collectAsState()
|
||||||
|
val isExpanded by branchesViewModel.isExpanded.collectAsState()
|
||||||
val currentBranch = currentBranchState.value
|
val currentBranch = currentBranchState.value
|
||||||
|
|
||||||
val (mergeBranch, setMergeBranch) = remember { mutableStateOf<Ref?>(null) }
|
val (mergeBranch, setMergeBranch) = remember { mutableStateOf<Ref?>(null) }
|
||||||
@ -35,6 +36,8 @@ fun Branches(
|
|||||||
title = "Local branches",
|
title = "Local branches",
|
||||||
icon = painterResource("branch.svg"),
|
icon = painterResource("branch.svg"),
|
||||||
items = branches,
|
items = branches,
|
||||||
|
isExpanded = isExpanded,
|
||||||
|
onExpand = { branchesViewModel.onExpand() },
|
||||||
itemContent = { branch ->
|
itemContent = { branch ->
|
||||||
BranchLineEntry(
|
BranchLineEntry(
|
||||||
branch = branch,
|
branch = branch,
|
||||||
|
@ -33,6 +33,7 @@ fun Remotes(
|
|||||||
) {
|
) {
|
||||||
val remotes by remotesViewModel.remotes.collectAsState()
|
val remotes by remotesViewModel.remotes.collectAsState()
|
||||||
var showEditRemotesDialog by remember { mutableStateOf(false) }
|
var showEditRemotesDialog by remember { mutableStateOf(false) }
|
||||||
|
val isExpanded by remotesViewModel.isExpanded.collectAsState()
|
||||||
|
|
||||||
val itemsCount = remember(remotes) {
|
val itemsCount = remember(remotes) {
|
||||||
val allBranches = remotes.filter { remoteView ->
|
val allBranches = remotes.filter { remoteView ->
|
||||||
@ -58,6 +59,8 @@ fun Remotes(
|
|||||||
icon = painterResource("cloud.svg"),
|
icon = painterResource("cloud.svg"),
|
||||||
items = remotes,
|
items = remotes,
|
||||||
itemsCountForMaxHeight = itemsCount,
|
itemsCountForMaxHeight = itemsCount,
|
||||||
|
isExpanded = isExpanded,
|
||||||
|
onExpand = { remotesViewModel.onExpand() },
|
||||||
contextItems = {
|
contextItems = {
|
||||||
remoteContextMenu { showEditRemotesDialog = true }
|
remoteContextMenu { showEditRemotesDialog = true }
|
||||||
},
|
},
|
||||||
@ -84,7 +87,7 @@ fun Remotes(
|
|||||||
onDeleteBranch = { branch -> remotesViewModel.deleteRemoteBranch(branch) },
|
onDeleteBranch = { branch -> remotesViewModel.deleteRemoteBranch(branch) },
|
||||||
onRemoteClicked = { remotesViewModel.onRemoteClicked(remoteInfo) }
|
onRemoteClicked = { remotesViewModel.onRemoteClicked(remoteInfo) }
|
||||||
)
|
)
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import androidx.compose.foundation.ContextMenuItem
|
|||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import app.ui.components.SideMenuPanel
|
import app.ui.components.SideMenuPanel
|
||||||
import app.ui.components.SideMenuSubentry
|
import app.ui.components.SideMenuSubentry
|
||||||
@ -21,6 +22,7 @@ fun Stashes(
|
|||||||
) {
|
) {
|
||||||
val stashStatusState = stashesViewModel.stashStatus.collectAsState()
|
val stashStatusState = stashesViewModel.stashStatus.collectAsState()
|
||||||
val stashStatus = stashStatusState.value
|
val stashStatus = stashStatusState.value
|
||||||
|
val isExpanded by stashesViewModel.isExpanded.collectAsState()
|
||||||
|
|
||||||
val stashList = if (stashStatus is StashStatus.Loaded)
|
val stashList = if (stashStatus is StashStatus.Loaded)
|
||||||
stashStatus.stashes
|
stashStatus.stashes
|
||||||
@ -31,6 +33,8 @@ fun Stashes(
|
|||||||
title = "Stashes",
|
title = "Stashes",
|
||||||
icon = painterResource("stash.svg"),
|
icon = painterResource("stash.svg"),
|
||||||
items = stashList,
|
items = stashList,
|
||||||
|
isExpanded = isExpanded,
|
||||||
|
onExpand = { stashesViewModel.onExpand() },
|
||||||
itemContent = { stash ->
|
itemContent = { stash ->
|
||||||
StashRow(
|
StashRow(
|
||||||
stash = stash,
|
stash = stash,
|
||||||
|
@ -4,6 +4,7 @@ import androidx.compose.foundation.ContextMenuArea
|
|||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import app.extensions.simpleName
|
import app.extensions.simpleName
|
||||||
import app.ui.components.SideMenuPanel
|
import app.ui.components.SideMenuPanel
|
||||||
@ -19,11 +20,14 @@ fun Tags(
|
|||||||
) {
|
) {
|
||||||
val tagsState = tagsViewModel.tags.collectAsState()
|
val tagsState = tagsViewModel.tags.collectAsState()
|
||||||
val tags = tagsState.value
|
val tags = tagsState.value
|
||||||
|
val isExpanded by tagsViewModel.isExpanded.collectAsState()
|
||||||
|
|
||||||
SideMenuPanel(
|
SideMenuPanel(
|
||||||
title = "Tags",
|
title = "Tags",
|
||||||
items = tags,
|
items = tags,
|
||||||
icon = painterResource("tag.svg"),
|
icon = painterResource("tag.svg"),
|
||||||
|
isExpanded = isExpanded,
|
||||||
|
onExpand = { tagsViewModel.onExpand() },
|
||||||
itemContent = { tag ->
|
itemContent = { tag ->
|
||||||
TagRow(
|
TagRow(
|
||||||
tag = tag,
|
tag = tag,
|
||||||
|
@ -10,21 +10,6 @@ import androidx.compose.runtime.mutableStateOf
|
|||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
|
||||||
@OptIn(ExperimentalAnimationApi::class)
|
|
||||||
@Composable
|
|
||||||
fun VerticalExpandable(
|
|
||||||
isExpanded: MutableState<Boolean> = remember { mutableStateOf(true) },
|
|
||||||
header: @Composable () -> Unit,
|
|
||||||
child: @Composable () -> Unit,
|
|
||||||
) {
|
|
||||||
VerticalExpandable(
|
|
||||||
isExpanded = isExpanded.value,
|
|
||||||
onExpand = { isExpanded.value = !isExpanded.value },
|
|
||||||
header = header,
|
|
||||||
child = child,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@OptIn(ExperimentalAnimationApi::class)
|
@OptIn(ExperimentalAnimationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun VerticalExpandable(
|
fun VerticalExpandable(
|
||||||
|
@ -21,6 +21,8 @@ fun <T> SideMenuPanel(
|
|||||||
title: String,
|
title: String,
|
||||||
icon: Painter? = null,
|
icon: Painter? = null,
|
||||||
items: List<T>,
|
items: List<T>,
|
||||||
|
isExpanded: Boolean = false,
|
||||||
|
onExpand: () -> Unit,
|
||||||
itemsCountForMaxHeight: Int = items.count(),
|
itemsCountForMaxHeight: Int = items.count(),
|
||||||
itemContent: @Composable (T) -> Unit,
|
itemContent: @Composable (T) -> Unit,
|
||||||
headerHoverIcon: @Composable (() -> Unit)? = null,
|
headerHoverIcon: @Composable (() -> Unit)? = null,
|
||||||
@ -29,6 +31,8 @@ fun <T> SideMenuPanel(
|
|||||||
val maxHeight = remember(items) { maxSidePanelHeight(itemsCountForMaxHeight) }
|
val maxHeight = remember(items) { maxSidePanelHeight(itemsCountForMaxHeight) }
|
||||||
|
|
||||||
VerticalExpandable(
|
VerticalExpandable(
|
||||||
|
isExpanded = isExpanded,
|
||||||
|
onExpand = onExpand,
|
||||||
header = {
|
header = {
|
||||||
ContextMenuArea(
|
ContextMenuArea(
|
||||||
items = contextItems
|
items = contextItems
|
||||||
|
@ -13,7 +13,7 @@ class BranchesViewModel @Inject constructor(
|
|||||||
private val mergeManager: MergeManager,
|
private val mergeManager: MergeManager,
|
||||||
private val remoteOperationsManager: RemoteOperationsManager,
|
private val remoteOperationsManager: RemoteOperationsManager,
|
||||||
private val tabState: TabState,
|
private val tabState: TabState,
|
||||||
) {
|
) : ExpandableViewModel() {
|
||||||
private val _branches = MutableStateFlow<List<Ref>>(listOf())
|
private val _branches = MutableStateFlow<List<Ref>>(listOf())
|
||||||
val branches: StateFlow<List<Ref>>
|
val branches: StateFlow<List<Ref>>
|
||||||
get() = _branches
|
get() = _branches
|
||||||
|
13
src/main/kotlin/app/viewmodels/ExpandableViewModel.kt
Normal file
13
src/main/kotlin/app/viewmodels/ExpandableViewModel.kt
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package app.viewmodels
|
||||||
|
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
|
||||||
|
abstract class ExpandableViewModel {
|
||||||
|
private val _isExpanded = MutableStateFlow(true)
|
||||||
|
val isExpanded: StateFlow<Boolean> = _isExpanded
|
||||||
|
|
||||||
|
fun onExpand() {
|
||||||
|
_isExpanded.value = !isExpanded.value
|
||||||
|
}
|
||||||
|
}
|
@ -17,7 +17,7 @@ class RemotesViewModel @Inject constructor(
|
|||||||
private val remoteOperationsManager: RemoteOperationsManager,
|
private val remoteOperationsManager: RemoteOperationsManager,
|
||||||
private val branchesManager: BranchesManager,
|
private val branchesManager: BranchesManager,
|
||||||
private val tabState: TabState,
|
private val tabState: TabState,
|
||||||
) {
|
) : ExpandableViewModel() {
|
||||||
private val _remotes = MutableStateFlow<List<RemoteView>>(listOf())
|
private val _remotes = MutableStateFlow<List<RemoteView>>(listOf())
|
||||||
val remotes: StateFlow<List<RemoteView>>
|
val remotes: StateFlow<List<RemoteView>>
|
||||||
get() = _remotes
|
get() = _remotes
|
||||||
|
@ -13,7 +13,7 @@ import javax.inject.Inject
|
|||||||
class StashesViewModel @Inject constructor(
|
class StashesViewModel @Inject constructor(
|
||||||
private val stashManager: StashManager,
|
private val stashManager: StashManager,
|
||||||
private val tabState: TabState,
|
private val tabState: TabState,
|
||||||
) {
|
) : ExpandableViewModel() {
|
||||||
private val _stashStatus = MutableStateFlow<StashStatus>(StashStatus.Loaded(listOf()))
|
private val _stashStatus = MutableStateFlow<StashStatus>(StashStatus.Loaded(listOf()))
|
||||||
val stashStatus: StateFlow<StashStatus>
|
val stashStatus: StateFlow<StashStatus>
|
||||||
get() = _stashStatus
|
get() = _stashStatus
|
||||||
|
@ -16,7 +16,7 @@ class TagsViewModel @Inject constructor(
|
|||||||
private val tabState: TabState,
|
private val tabState: TabState,
|
||||||
private val branchesManager: BranchesManager,
|
private val branchesManager: BranchesManager,
|
||||||
private val tagsManager: TagsManager,
|
private val tagsManager: TagsManager,
|
||||||
) {
|
) : ExpandableViewModel() {
|
||||||
private val _tags = MutableStateFlow<List<Ref>>(listOf())
|
private val _tags = MutableStateFlow<List<Ref>>(listOf())
|
||||||
val tags: StateFlow<List<Ref>>
|
val tags: StateFlow<List<Ref>>
|
||||||
get() = _tags
|
get() = _tags
|
||||||
|
Loading…
Reference in New Issue
Block a user