Updated on 2026-08-14
This commit is contained in:
parent
8072b4efcd
commit
0e275d7f5f
1 changed files with 35 additions and 32 deletions
|
|
@ -26,42 +26,17 @@ internal class UpdateDataStateTransformer(
|
||||||
) : Transformer<NFTCollectionsStateUM> {
|
) : Transformer<NFTCollectionsStateUM> {
|
||||||
|
|
||||||
override fun transform(prevState: NFTCollectionsStateUM): NFTCollectionsStateUM {
|
override fun transform(prevState: NFTCollectionsStateUM): NFTCollectionsStateUM {
|
||||||
|
val hasQuery = !(prevState.content as? NFTCollectionsUM.Content)?.search?.query.isNullOrEmpty()
|
||||||
val content = when {
|
val content = when {
|
||||||
nftCollections.allCollectionsFailed() ->
|
!hasQuery && nftCollections.allCollectionsFailed() ->
|
||||||
NFTCollectionsUM.Failed(onRetryClick, onReceiveClick)
|
NFTCollectionsUM.Failed(onRetryClick, onReceiveClick)
|
||||||
nftCollections.anyCollectionFailed() && nftCollections.allLoadedCollectionsEmpty() ->
|
!hasQuery && nftCollections.anyCollectionFailed() && nftCollections.allLoadedCollectionsEmpty() ->
|
||||||
NFTCollectionsUM.Failed(onRetryClick, onReceiveClick)
|
NFTCollectionsUM.Failed(onRetryClick, onReceiveClick)
|
||||||
nftCollections.allCollectionsLoaded() && nftCollections.allCollectionsEmpty() ->
|
!hasQuery && nftCollections.allCollectionsLoaded() && nftCollections.allCollectionsEmpty() ->
|
||||||
NFTCollectionsUM.Empty(onReceiveClick)
|
NFTCollectionsUM.Empty(onReceiveClick)
|
||||||
!nftCollections.allCollectionsLoaded() && nftCollections.allCollectionsEmpty() ->
|
!nftCollections.allCollectionsLoaded() && nftCollections.allCollectionsEmpty() -> prevState.createLoading()
|
||||||
NFTCollectionsUM.Loading(
|
|
||||||
onReceiveClick = onReceiveClick,
|
else -> prevState.createContent()
|
||||||
search = SearchBarUM(
|
|
||||||
placeholderText = resourceReference(R.string.common_search),
|
|
||||||
query = "",
|
|
||||||
isActive = false,
|
|
||||||
onQueryChange = { },
|
|
||||||
onActiveChange = { },
|
|
||||||
),
|
|
||||||
)
|
|
||||||
else -> {
|
|
||||||
NFTCollectionsUM.Content(
|
|
||||||
search = if (prevState.content is NFTCollectionsUM.Content) {
|
|
||||||
prevState.content.search
|
|
||||||
} else {
|
|
||||||
initialSearchBarFactory()
|
|
||||||
},
|
|
||||||
collections = nftCollections
|
|
||||||
.map { it.content }
|
|
||||||
.asSequence()
|
|
||||||
.filterIsInstance<NFTCollections.Content.Collections>()
|
|
||||||
.map { it.collections.orEmpty().transform(prevState) }
|
|
||||||
.flatten()
|
|
||||||
.toPersistentList(),
|
|
||||||
warnings = transformNotifications(),
|
|
||||||
onReceiveClick = onReceiveClick,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return prevState.copy(
|
return prevState.copy(
|
||||||
content = content,
|
content = content,
|
||||||
|
|
@ -74,6 +49,34 @@ internal class UpdateDataStateTransformer(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun NFTCollectionsStateUM.createLoading(): NFTCollectionsUM.Loading = NFTCollectionsUM.Loading(
|
||||||
|
onReceiveClick = onReceiveClick,
|
||||||
|
search = SearchBarUM(
|
||||||
|
placeholderText = resourceReference(R.string.common_search),
|
||||||
|
query = "",
|
||||||
|
isActive = false,
|
||||||
|
onQueryChange = { },
|
||||||
|
onActiveChange = { },
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
private fun NFTCollectionsStateUM.createContent(): NFTCollectionsUM.Content = NFTCollectionsUM.Content(
|
||||||
|
search = if (content is NFTCollectionsUM.Content) {
|
||||||
|
content.search
|
||||||
|
} else {
|
||||||
|
initialSearchBarFactory()
|
||||||
|
},
|
||||||
|
collections = nftCollections
|
||||||
|
.map { it.content }
|
||||||
|
.asSequence()
|
||||||
|
.filterIsInstance<NFTCollections.Content.Collections>()
|
||||||
|
.map { it.collections.orEmpty().transform(this) }
|
||||||
|
.flatten()
|
||||||
|
.toPersistentList(),
|
||||||
|
warnings = transformNotifications(),
|
||||||
|
onReceiveClick = onReceiveClick,
|
||||||
|
)
|
||||||
|
|
||||||
private fun List<NFTCollection>.transform(state: NFTCollectionsStateUM): ImmutableList<NFTCollectionUM> = map {
|
private fun List<NFTCollection>.transform(state: NFTCollectionsStateUM): ImmutableList<NFTCollectionUM> = map {
|
||||||
NFTCollectionUM(
|
NFTCollectionUM(
|
||||||
id = it.collectionIdProvider(),
|
id = it.collectionIdProvider(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue