Skip to content

Commit

Permalink
🐛 fix edit
Browse files Browse the repository at this point in the history
  • Loading branch information
kmkim2689 committed Oct 25, 2024
1 parent 14db395 commit 4416736
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ object EditRecipeRepository {

private fun RecipeCreation.toSavedRecipeDescription(): SavedRecipeDescription =
SavedRecipeDescription(
id = 1L,
id = recipeId,
title = title,
imageUri = "",
description = introduction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import net.pengcook.android.presentation.core.model.Ingredient
import net.pengcook.android.presentation.core.model.RecipeStepMaking

data class RecipeCreation(
val recipeId: Long = 1L,
val title: String,
val introduction: String,
val cookingTime: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ class EditRecipeViewModel
minuteContent.value = recipe.cookingTime.split(":")[1]
secondContent.value = recipe.cookingTime.split(":")[2]
_thumbnailUri.value = Uri.parse(recipe.thumbnail)
thumbnailTitle = recipe.thumbnail
thumbnailTitle = recipe.thumbnail.split("/").lastOrNull() ?: run {
_uiEvent.value = Event(EditRecipeEvent.RecipePostFailure)
return@launch
}
}
}
}
Expand Down Expand Up @@ -283,6 +286,8 @@ class EditRecipeViewModel
}

override fun onConfirm() {
val steps = EditRecipeRepository.fetchAllSavedRecipeData().getOrNull()?.steps

val recipeCreation =
RecipeCreation(
title = titleContent.value ?: "",
Expand All @@ -302,16 +307,16 @@ class EditRecipeViewModel
)
} ?: emptyList(),
steps =
currentStepImages.value?.map {
steps?.map {
RecipeStepMaking(
stepId = it.itemId.toLong(),
stepId = it.stepId,
recipeId = recipeId,
description = it.description,
image = it.imageTitle,
image = it.image,
sequence = it.sequence,
imageUri = it.uri.toString(),
imageUri = it.imageUri,
cookingTime = it.cookingTime,
imageUploaded = it.uploaded,
imageUploaded = it.imageUploaded,
)
} ?: emptyList(),
categories =
Expand All @@ -332,10 +337,8 @@ class EditRecipeViewModel
return
}

val entireData = EditRecipeRepository.fetchAllSavedRecipeData().getOrNull()
if (entireData == null) {
return
}
val entireData = EditRecipeRepository.fetchAllSavedRecipeData().getOrNull() ?: return
println(entireData.steps)
val changedRecipe =
ChangedRecipe(
title = entireData.title,
Expand Down Expand Up @@ -431,7 +434,7 @@ class EditRecipeViewModel
private fun saveRecipeDescription() {
val recipeDescription =
RecipeDescription(
recipeDescriptionId = recipeId ?: return,
recipeDescriptionId = recipeId,
categories =
categoryContent.value
?.split(SEPARATOR_INGREDIENTS)
Expand All @@ -450,6 +453,7 @@ class EditRecipeViewModel

val recipeCreation =
RecipeCreation(
recipeId = recipeId,
title = recipeDescription.title,
introduction = recipeDescription.description,
cookingTime = recipeDescription.cookingTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class EditStepsViewModel :

fun saveData() {
val data = steps.value
println(data)

if (data == null) {
_uiEvent.value = EditStepsEvent.OnSaveFailure
Expand All @@ -47,6 +48,7 @@ class EditStepsViewModel :

fun exit() {
val data = steps.value
println(data)

if (data == null) {
_uiEvent.value = EditStepsEvent.OnSaveFailure
Expand All @@ -68,12 +70,17 @@ class EditStepsViewModel :
}

override fun navigationAction() {
exit()
println("data : ${EditRecipeRepository.fetchAllSavedRecipeData().getOrNull()}")

_uiEvent.value = EditStepsEvent.NavigationEvent
}

override fun customAction() {
_uiEvent.value = EditStepsEvent.TempSaveEvent
saveData()
println("data : ${EditRecipeRepository.fetchAllSavedRecipeData().getOrNull()}")

_uiEvent.value = EditStepsEvent.TempSaveEvent
}

override fun onDescriptionChanged(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ class StepMakingViewModel
private suspend fun recipeCreation(): RecipeCreation? {
val recipeData = makingRecipeRepository.fetchTotalRecipeData().getOrNull() ?: return null
return RecipeCreation(
recipeId = recipeId,
title = recipeData.title,
thumbnail = recipeData.thumbnail,
cookingTime = recipeData.cookingTime,
Expand Down

0 comments on commit 4416736

Please sign in to comment.