Skip to content

Commit dd431b3

Browse files
committed
[refactor]: SavedScreen content들 component로 분리(#26)
1 parent 198f78c commit dd431b3

4 files changed

Lines changed: 62 additions & 48 deletions

File tree

app/src/main/java/com/texthip/thip/ui/myPage/SavedScreen.kt

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@ import androidx.compose.foundation.layout.fillMaxWidth
88
import androidx.compose.foundation.layout.height
99
import androidx.compose.foundation.layout.padding
1010
import androidx.compose.foundation.layout.width
11-
import androidx.compose.foundation.lazy.LazyColumn
12-
import androidx.compose.foundation.lazy.items
1311
import androidx.compose.foundation.shape.RoundedCornerShape
1412
import androidx.compose.material3.Scaffold
1513
import androidx.compose.material3.Tab
1614
import androidx.compose.material3.TabRow
1715
import androidx.compose.material3.TabRowDefaults.tabIndicatorOffset
1816
import androidx.compose.material3.Text
1917
import androidx.compose.runtime.Composable
20-
import androidx.compose.runtime.collectAsState
2118
import androidx.compose.runtime.getValue
2219
import androidx.compose.runtime.mutableStateOf
2320
import androidx.compose.runtime.saveable.rememberSaveable
@@ -26,20 +23,15 @@ import androidx.compose.ui.Alignment
2623
import androidx.compose.ui.Modifier
2724
import androidx.compose.ui.draw.clip
2825
import androidx.compose.ui.graphics.Color
29-
import androidx.compose.ui.res.painterResource
3026
import androidx.compose.ui.res.stringResource
3127
import androidx.compose.ui.text.style.TextAlign
3228
import androidx.compose.ui.tooling.preview.Preview
3329
import androidx.compose.ui.unit.dp
34-
import androidx.lifecycle.viewmodel.compose.viewModel
3530
import com.texthip.thip.R
36-
import com.texthip.thip.ui.common.cards.CardBookList
3731
import com.texthip.thip.ui.common.topappbar.DefaultTopAppBar
38-
import com.texthip.thip.ui.myPage.component.SavedFeedCard
39-
import com.texthip.thip.ui.myPage.viewmodel.SavedBookViewModel
40-
import com.texthip.thip.ui.myPage.viewmodel.SavedFeedViewModel
32+
import com.texthip.thip.ui.myPage.component.BookContent
33+
import com.texthip.thip.ui.myPage.component.FeedContent
4134
import com.texthip.thip.ui.theme.Black
42-
import com.texthip.thip.ui.theme.Grey02
4335
import com.texthip.thip.ui.theme.ThipTheme.colors
4436
import com.texthip.thip.ui.theme.ThipTheme.typography
4537
import com.texthip.thip.ui.theme.White
@@ -112,43 +104,6 @@ fun SavedScreen() {
112104
}
113105
}
114106

115-
@Composable
116-
fun FeedContent(viewModel: SavedFeedViewModel = viewModel()) {
117-
val feedList by viewModel.feeds.collectAsState()
118-
119-
LazyColumn {
120-
items(feedList, key = { it.id }) { feed ->
121-
val bookImagePainter = feed.imageUrl?.let { painterResource(it) }
122-
val profileImagePainter = feed.userProfileImage?.let { painterResource(it) }
123-
124-
SavedFeedCard(
125-
feedItem = feed,
126-
bookImage = bookImagePainter,
127-
profileImage = profileImagePainter,
128-
onBookmarkClick = { viewModel.toggleBookmark(feed.id) },
129-
onLikeClick = { viewModel.toggleLike(feed.id) }
130-
)
131-
}
132-
}
133-
}
134-
135-
@Composable
136-
fun BookContent(viewModel: SavedBookViewModel = viewModel()) {
137-
val books by viewModel.bookList.collectAsState()
138-
139-
LazyColumn {
140-
items(items = books, key = { it.id }) { book ->
141-
CardBookList(
142-
title = book.title,
143-
author = book.author,
144-
imageRes = null,
145-
publisher = book.publisher,
146-
isBookmarked = book.isSaved,
147-
onBookmarkClick = { viewModel.toggleBookmark(book.id) }
148-
)
149-
}
150-
}
151-
}
152107

153108
@Preview
154109
@Composable
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.texthip.thip.ui.myPage.component
2+
3+
import androidx.compose.foundation.lazy.LazyColumn
4+
import androidx.compose.foundation.lazy.items
5+
import androidx.compose.runtime.Composable
6+
import androidx.compose.runtime.collectAsState
7+
import androidx.compose.runtime.getValue
8+
import androidx.lifecycle.viewmodel.compose.viewModel
9+
import com.texthip.thip.ui.common.cards.CardBookList
10+
import com.texthip.thip.ui.myPage.viewmodel.SavedBookViewModel
11+
12+
@Composable
13+
fun BookContent(viewModel: SavedBookViewModel = viewModel()) {
14+
val books by viewModel.bookList.collectAsState()
15+
16+
LazyColumn {
17+
items(items = books, key = { it.id }) { book ->
18+
CardBookList(
19+
title = book.title,
20+
author = book.author,
21+
imageRes = null,
22+
publisher = book.publisher,
23+
isBookmarked = book.isSaved,
24+
onBookmarkClick = { viewModel.toggleBookmark(book.id) }
25+
)
26+
}
27+
}
28+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.texthip.thip.ui.myPage.component
2+
3+
import androidx.compose.foundation.lazy.LazyColumn
4+
import androidx.compose.foundation.lazy.items
5+
import androidx.compose.runtime.Composable
6+
import androidx.compose.runtime.collectAsState
7+
import androidx.compose.runtime.getValue
8+
import androidx.compose.ui.res.painterResource
9+
import androidx.lifecycle.viewmodel.compose.viewModel
10+
import com.texthip.thip.ui.myPage.viewmodel.SavedFeedViewModel
11+
12+
@Composable
13+
fun FeedContent(viewModel: SavedFeedViewModel = viewModel()) {
14+
val feedList by viewModel.feeds.collectAsState()
15+
16+
LazyColumn {
17+
items(feedList, key = { it.id }) { feed ->
18+
val bookImagePainter = feed.imageUrl?.let { painterResource(it) }
19+
val profileImagePainter = feed.userProfileImage?.let { painterResource(it) }
20+
21+
SavedFeedCard(
22+
feedItem = feed,
23+
bookImage = bookImagePainter,
24+
profileImage = profileImagePainter,
25+
onBookmarkClick = { viewModel.toggleBookmark(feed.id) },
26+
onLikeClick = { viewModel.toggleLike(feed.id) }
27+
)
28+
}
29+
}
30+
}

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
<string name="menu">메뉴</string>
7575
<string name="likes">좋아요</string>
7676
<string name="comments">댓글</string>
77+
<string name="feed">피드</string>
78+
<string name="book">책</string>
7779
<string name="edit_profile">프로필 편집</string>
7880
<string name="change_nickname">닉네임 변경</string>
7981
<string name="edit_role">칭호 편집</string>
@@ -83,7 +85,6 @@
8385
<string name="ask_account_deletion">정말로 탈퇴하시겠어요?</string>
8486
<string name="delete_account_description">\'예\'를 누르면 모든 기록이 사라져요.</string>
8587

86-
8788
<string name="literature">문학</string>
8889
<string name="literary_person">문학가</string>
8990
<string name="science_it">과학·IT</string>

0 commit comments

Comments
 (0)