mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-11 17:16:59 -05:00
first steps to advanced search
This commit is contained in:
@@ -91,21 +91,20 @@ const searchResults = computed(() => {
|
||||
let searchResults = [] as Array<SearchResult>
|
||||
|
||||
if (searchQuery.value != '' && searchQuery.value != null) {
|
||||
// TODO add link to advanced search once it exists
|
||||
//searchResults.push({name: searchQuery.value, icon: 'fas fa-search', suffix: 'Advanced Search'} as SearchResult)
|
||||
|
||||
flatRecipes.value.filter(fr => fr.name.toLowerCase().includes(searchQuery.value.toLowerCase())).slice(0, 10).forEach(r => {
|
||||
searchResults.push({name: r.name, image: r.image, recipeId: r.id} as SearchResult)
|
||||
searchResults.push({name: r.name, image: r.image, recipeId: r.id, type: "recipe"} as SearchResult)
|
||||
})
|
||||
|
||||
if (searchResults.length < 3) {
|
||||
asyncSearchResults.value.slice(0, 5).forEach(r => {
|
||||
if (searchResults.findIndex(x => x.recipeId == r.id) == -1) {
|
||||
searchResults.push({name: r.name, image: r.image, recipeId: r.id})
|
||||
searchResults.push({name: r.name, image: r.image, recipeId: r.id, type: "recipe"})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
searchResults.push({name: searchQuery.value, icon: 'fas fa-search', type: "link_advanced_search"} as SearchResult)
|
||||
|
||||
} else {
|
||||
// show first 5 recipes by default
|
||||
|
||||
@@ -212,10 +211,17 @@ function cardVariant(index: number) {
|
||||
function goToSelectedRecipe(index: number) {
|
||||
dialog.value = false
|
||||
let searchResult = searchResults.value[index]
|
||||
console.log('going to', searchResult.recipeId)
|
||||
if (searchResult.recipeId != null) {
|
||||
router.push({name: 'view_recipe', params: {'id': searchResult.recipeId}})
|
||||
|
||||
if (searchResult.type == 'link_advanced_search') {
|
||||
router.push({name: 'view_search', query: {'query': searchQuery.value}})
|
||||
} else {
|
||||
console.log('going to', searchResult.recipeId)
|
||||
if (searchResult.recipeId != null) {
|
||||
router.push({name: 'view_recipe', params: {'id': searchResult.recipeId}})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
:on-create="createObject"
|
||||
:createOption="props.allowCreate"
|
||||
:delay="300"
|
||||
:object="true"
|
||||
:object="props.object"
|
||||
:valueProp="itemValue"
|
||||
:label="itemLabel"
|
||||
:searchable="true"
|
||||
@@ -72,6 +72,7 @@ const props = defineProps({
|
||||
|
||||
mode: {type: String as PropType<'single' | 'multiple' | 'tags'>, default: 'single'},
|
||||
appendToBody: {type: Boolean, default: false},
|
||||
object: {type: Boolean, default: true},
|
||||
|
||||
allowCreate: {type: Boolean, default: false},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user