1package soy.iko.opencode.ui.file
3import androidx.lifecycle.ViewModel
4import androidx.lifecycle.viewModelScope
5import soy.iko.opencode.data.model.FileContent
6import soy.iko.opencode.di.AppContainer
7import kotlinx.coroutines.flow.MutableStateFlow
8import kotlinx.coroutines.flow.StateFlow
9import kotlinx.coroutines.flow.asStateFlow
10import kotlinx.coroutines.launch
12data class FileViewState(
13 val loading: Boolean = true,
14 val content: FileContent? = null,
15 val error: String? = null,
19 private val container: AppContainer,
20 private val path: String,
23 private val _state = MutableStateFlow(FileViewState())
24 val state: StateFlow<FileViewState> = _state.asStateFlow()
27 val api = container.activeConnection.value?.api
29 _state.value = FileViewState(loading = false, error = "Not connected")
31 viewModelScope.launch {
32 runCatching { api.readFile(path) }
33 .onSuccess { _state.value = FileViewState(loading = false, content = it) }
34 .onFailure { _state.value = FileViewState(loading = false, error = it.message ?: "Failed to read $path") }
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list