Skip to content

Commit 9445b51

Browse files
committed
[BOOK-504] refactor: remember를 통한 최적화 적용
1 parent dfdadc2 commit 9445b51

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

  • feature/detail/src/main/kotlin/com/ninecraft/booket/feature/detail/book/component

feature/detail/src/main/kotlin/com/ninecraft/booket/feature/detail/book/component/CollectedSeeds.kt

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import androidx.compose.material3.HorizontalDivider
2222
import androidx.compose.material3.Icon
2323
import androidx.compose.material3.Text
2424
import androidx.compose.runtime.Composable
25+
import androidx.compose.runtime.remember
2526
import androidx.compose.ui.Alignment
2627
import androidx.compose.ui.Modifier
2728
import androidx.compose.ui.draw.clip
@@ -43,6 +44,14 @@ import kotlinx.collections.immutable.ImmutableList
4344
import kotlinx.collections.immutable.persistentListOf
4445
import com.ninecraft.booket.core.designsystem.R as designR
4546

47+
private val EMOTION_DISPLAY_ORDER = listOf(
48+
EmotionCode.WARMTH,
49+
EmotionCode.JOY,
50+
EmotionCode.SADNESS,
51+
EmotionCode.INSIGHT,
52+
EmotionCode.OTHER,
53+
)
54+
4655
@Composable
4756
internal fun CollectedSeeds(
4857
seedsStats: ImmutableList<EmotionModel>,
@@ -87,14 +96,10 @@ internal fun CollectedSeeds(
8796

8897
Spacer(modifier = Modifier.height(ReedTheme.spacing.spacing4))
8998

90-
val displayEmotions = listOf(
91-
EmotionCode.WARMTH,
92-
EmotionCode.JOY,
93-
EmotionCode.SADNESS,
94-
EmotionCode.INSIGHT,
95-
EmotionCode.OTHER,
96-
).mapNotNull { emotionCode ->
97-
seedsStats.find { it.code == emotionCode && it.count > 0 }
99+
val displayEmotions = remember(seedsStats) {
100+
EMOTION_DISPLAY_ORDER.mapNotNull { emotionCode ->
101+
seedsStats.find { it.code == emotionCode && it.count > 0 }
102+
}
98103
}
99104

100105
if (displayEmotions.isNotEmpty()) {
@@ -188,7 +193,9 @@ private fun EmotionRatioBar(
188193
seedsStats: ImmutableList<EmotionModel>,
189194
modifier: Modifier = Modifier,
190195
) {
191-
val totalCount = seedsStats.sumOf { it.count }.coerceAtLeast(1)
196+
val totalCount = remember(seedsStats) {
197+
seedsStats.sumOf { it.count }.coerceAtLeast(1)
198+
}
192199

193200
Row(
194201
modifier = modifier

0 commit comments

Comments
 (0)