Skip to content

Instantly share code, notes, and snippets.

@mcatta
Created October 25, 2022 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcatta/c35bab2e846d57f4e1539820cc9994db to your computer and use it in GitHub Desktop.
Save mcatta/c35bab2e846d57f4e1539820cc9994db to your computer and use it in GitHub Desktop.
@Composable
fun RepoInfoScreen(
githubViewModel: GithubViewModel
) {
val uiState by githubViewModel.rememberState()
Column(
modifier = Modifier
.fillMaxSize()
.padding(16.dp)
) {
when (uiState) {
is GithubState.ContentState -> {
Column {
val contentState = (uiState as GithubState.ContentState)
Row(
modifier = Modifier
.fillMaxWidth()
.padding(bottom = 16.dp),
verticalAlignment = Alignment.CenterVertically,
) {
TextField(placeholder = {
Text(text = "Owner")
}, value = contentState.owner, onValueChange = {
githubViewModel.dispatch(GithubAction.TypeOwner(it))
})
Button(
modifier = Modifier.padding(start = 16.dp),
onClick = { githubViewModel.dispatch(GithubAction.Confirm) },
content = { Text(text = "OK") }
)
}
LazyColumn {
items(contentState.repositories)
}
}
}
is GithubState.Error -> Column {
Text(text = "FAIL")
Button(onClick = { githubViewModel.dispatch(GithubAction.RetryLoadingAction) }) {
Text(text = "Retry")
}
}
is GithubState.Load -> {
Text(text = "Loading stuff")
}
null -> Unit
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment