Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.paw.key.core.designsystem.component

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
Expand Down Expand Up @@ -35,22 +36,19 @@ fun CourseCard(
createdAt: String,
isLiked: Boolean,
onClickItem: () -> Unit,
onClickLike: (Boolean) -> Unit,
petName: String,
representativeImageUrl: String? = null, // 추가
petProfileImageUrl: String? = null, // 추가
descriptionTags: List<String> = emptyList(), // 추가
modifier: Modifier = Modifier,
isShared: Boolean = false,
isRecord: Boolean = false
representativeImageUrl: String? = null,
petProfileImageUrl: String? = null,
descriptionTags: List<String> = emptyList()
) {
// 날짜 포맷 변환 함수
fun formatDate(dateString: String): String {
return try {
// "2025-07-15T21:27:03.54498" -> "2025/07/15"
val datePart = dateString.split("T")[0] // "2025-07-15"
datePart.replace("-", "/") // "2025/07/15"
val datePart = dateString.split("T")[0]
datePart.replace("-", "/")
} catch (e: Exception) {
dateString // 실패하면 원본 반환
dateString
}
}

Expand All @@ -62,16 +60,12 @@ fun CourseCard(
.background(Color.White, shape = RoundedCornerShape(20.dp))
.noRippleClickable { onClickItem() }
) {
// 지도 썸네일
Box(
modifier = Modifier
.fillMaxWidth()
.aspectRatio(343f / 172f)
.clip(RoundedCornerShape(10.dp))
) {


// 서버 이미지 또는 기본 이미지
if (representativeImageUrl != null) {
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
Expand All @@ -86,7 +80,6 @@ fun CourseCard(
contentScale = ContentScale.Crop
)
} else {
// 기본 이미지
Image(
painter = painterResource(id = R.drawable.dummy_map),
contentDescription = null,
Expand All @@ -98,7 +91,6 @@ fun CourseCard(
)
}

// 하단 그라데이션 오버레이
Box(
modifier = Modifier
.fillMaxWidth()
Expand All @@ -123,7 +115,6 @@ fun CourseCard(
.align(Alignment.BottomStart)
.padding(start = 16.dp, end = 16.dp, bottom = 16.dp)
) {
// 반려견 프로필 이미지
if (petProfileImageUrl != null) {
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
Expand All @@ -137,7 +128,6 @@ fun CourseCard(
contentScale = ContentScale.Crop
)
} else {
// 기본 프로필 이미지
Box(
modifier = Modifier
.size(40.dp)
Expand All @@ -155,6 +145,7 @@ fun CourseCard(
}

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

Column {
Text(
text = title,
Expand All @@ -170,39 +161,40 @@ fun CourseCard(
)
Spacer(modifier = Modifier.width(8.dp))
Text(
text = createdAt,
text = formatDate(createdAt),
style = PawKeyTheme.typography.caption12R,
color = PawKeyTheme.colors.gray100
)
}
}

Spacer(modifier = Modifier.weight(1f))

Icon(
imageVector = if (isLiked)
ImageVector.vectorResource(id = R.drawable.ic_heart_filled)
else
ImageVector.vectorResource(id = R.drawable.ic_heart_default),
contentDescription = "좋아요",
tint = Color.Unspecified
tint = Color.Unspecified,
modifier = Modifier.clickable { onClickLike(!isLiked) } //클릭하면 외부에 알려줌
)
}
}

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

// 서버에서 받은 태그들 사용
ChipRow(
tags = descriptionTags,
modifier = Modifier
.padding(start = 16.dp, end = 16.dp)
modifier = Modifier.padding(horizontal = 16.dp)
)

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

HorizontalDivider(
color = PawKeyTheme.colors.gray50,
thickness = 1.dp,
modifier = Modifier.padding(start = 16.dp, end = 16.dp)
modifier = Modifier.padding(horizontal = 16.dp)
)
}
}
Expand All @@ -214,13 +206,14 @@ fun CourseCardPreview() {
CourseCard(
postId = 1,
title = "홍대 주변 좋은 산책 코스",
createdAt = "2025/07/16",
representativeImageUrl = "https://pawkey-server.com/image.jpg",
createdAt = "2025-07-16T21:27:03.54498",
isLiked = true,
onClickItem = {},
onClickLike = {},
petName = "후추",
representativeImageUrl = "https://pawkey-server.com/image.jpg",
petProfileImageUrl = "https://pawkey-server.com/profile.jpg",
descriptionTags = listOf("이륜차 거의 없음", "물그릇 비치", "쉴 곳 있음"),
isLiked = true,
onClickItem = {}
descriptionTags = listOf("이륜차 거의 없음", "물그릇 비치", "쉴 곳 있음")
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ fun TabListScreen(
petProfileImageUrl = post.writer.petProfileImageUrl,
descriptionTags = post.descriptionTags,
isLiked = post.isLike,
onClickLike = { isLiked ->
viewModel.toggleLike(post.postId, isLiked)
},
onClickItem = { navigateToDetail() }
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,38 @@ class TapListViewModel @Inject constructor(
_state.update { it.copy(selectedSortOption = option) }
}

fun toggleLike(postId: Int, isLiked: Boolean) {
viewModelScope.launch {
_state.update { currentState ->
val updatedPostsResult = currentState.postsResult?.let { postsResult ->
postsResult.copy(
posts = postsResult.posts.map { post ->
if (post.postId == postId) {
post.copy(isLike = isLiked)
} else {
post
}
}
)
}

// val updatedCourseList = currentState.courseList.map { course ->
// if (course.postId == postId) {
// // ArchivedListEntity의 실제 프로퍼티명에 맞게 수정
// // isLiked 대신 isLike 또는 liked 등의 프로퍼티를 확인하고 사용
// course.copy(isLike = isLiked) // 또는 course.copy(liked = isLiked)
// } else {
// course
// }
// }

currentState.copy(
postsResult = updatedPostsResult,
// courseList = updatedCourseList
)
}
}
}
fun updateMood(option: String) {
_state.update {
it.copy(
Expand Down
Loading