|
| 1 | +package com.texthip.thip.ui.booksearch.component |
| 2 | + |
| 3 | +import androidx.compose.foundation.background |
| 4 | +import androidx.compose.foundation.layout.* |
| 5 | +import androidx.compose.foundation.lazy.LazyColumn |
| 6 | +import androidx.compose.foundation.lazy.itemsIndexed |
| 7 | +import androidx.compose.material3.Text |
| 8 | +import androidx.compose.runtime.Composable |
| 9 | +import androidx.compose.ui.Alignment |
| 10 | +import androidx.compose.ui.Modifier |
| 11 | +import androidx.compose.ui.res.stringResource |
| 12 | +import androidx.compose.ui.tooling.preview.Preview |
| 13 | +import androidx.compose.ui.unit.dp |
| 14 | +import com.texthip.thip.R |
| 15 | +import com.texthip.thip.ui.booksearch.mock.BookData |
| 16 | +import com.texthip.thip.ui.common.cards.CardBookList |
| 17 | +import com.texthip.thip.ui.theme.ThipTheme |
| 18 | +import com.texthip.thip.ui.theme.ThipTheme.colors |
| 19 | +import com.texthip.thip.ui.theme.ThipTheme.typography |
| 20 | + |
| 21 | +@Composable |
| 22 | +fun BookFilteredSearchResult( |
| 23 | + resultCount: Int, |
| 24 | + bookList: List<BookData> |
| 25 | +) { |
| 26 | + Column { |
| 27 | + Row( |
| 28 | + modifier = Modifier.fillMaxWidth(), |
| 29 | + verticalAlignment = Alignment.CenterVertically |
| 30 | + ) { |
| 31 | + Text( |
| 32 | + text = stringResource(R.string.group_searched_room_size, resultCount), |
| 33 | + color = colors.Grey, |
| 34 | + style = typography.menu_m500_s14_h24 |
| 35 | + ) |
| 36 | + } |
| 37 | + Spacer( |
| 38 | + modifier = Modifier |
| 39 | + .padding(top = 4.dp, bottom = 20.dp) |
| 40 | + .fillMaxWidth() |
| 41 | + .height(1.dp) |
| 42 | + .background(colors.DarkGrey02) |
| 43 | + ) |
| 44 | + |
| 45 | + if (bookList.isEmpty()) { |
| 46 | + BookEmptyResult( |
| 47 | + mainText = stringResource(R.string.book_no_search_result1), |
| 48 | + subText = stringResource(R.string.book_no_search_result2), |
| 49 | + onRequestBook = { /*책 요청 처리*/ } |
| 50 | + ) |
| 51 | + } else { |
| 52 | + LazyColumn( |
| 53 | + verticalArrangement = Arrangement.Center |
| 54 | + ) { |
| 55 | + itemsIndexed(bookList) { index, book -> |
| 56 | + CardBookList( |
| 57 | + title = book.title, |
| 58 | + author = book.author, |
| 59 | + publisher = book.publisher, |
| 60 | + imageRes = book.imageRes |
| 61 | + ) |
| 62 | + if (index < bookList.size - 1) { |
| 63 | + Spacer( |
| 64 | + modifier = Modifier |
| 65 | + .padding(top = 12.dp, bottom = 12.dp) |
| 66 | + .fillMaxWidth() |
| 67 | + .height(1.dp) |
| 68 | + .background(colors.DarkGrey02) |
| 69 | + ) |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +@Preview |
| 78 | +@Composable |
| 79 | +fun PreviewBookFilteredSearchResult() { |
| 80 | + ThipTheme { |
| 81 | + BookFilteredSearchResult( |
| 82 | + resultCount = 3, |
| 83 | + bookList = listOf( |
| 84 | + BookData( |
| 85 | + title = "이기적 유전자", |
| 86 | + author = "리처드 도킨스", |
| 87 | + publisher = "을유문화사" |
| 88 | + ), |
| 89 | + BookData( |
| 90 | + title = "총, 균, 쇠", |
| 91 | + author = "재레드 다이아몬드", |
| 92 | + publisher = "문학사상사" |
| 93 | + ), |
| 94 | + BookData( |
| 95 | + title = "코스모스", |
| 96 | + author = "칼 세이건", |
| 97 | + publisher = "사이언스북스" |
| 98 | + ) |
| 99 | + ) |
| 100 | + ) |
| 101 | + } |
| 102 | +} |
0 commit comments