Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Alba María Álvarez
/
front_recipes
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f7d7eede
authored
Sep 04, 2025
by
Alba María Álvarez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
feat(RecipeDetail): implementada funcionalidad para eliminar recetas con un modal
parent
524aaa38
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
3 deletions
src/views/RecipeDetail.vue
src/views/RecipeDetail.vue
View file @
f7d7eede
...
...
@@ -7,14 +7,14 @@
<div
class=
"d-flex justify-content-between align-items-center mb-4"
>
<span
v-if=
"recipe.favorite"
class=
"badge badge-custom px-3 py-2 shadow-sm"
>
<i
class=
"bi bi-heart-fill"
></i>
Favorita
<i
class=
"bi bi-heart-fill
me-2
"
></i>
Favorita
</span>
<div
v-if=
"mode === 'view'"
class=
"d-flex gap-2"
>
<button
@
click=
"editRecipe"
class=
"btn btn-outline-custom"
>
<i
class=
"bi bi-pencil-square"
></i>
Editar
</button>
<button
@
click=
"
deleteRecipe
"
class=
"btn btn-danger"
>
<button
@
click=
"
openDeleteModal
"
class=
"btn btn-danger"
>
<i
class=
"bi bi-trash"
></i>
Eliminar
</button>
</div>
...
...
@@ -120,19 +120,31 @@
</div>
</div>
</div>
<ConfirmModal
modalId=
"deleteRecipeModal"
message=
"¿Estás seguro de que quieres eliminar esta receta? Esta acción es irreversible."
@
confirmed=
"deleteRecipe"
/>
</template>
<
script
setup
>
import
ConfirmModal
from
'@/components/ConfirmModal.vue'
;
import
{
useRecipeStore
}
from
'@/stores/recipeStore'
;
import
{
computed
,
onMounted
,
ref
}
from
'vue'
;
import
{
useRoute
}
from
'vue-router'
;
import
{
useRoute
,
useRouter
}
from
'vue-router'
;
import
defaultImage
from
'@/assets/default-recipe.jpg'
;
import
*
as
bootstrap
from
'bootstrap'
;
// Estado de la vista: 'view' o 'edit'
const
mode
=
ref
(
'view'
);
const
recipeStore
=
useRecipeStore
();
const
route
=
useRoute
();
const
router
=
useRouter
();
// Id de la receta a eliminar
const
recipeToDeleteId
=
ref
(
null
);
// Usa una propiedad computada para acceder al estado reactivo del store
const
recipe
=
computed
(()
=>
recipeStore
.
recipe
);
...
...
@@ -165,6 +177,24 @@ const processedIngredients = computed(() => {
};
});
});
// Funciones para eliminar la receta
const
openDeleteModal
=
()
=>
{
// Guarda el ID de la receta actual
recipeToDeleteId
.
value
=
recipe
.
value
.
id
;
// Muestra el modal de Bootstrap
const
deleteModal
=
new
bootstrap
.
Modal
(
document
.
getElementById
(
'deleteRecipeModal'
));
deleteModal
.
show
();
};
const
deleteRecipe
=
async
()
=>
{
if
(
!
recipeToDeleteId
.
value
)
return
;
await
recipeStore
.
delete
(
recipeToDeleteId
.
value
);
// Redirige al usuario a la página de recetas después de eliminar
router
.
push
(
'/recipes'
);
};
</
script
>
<
style
scoped
>
...
...
@@ -244,5 +274,6 @@ textarea {
.badge-custom
{
background-color
:
#793E6C
;
color
:
white
;
font-size
:
14px
;
}
</
style
>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment