Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -125,6 +125,12 @@ class SpotRepositoryImpl @Inject constructor(
return runCatchingWith(DeleteBookmarkError()) {
spotRemoteDataSource.deleteBookmark(spotId)

val cachedSavedSpots = profileLocalDataSource.getSavedSpots().firstOrNull()
if (cachedSavedSpots != null)
profileLocalDataSource.cacheSavedSpots(profileRemoteDataSource.getSavedSpots().map {
it.toSavedSpot()
})

profileRepositoryLegacy.fetchSavedSpots().onSuccess { fetched ->
(profileInfoCacheLegacy.data.value.getOrNull()
?: return@onSuccess).let { profileInfo ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.acon.acon.feature.profile.composable.screen.bookmark

import com.acon.acon.domain.repository.SpotRepository
import androidx.compose.runtime.Immutable
import com.acon.acon.core.model.model.profile.SavedSpot
import com.acon.acon.core.ui.base.BaseContainerHost
import com.acon.acon.domain.repository.ProfileRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.delay
import org.orbitmvi.orbit.annotation.OrbitExperimental
Expand All @@ -11,27 +13,24 @@ import javax.inject.Inject
@OptIn(OrbitExperimental::class)
@HiltViewModel
class BookmarkViewModel @Inject constructor(
private val spotRepository: SpotRepository
private val profileRepository: ProfileRepository
) : BaseContainerHost<BookmarkUiState, BookmarkUiSideEffect>() {

override val container = container<BookmarkUiState, BookmarkUiSideEffect>(BookmarkUiState.Loading) {
fetchSavedSpotList()
}

private fun fetchSavedSpotList() = intent {
delay(800)
spotRepository.fetchSavedSpotList().onSuccess {
reduce {
BookmarkUiState.Success(savedSpotLegacies = it)
}
}.onFailure {
reduce {
BookmarkUiState.LoadFailed
delay(LOADING_DELAY_MILLIS)
profileRepository.getSavedSpots().collect { result ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

북마크도 캐시데이터에 추가한건가요??

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넹 프로필 들어갈 때마다 안끊기게 하려구여

result.onSuccess {
reduce {
BookmarkUiState.Success(savedSpots = it)
}
}.onFailure {
reduce {
BookmarkUiState.LoadFailed
}
}
}
}


fun navigateToBack() = intent {
postSideEffect(BookmarkUiSideEffect.OnNavigateToBack)
}
Expand All @@ -41,10 +40,17 @@ class BookmarkViewModel @Inject constructor(
postSideEffect(BookmarkUiSideEffect.OnNavigateToSpotDetailScreen(spotId))
}
}

companion object {
private const val LOADING_DELAY_MILLIS = 800L
}
}

sealed interface BookmarkUiState {
data class Success(val savedSpotLegacies: List<com.acon.acon.core.model.model.profile.SavedSpotLegacy>? = emptyList()) : BookmarkUiState
@Immutable
data class Success(
val savedSpots: List<SavedSpot>
) : BookmarkUiState
data object Loading : BookmarkUiState
data object LoadFailed : BookmarkUiState
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ fun BookmarkScreen(
.verticalScroll(rememberScrollState())
.hazeSource(LocalHazeState.current)
) {
state.savedSpotLegacies?.chunked(2)?.fastForEach { rowItems ->
state.savedSpots.chunked(2)?.fastForEach { rowItems ->
Row(
modifier = Modifier
.fillMaxWidth()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ import com.acon.acon.core.designsystem.effect.imageGradientLayer
import com.acon.acon.core.designsystem.effect.imageGradientTopLayer
import com.acon.acon.core.designsystem.image.rememberDefaultLoadImageErrorPainter
import com.acon.acon.core.designsystem.theme.AconTheme
import com.acon.acon.core.model.model.profile.SavedSpot
import com.acon.acon.core.model.model.profile.SpotThumbnailStatus

@Composable
internal fun BookmarkItemLegacy(
spot: com.acon.acon.core.model.model.profile.SavedSpotLegacy,
spot: SavedSpot,
onClickSpotItem:() -> Unit,
modifier: Modifier = Modifier
) {
Expand All @@ -36,57 +38,65 @@ internal fun BookmarkItemLegacy(
.clip(RoundedCornerShape(8.dp))
.clickable { onClickSpotItem() }
) {
if(spot.image.isNotEmpty()) {
AsyncImage(
model = spot.image,
contentDescription = stringResource(R.string.store_background_image_content_description),
contentScale = ContentScale.Crop,
modifier = Modifier
.fillMaxSize()
.imageGradientTopLayer(),
error = rememberDefaultLoadImageErrorPainter()
)
when(val thumbnailStatus = spot.spotThumbnail) {
is SpotThumbnailStatus.Exist -> {
AsyncImage(
model = thumbnailStatus.url,
contentDescription = stringResource(R.string.store_background_image_content_description),
contentScale = ContentScale.Crop,
modifier = Modifier
.fillMaxSize()
.imageGradientTopLayer(),
error = rememberDefaultLoadImageErrorPainter()
)

Text(
text = if (spot.name.length > 9) spot.name.take(8) + stringResource(R.string.ellipsis) else spot.name,
color = AconTheme.color.White,
style = AconTheme.typography.Title5,
fontWeight = FontWeight.SemiBold,
modifier = Modifier
.align(Alignment.TopCenter)
.fillMaxWidth()
.padding(top = 20.dp)
.padding(horizontal = 20.dp)
)
} else {
Image(
painter = painterResource(R.drawable.ic_bg_no_store_profile),
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier
.fillMaxSize()
.imageGradientLayer()
)
Text(
text = spot.spotName.let { name ->
if (name.length > 9) name.take(8) + "…" else name
},
color = AconTheme.color.White,
style = AconTheme.typography.Title5,
fontWeight = FontWeight.SemiBold,
modifier = Modifier
.align(Alignment.TopCenter)
.fillMaxWidth()
.padding(top = 20.dp)
.padding(horizontal = 20.dp)
)
}
is SpotThumbnailStatus.Empty -> {

Text(
text = if (spot.name.length > 9) spot.name.take(8) + stringResource(R.string.ellipsis) else spot.name,
color = AconTheme.color.White,
style = AconTheme.typography.Title5,
fontWeight = FontWeight.SemiBold,
modifier = Modifier
.fillMaxWidth()
.align(Alignment.TopCenter)
.padding(top = 20.dp)
.padding(horizontal = 20.dp)
)
Image(
painter = painterResource(R.drawable.ic_bg_no_store_profile),
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier
.fillMaxSize()
.imageGradientLayer()
)

Text(
text = stringResource(R.string.no_store_image),
color = AconTheme.color.Gray50,
style = AconTheme.typography.Caption1,
modifier = Modifier
.align(Alignment.Center)
)
Text(
text = spot.spotName.let { name ->
if (name.length > 9) name.take(8) + "…" else name
},
color = AconTheme.color.White,
style = AconTheme.typography.Title5,
fontWeight = FontWeight.SemiBold,
modifier = Modifier
.fillMaxWidth()
.align(Alignment.TopCenter)
.padding(top = 20.dp)
.padding(horizontal = 20.dp)
)

Text(
text = stringResource(R.string.no_store_image),
color = AconTheme.color.Gray50,
style = AconTheme.typography.Caption1,
modifier = Modifier
.align(Alignment.Center)
)
}
}
}
}
Expand All @@ -96,7 +106,7 @@ internal fun BookmarkItemLegacy(
private fun BookmarkItemPreview() {
AconTheme {
BookmarkItemLegacy(
spot = com.acon.acon.core.model.model.profile.SavedSpotLegacy(1, "", ""),
spot = SavedSpot(0, "샘플", SpotThumbnailStatus.Empty),
onClickSpotItem = {}
)
}
Expand Down