diff --git a/src/main/kotlin/app/git/StatusManager.kt b/src/main/kotlin/app/git/StatusManager.kt index 17a9d11..9d4a9e4 100644 --- a/src/main/kotlin/app/git/StatusManager.kt +++ b/src/main/kotlin/app/git/StatusManager.kt @@ -85,8 +85,6 @@ class StatusManager @Inject constructor( dirCacheEditor.commit() completedWithErrors = false - -// loadStatus(git) } finally { if (completedWithErrors) dirCache.unlock() diff --git a/src/main/kotlin/app/ui/UncommitedChanges.kt b/src/main/kotlin/app/ui/UncommitedChanges.kt index c639af7..0e6daba 100644 --- a/src/main/kotlin/app/ui/UncommitedChanges.kt +++ b/src/main/kotlin/app/ui/UncommitedChanges.kt @@ -51,8 +51,9 @@ fun UncommitedChanges( onUnstagedDiffEntrySelected: (DiffEntry) -> Unit, ) { val stageStatusState = statusViewModel.stageStatus.collectAsState() - val stageStatus = stageStatusState.value + val commitMessage by statusViewModel.commitMessage.collectAsState() + val stageStatus = stageStatusState.value val staged: List val unstaged: List if (stageStatus is StageStatus.Loaded) { @@ -74,11 +75,10 @@ fun UncommitedChanges( unstaged = listOf() // return empty lists if still loading } - var commitMessage by remember { mutableStateOf("") } val doCommit = { statusViewModel.commit(commitMessage) onStagedDiffEntrySelected(null) - commitMessage = "" + statusViewModel.newCommitMessage = "" } val canCommit = commitMessage.isNotEmpty() && staged.isNotEmpty() @@ -158,7 +158,7 @@ fun UncommitedChanges( false }, value = commitMessage, - onValueChange = { commitMessage = it }, + onValueChange = { statusViewModel.newCommitMessage = it }, label = { Text("Write your commit message here", fontSize = 14.sp) }, colors = TextFieldDefaults.textFieldColors(backgroundColor = MaterialTheme.colors.background), textStyle = TextStyle.Default.copy(fontSize = 14.sp), diff --git a/src/main/kotlin/app/viewmodels/StatusViewModel.kt b/src/main/kotlin/app/viewmodels/StatusViewModel.kt index 6a2e394..30a2ab7 100644 --- a/src/main/kotlin/app/viewmodels/StatusViewModel.kt +++ b/src/main/kotlin/app/viewmodels/StatusViewModel.kt @@ -4,7 +4,6 @@ import app.git.* import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.eclipse.jgit.api.Git import org.eclipse.jgit.diff.DiffEntry @@ -19,6 +18,13 @@ class StatusViewModel @Inject constructor( private val _stageStatus = MutableStateFlow(StageStatus.Loaded(listOf(), listOf())) val stageStatus: StateFlow = _stageStatus + private val _commitMessage = MutableStateFlow("") + val commitMessage: StateFlow = _commitMessage + var newCommitMessage: String + get() = commitMessage.value + set(value) { + _commitMessage.value = value + } private val _hasUncommitedChanges = MutableStateFlow(false) val hasUncommitedChanges: StateFlow @@ -37,7 +43,6 @@ class StatusViewModel @Inject constructor( } - fun unstageAll() = tabState.safeProcessing { git -> statusManager.unstageAll(git) @@ -51,14 +56,13 @@ class StatusViewModel @Inject constructor( } - fun resetStaged(diffEntry: DiffEntry) = tabState.runOperation { git -> statusManager.reset(git, diffEntry, staged = true) return@runOperation RefreshType.UNCOMMITED_CHANGES } - fun resetUnstaged(diffEntry: DiffEntry) =tabState.runOperation { git -> + fun resetUnstaged(diffEntry: DiffEntry) = tabState.runOperation { git -> statusManager.reset(git, diffEntry, staged = false) return@runOperation RefreshType.UNCOMMITED_CHANGES @@ -92,7 +96,6 @@ class StatusViewModel @Inject constructor( } - suspend fun refresh(git: Git) = withContext(Dispatchers.IO) { loadStatus(git) loadHasUncommitedChanges(git)