-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83da642
commit e395e81
Showing
6 changed files
with
119 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 71 additions & 7 deletions
78
feature/search/src/main/java/team/ppac/search/result/SearchResultScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,91 @@ | ||
package team.ppac.search.result | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.calculateEndPadding | ||
import androidx.compose.foundation.layout.calculateStartPadding | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.LayoutDirection | ||
import androidx.paging.LoadStates | ||
import team.ppac.common.android.component.error.FarmemeErrorScreen | ||
import team.ppac.common.android.extension.collectPagingItemsWithHandleState | ||
import team.ppac.designsystem.component.scaffold.FarmemeScaffold | ||
import team.ppac.designsystem.component.tabbar.TabBarHeight | ||
import team.ppac.designsystem.component.toolbar.FarmemeSearchToolbar | ||
import team.ppac.search.detail.component.EmptyResultContent | ||
import team.ppac.search.detail.component.SearchDetailLoadingContent | ||
import team.ppac.search.detail.component.SearchDetailResultContent | ||
import team.ppac.search.result.mvi.SearchResultUiState | ||
|
||
@Composable | ||
internal fun SearchResultScreen( | ||
modifier: Modifier = Modifier, | ||
uiState: SearchResultUiState, | ||
handleLoadStates: (LoadStates) -> Unit, | ||
onQueryChange: (String) -> Unit, | ||
onRetryClick: () -> Unit, | ||
onMemeClick: (String) -> Unit, | ||
onCopyClick: (String, String) -> Unit, | ||
) { | ||
FarmemeScaffold( | ||
modifier = modifier.fillMaxSize(), | ||
topBar = { | ||
FarmemeSearchToolbar( | ||
text = uiState.query, | ||
onTextChanged = onQueryChange | ||
val searchResults = uiState.searchResults.collectPagingItemsWithHandleState(handleLoadStates) | ||
|
||
when { | ||
uiState.isError -> { | ||
FarmemeErrorScreen( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(bottom = TabBarHeight), | ||
title = "정보를 불러오지 못 했어요.\n새로고침 해주세요.", | ||
onRetryClick = onRetryClick | ||
) | ||
} | ||
) { | ||
|
||
else -> { | ||
FarmemeScaffold( | ||
modifier = modifier.fillMaxSize(), | ||
topBar = { | ||
FarmemeSearchToolbar( | ||
text = uiState.query, | ||
onTextChanged = onQueryChange | ||
) | ||
} | ||
) { paddingValues -> | ||
val innerPadding = PaddingValues( | ||
top = paddingValues.calculateTopPadding(), | ||
start = paddingValues.calculateStartPadding(LayoutDirection.Ltr), | ||
end = paddingValues.calculateEndPadding(LayoutDirection.Ltr), | ||
bottom = paddingValues.calculateBottomPadding() + TabBarHeight | ||
) | ||
|
||
when { | ||
uiState.isLoading -> { | ||
SearchDetailLoadingContent( | ||
modifier = Modifier.fillMaxSize(), | ||
isLoading = uiState.isLoading | ||
) | ||
} | ||
|
||
else -> { | ||
Column( | ||
modifier = Modifier.padding(innerPadding) | ||
) { | ||
if (uiState.totalMemeCount == 0) { | ||
EmptyResultContent() | ||
} else { | ||
SearchDetailResultContent( | ||
totalItemCount = uiState.totalMemeCount, | ||
searchResults = searchResults, | ||
onMemeClick = onMemeClick, | ||
onCopyClick = onCopyClick, | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 12 additions & 2 deletions
14
feature/search/src/main/java/team/ppac/search/result/mvi/SearchResultUiState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
package team.ppac.search.result.mvi | ||
|
||
import androidx.paging.PagingData | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flowOf | ||
import team.ppac.common.android.base.UiState | ||
import team.ppac.search.detail.model.SearchResultUiModel | ||
|
||
data class SearchResultUiState( | ||
val isLoading: Boolean, | ||
val query: String | ||
val isError: Boolean, | ||
val query: String, | ||
val totalMemeCount: Int, | ||
val searchResults: Flow<PagingData<SearchResultUiModel>>, | ||
) : UiState { | ||
|
||
companion object { | ||
val INITIAL_STATE = SearchResultUiState( | ||
isLoading = true, | ||
query = "" | ||
isError = false, | ||
query = "", | ||
totalMemeCount = 0, | ||
searchResults = flowOf(PagingData.empty()), | ||
) | ||
} | ||
} |