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
96bb2d32
authored
Sep 05, 2025
by
Alba María Álvarez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
feat(Recipes): implementada funcionalidad para buscar recetas
parent
52f51b56
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
4 deletions
src/views/Recipes.vue
src/views/Recipes.vue
View file @
96bb2d32
<
template
>
<section
class=
"bg-custom py-5 flex-grow-1"
>
<div
class=
"container px-4 px-lg-5 mt-1"
>
<div
class=
"d-flex justify-content-center mb-4"
>
<div
class=
"input-group"
style=
"max-width: 500px;"
>
<input
type=
"text"
class=
"form-control"
placeholder=
"Buscar por nombre o ingrediente..."
aria-label=
"Buscar recetas"
v-model=
"searchQuery"
@
input=
"handleSearch"
/>
</div>
</div>
<div
class=
"d-flex justify-content-between align-items-center mb-4"
>
<div>
<label>
...
...
@@ -59,20 +67,48 @@
<
script
setup
>
import
RecipeCard
from
'@/components/RecipeCard.vue'
;
import
{
useRecipeStore
}
from
'@/stores/recipeStore'
;
import
{
onMounted
,
watch
}
from
'vue'
;
import
{
onMounted
,
ref
,
watch
}
from
'vue'
;
const
recipeStore
=
useRecipeStore
();
// Variables para la búsqueda
const
searchQuery
=
ref
(
''
);
let
searchTimeout
=
null
;
onMounted
(()
=>
{
recipeStore
.
readAll
(
0
,
recipeStore
.
pageSize
,
recipeStore
.
sortDirection
);
});
watch
(()
=>
recipeStore
.
pageSize
,
(
newSize
)
=>
{
recipeStore
.
readAll
(
0
,
newSize
,
recipeStore
.
sortDirection
);
// Cuando cambia el tamaño de página, se mantiene el estado de la búsqueda
if
(
searchQuery
.
value
)
{
recipeStore
.
search
(
searchQuery
.
value
,
0
,
newSize
);
}
else
{
recipeStore
.
readAll
(
0
,
newSize
,
recipeStore
.
sortDirection
);
}
});
const
goToPage
=
(
page
)
=>
{
recipeStore
.
readAll
(
page
,
recipeStore
.
pageSize
,
recipeStore
.
sortDirection
);
// Comprueba si hay alguna consulta
if
(
searchQuery
.
value
)
{
recipeStore
.
search
(
searchQuery
.
value
,
page
,
recipeStore
.
pageSize
);
}
else
{
recipeStore
.
readAll
(
page
,
recipeStore
.
pageSize
,
recipeStore
.
sortDirection
);
}
};
// Función para la búsqueda
const
handleSearch
=
()
=>
{
clearTimeout
(
searchTimeout
);
searchTimeout
=
setTimeout
(()
=>
{
if
(
searchQuery
.
value
===
''
)
{
// Si el campo de búsqueda está vacío, carga todas las recetas
recipeStore
.
readAll
(
0
,
recipeStore
.
pageSize
,
recipeStore
.
sortDirection
);
}
else
{
// Si hay un valor, realiza la búsqueda
recipeStore
.
search
(
searchQuery
.
value
,
0
,
recipeStore
.
pageSize
);
}
},
500
);
// 500ms de retraso
};
</
script
>
...
...
@@ -118,7 +154,7 @@ const goToPage = (page) => {
color
:
white
;
}
.form-select
:focus
{
.form-select
:focus
,
.form-control
:focus
{
border-color
:
#793E6C
;
box-shadow
:
0
0
0
0.25rem
rgba
(
121
,
62
,
108
,
0.25
);
}
...
...
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