Skip to content

Commit

Permalink
#17 [REFACTOR] 좋아요 목록 아이템 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
gaeulzzang committed Nov 7, 2024
1 parent e4e4c1a commit 59ee4c1
Showing 1 changed file with 4 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.compose.rememberNavController
import coil.compose.AsyncImage
import com.hackathon.alddeul_babsang.R
import com.hackathon.alddeul_babsang.core_ui.theme.AlddeulBabsangTheme
Expand All @@ -39,14 +38,13 @@ import com.hackathon.alddeul_babsang.core_ui.theme.body2Regular
import com.hackathon.alddeul_babsang.core_ui.theme.body4Regular
import com.hackathon.alddeul_babsang.core_ui.theme.head4Bold
import com.hackathon.alddeul_babsang.domain.entity.LikesEntity
import com.hackathon.alddeul_babsang.presentation.profile.navigation.ProfileNavigator

@Composable
fun LikeItem(
onClick: () -> Unit = {},
data: LikesEntity
) {
var isFavorite by remember { mutableStateOf(data.favorite ?: false) }
var isFavorite by remember { mutableStateOf(data.favorite) }

// 클릭할 때마다 favorite 값 토글
val heartIconId = if (isFavorite) {
Expand All @@ -63,10 +61,7 @@ fun LikeItem(
color = Orange700,
shape = RoundedCornerShape(14.dp)
)
.height(240.dp)
.clickable(onClick = {
onClick()
})
.clickable(onClick = { onClick() })
) {
Box(
modifier = Modifier
Expand All @@ -76,32 +71,27 @@ fun LikeItem(
) {
// AsyncImage 로드
LoadImageWithPlaceholder(data.codeName, data.avatar)

Image(
painter = painterResource(heartIconId),
contentDescription = null,
modifier = Modifier
.padding(end = 10.dp, top = 10.dp)
.align(Alignment.TopEnd) // Box 내에서 오른쪽 끝으로 배치
.align(Alignment.TopEnd)
.clickable {
// 클릭 시 좋아요 상태를 토글
isFavorite = !isFavorite
}
)
}

Spacer(modifier = Modifier.height(15.dp))

Row {
Text(
text = data.name,
style = head4Bold,
color = Orange900,
modifier = Modifier.padding(start = 20.dp)
)

Spacer(modifier = Modifier.width(15.dp))

Text(
text = data.codeName,
style = body2Regular,
Expand All @@ -111,23 +101,19 @@ fun LikeItem(
.padding(bottom = 3.dp)
)
}

Spacer(modifier = Modifier.height(12.dp))

Text(
text = data.address,
style = body4Regular,
color = Gray300,
modifier = Modifier.padding(start = 20.dp)
)

Spacer(modifier = Modifier.height(7.dp))

Text(
text = data.phone,
style = body4Regular,
color = Gray300,
modifier = Modifier.padding(start = 20.dp)
modifier = Modifier.padding(start = 20.dp, bottom = 20.dp)
)
}
}
Expand All @@ -141,7 +127,6 @@ fun LoadImageWithPlaceholder(codeName: String, imageUrl: String?) {
else -> R.drawable.ic_etc_food
}


Box(
modifier = Modifier
.fillMaxWidth()
Expand Down Expand Up @@ -169,19 +154,14 @@ fun LoadImageWithPlaceholder(codeName: String, imageUrl: String?) {
.fillMaxWidth() // 가로는 꽉 차게
.fillMaxHeight() // 세로도 꽉 차게
.clip(RoundedCornerShape(topStart = 14.dp, topEnd = 14.dp))

)

}
}
}

@Preview(showBackground = true)
@Composable
fun LikeItemPreview() {
val navController = rememberNavController()
val navigator = ProfileNavigator(navController)

AlddeulBabsangTheme {
LikeItem(
data = LikesEntity(
Expand Down

0 comments on commit 59ee4c1

Please sign in to comment.