Skip to content

Commit

Permalink
fix paging
Browse files Browse the repository at this point in the history
  • Loading branch information
stslex committed Apr 30, 2024
1 parent 6d75f66 commit 5493ea7
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal fun FavouriteScreen(
when (state.screen) {
is FavouriteScreenState.Content -> FavouriteScreenContent(
state = state.screen,
items = state.pagingState,
items = state.pagingState.result,
query = state.query,
isLoading = state.isLoading,
onItemClick = { uuid ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal fun FavouriteScreenContent(
onSearch = onSearch,
)
when (state) {
FavouriteScreenState.Content.Empty -> {
FavouriteScreenState.Empty -> {
Column {
if (isLoading) {
FavouriteScreenShimmer()
Expand Down Expand Up @@ -88,8 +88,14 @@ internal fun FavouriteScreenContent(
}
}
}
}

FavouriteScreenState.Content.Loading -> {
// TODO()
}
FavouriteScreenState.Content.Refresh -> {
// TODO()
}
}
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ internal fun FollowerScreen(
when (state.screen) {
is FollowerScreenState.Content -> {
LazyColumn {
items(state.data.size) { index ->
items(state.pagingState.result.size) { index ->
Text(
"test: ${state.data[index].username}"
"test: ${state.pagingState.result[index].username}"
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.stslex.feature.follower.ui.model

import com.stslex.feature.follower.data.model.FollowerDataModel

fun FollowerDataModel.toUi(): FollowerModel = FollowerModel(
uuid = uuid,
username = username,
avatarUrl = avatarUrl,
isFollowing = isFollowing
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.stslex.feature.follower.ui.store

import androidx.compose.runtime.Stable
import com.stslex.core.ui.base.AppError
import com.stslex.core.ui.pager.states.PagerLoadState

@Stable
sealed interface FollowerScreenState {

@Stable
sealed interface Content : FollowerScreenState {

@Stable
data object Data : Content

@Stable
data object Loading : Content

@Stable
data object Refresh : Content
}

@Stable
data object Shimmer : FollowerScreenState

@Stable
data object Empty : FollowerScreenState

@Stable
data class Error(val error: AppError) : FollowerScreenState
}

fun PagerLoadState.toUi(): FollowerScreenState = when (this) {
is PagerLoadState.Loading -> FollowerScreenState.Content.Loading
is PagerLoadState.Error -> FollowerScreenState.Error(error)
is PagerLoadState.Initial -> FollowerScreenState.Shimmer
is PagerLoadState.Empty -> FollowerScreenState.Empty
PagerLoadState.Data -> FollowerScreenState.Content.Data
PagerLoadState.Refresh -> FollowerScreenState.Content.Refresh
PagerLoadState.Retry -> FollowerScreenState.Shimmer
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
package com.stslex.feature.follower.ui.store

import androidx.compose.runtime.Stable
import com.stslex.core.ui.base.paging.PagingState
import com.stslex.core.ui.mvi.Store
import com.stslex.core.ui.mvi.Store.Event.Snackbar
import com.stslex.feature.follower.navigation.FollowerScreenArgs
import com.stslex.feature.follower.ui.model.FollowerModel
import com.stslex.feature.follower.ui.store.FollowerStore.Action
import com.stslex.feature.follower.ui.store.FollowerStore.Event
import com.stslex.feature.follower.ui.store.FollowerStore.State
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList

interface FollowerStore : Store<State, Event, Action> {

@Stable
data class State(
val uuid: String,
val page: Int,
val type: FollowerScreenArgs,
val data: ImmutableList<FollowerModel>,
val pagingState: PagingState<FollowerModel>,
val screen: FollowerScreenState,
val query: String
) : Store.State {
Expand All @@ -27,10 +25,8 @@ interface FollowerStore : Store<State, Event, Action> {
const val DEFAULT_PAGE = -1

val INITIAL = State(
uuid = "",
page = DEFAULT_PAGE,
type = FollowerScreenArgs.Follower(""),
data = emptyList<FollowerModel>().toImmutableList(),
pagingState = PagingState.default(),
screen = FollowerScreenState.Shimmer,
query = ""
)
Expand All @@ -46,38 +42,27 @@ interface FollowerStore : Store<State, Event, Action> {
) : Action

@Stable
data object LoadMore : Action
}

@Stable
sealed interface Event : Store.Event {
data object Load : Action

@Stable
data class ErrorSnackBar(val message: String) : Event
}

sealed interface Navigation : Store.Navigation
}

@Stable
sealed interface FollowerScreenState {
data object Refresh : Action

@Stable
sealed interface Content : FollowerScreenState {
@Stable
data object Retry : Action

@Stable
data object NotLoading : Content
data class QueryChanged(val query: String) : Action

@Stable
data object Loading : Content
data class OnUserClick(val uuid: String) : Action
}

@Stable
data object Shimmer : FollowerScreenState
sealed interface Event : Store.Event {

@Stable
data object Empty : FollowerScreenState
@Stable
data class ShowSnackbar(val snackbar: Snackbar) : Event
}

@Stable
data class Error(val error: Throwable) : FollowerScreenState
}
sealed interface Navigation : Store.Navigation
}
Loading

0 comments on commit 5493ea7

Please sign in to comment.