adding an empty state to messages list
This commit is contained in:
parent
42914ffe53
commit
a10f51aa08
|
@ -0,0 +1,18 @@
|
||||||
|
package app.dapk.st.design.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.material.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun GenericEmpty() {
|
||||||
|
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
||||||
|
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||||
|
Text("Nothing to see here...")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,7 +10,6 @@ import androidx.compose.foundation.lazy.LazyListState
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.material.Button
|
|
||||||
import androidx.compose.material.MaterialTheme
|
import androidx.compose.material.MaterialTheme
|
||||||
import androidx.compose.material.Text
|
import androidx.compose.material.Text
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
|
@ -33,6 +32,8 @@ import app.dapk.st.core.LifecycleEffect
|
||||||
import app.dapk.st.core.StartObserving
|
import app.dapk.st.core.StartObserving
|
||||||
import app.dapk.st.core.components.CenteredLoading
|
import app.dapk.st.core.components.CenteredLoading
|
||||||
import app.dapk.st.design.components.CircleishAvatar
|
import app.dapk.st.design.components.CircleishAvatar
|
||||||
|
import app.dapk.st.design.components.GenericEmpty
|
||||||
|
import app.dapk.st.design.components.GenericError
|
||||||
import app.dapk.st.design.components.Toolbar
|
import app.dapk.st.design.components.Toolbar
|
||||||
import app.dapk.st.directory.DirectoryEvent.OpenDownloadUrl
|
import app.dapk.st.directory.DirectoryEvent.OpenDownloadUrl
|
||||||
import app.dapk.st.directory.DirectoryScreenState.Content
|
import app.dapk.st.directory.DirectoryScreenState.Content
|
||||||
|
@ -85,20 +86,12 @@ fun DirectoryScreen(directoryViewModel: DirectoryViewModel) {
|
||||||
.nestedScroll(nestedScrollConnection)
|
.nestedScroll(nestedScrollConnection)
|
||||||
) {
|
) {
|
||||||
when (state) {
|
when (state) {
|
||||||
is Content -> {
|
|
||||||
Content(listState, state)
|
|
||||||
}
|
|
||||||
EmptyLoading -> CenteredLoading()
|
EmptyLoading -> CenteredLoading()
|
||||||
is Error -> {
|
DirectoryScreenState.Empty -> GenericEmpty()
|
||||||
Box(contentAlignment = Alignment.Center) {
|
is Error -> GenericError {
|
||||||
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
// TODO
|
||||||
Text("Something went wrong...")
|
|
||||||
Button(onClick = {}) {
|
|
||||||
Text("Retry")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
is Content -> Content(listState, state)
|
||||||
}
|
}
|
||||||
Toolbar(title = "Messages", offset = { IntOffset(x = 0, y = toolbarOffsetHeightPx.value.roundToInt()) })
|
Toolbar(title = "Messages", offset = { IntOffset(x = 0, y = toolbarOffsetHeightPx.value.roundToInt()) })
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package app.dapk.st.directory
|
||||||
sealed interface DirectoryScreenState {
|
sealed interface DirectoryScreenState {
|
||||||
|
|
||||||
object EmptyLoading : DirectoryScreenState
|
object EmptyLoading : DirectoryScreenState
|
||||||
|
object Empty : DirectoryScreenState
|
||||||
data class Content(
|
data class Content(
|
||||||
val overviewState: DirectoryState,
|
val overviewState: DirectoryState,
|
||||||
) : DirectoryScreenState
|
) : DirectoryScreenState
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
package app.dapk.st.directory
|
package app.dapk.st.directory
|
||||||
|
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import app.dapk.st.directory.DirectoryScreenState.Content
|
import app.dapk.st.directory.DirectoryScreenState.*
|
||||||
import app.dapk.st.directory.DirectoryScreenState.EmptyLoading
|
|
||||||
import app.dapk.st.viewmodel.DapkViewModel
|
import app.dapk.st.viewmodel.DapkViewModel
|
||||||
import app.dapk.st.viewmodel.MutableStateFactory
|
import app.dapk.st.viewmodel.MutableStateFactory
|
||||||
import app.dapk.st.viewmodel.defaultStateFactory
|
import app.dapk.st.viewmodel.defaultStateFactory
|
||||||
|
@ -26,8 +25,9 @@ class DirectoryViewModel(
|
||||||
syncJob = viewModelScope.launch {
|
syncJob = viewModelScope.launch {
|
||||||
directoryUseCase.state().onEach {
|
directoryUseCase.state().onEach {
|
||||||
shortcutHandler.onDirectoryUpdate(it.map { it.overview })
|
shortcutHandler.onDirectoryUpdate(it.map { it.overview })
|
||||||
if (it.isNotEmpty()) {
|
state = when (it.isEmpty()) {
|
||||||
state = Content(it)
|
true -> Empty
|
||||||
|
false -> Content(it)
|
||||||
}
|
}
|
||||||
}.collect()
|
}.collect()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue