Do the search

This commit is contained in:
2024-06-22 16:54:14 +01:00
parent fadb1bc00a
commit 01002b31a7
10 changed files with 262 additions and 7 deletions

View File

@@ -0,0 +1,45 @@
<script setup>
import {useForm} from "@inertiajs/vue3";
const props = defineProps(['previousSearch'])
const form = useForm({
ingredients: props.previousSearch ?? "",
})
function search() {
if (form.ingredients.trim().length >= 3) {
form.post('/search/recipes', {
onSuccess: params => {
console.log(params)
}
})
}
}
</script>
<template>
<div class="bg-white rounded-md p-4">
<form class="space-y-4" action="" method="post" @submit.prevent="search">
<div>
<label for="ingredients" class="block text-sm font-medium leading-6 text-gray-900">Search Recipes (comma separated list of ingredients)</label>
<div class="mt-2">
<input v-model="form.ingredients" type="text" name="ingredients" id="ingredients" class="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" placeholder="salmon" />
</div>
</div>
<div class="flex justify-end">
<button type="submit" :disabled="form.processing" class="bg-green-500 px-4 py-2 text-white rounded-sm"> Search </button>
</div>
</form>
<progress v-if="form.progress" :value="form.progress.percentage" max="100">
{{ form.progress.percentage }}%
</progress>
</div>
</template>
<style scoped>
</style>

View File

@@ -0,0 +1,43 @@
<script setup>
const props = defineProps({
recipe: {
required: true
}
})
</script>
<template>
<div class="max-w-2xl overflow-hidden bg-white rounded-lg shadow-md dark:bg-gray-800">
<img class="object-cover w-full h-64" :src="recipe.image" :alt="recipe.title">
<div class="p-6 h-full">
<div>
<span class="text-xs font-medium text-blue-600 uppercase dark:text-blue-400">Recipe</span>
<a href="#" class="block mt-2 text-xl font-semibold text-gray-800 transition-colors duration-300 transform dark:text-white hover:text-gray-600 hover:underline" tabindex="0" role="link">{{ recipe.title }}</a>
</div>
<div class="mt-4 border-t border-gray-100 text-white">
<dl class="divide-y divide-gray-100">
<div class="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0">
<dt class="text-sm font-medium leading-6">Used Ingredients ({{ recipe.usedIngredientCount}})</dt>
<dd class="mt-1 text-sm leading-6 sm:col-span-2 sm:mt-0">
{{ recipe.usedIngredients.map((item) => item.name).join(", ") }}
</dd>
</div>
<div class="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0">
<dt class="text-sm font-medium leading-6 ">Missing Ingredients ({{ recipe.missedIngredientCount }})</dt>
<dd class="mt-1 text-sm leading-6 sm:col-span-2 sm:mt-0">
{{ recipe.missedIngredients.map((item) => item.name).join(", ") }}
</dd>
</div>
</dl>
</div>
</div>
</div>
</template>
<style scoped>
</style>

View File

@@ -1,6 +1,9 @@
<script setup>
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue';
import { Head } from '@inertiajs/vue3';
import {Head} from '@inertiajs/vue3';
import RecipeSearchForm from "@/Components/Search/RecipeSearchForm.vue";
</script>
<template>
@@ -13,9 +16,7 @@ import { Head } from '@inertiajs/vue3';
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 text-gray-900">You're logged in!</div>
</div>
<recipe-search-form />
</div>
</div>
</AuthenticatedLayout>

View File

@@ -0,0 +1,44 @@
<script setup>
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout.vue";
import {Head} from "@inertiajs/vue3";
import RecipeSearchForm from "@/Components/Search/RecipeSearchForm.vue";
import RecipeSearchResultCard from "@/Components/Search/RecipeSearchResultCard.vue";
const props = defineProps({
recipes: {
type: Array,
required: true
},
previousSearch: {
required: false
}
})
</script>
<template>
<Head title="Recipe Search"/>
<AuthenticatedLayout>
<template #header>
<h2 class="font-semibold text-xl text-gray-800 leading-tight">Recipes ({{ recipes.length }})</h2>
</template>
<div class="py-12 space-y-4">
<div class="max-w-7xl mx-auto">
<recipe-search-form :previous-search="props.previousSearch" />
</div>
<div class="max-w-7xl mx-auto">
<ul role="list" class="grid grid-cols-1 gap-6 sm:grid-cols-2 md:grid-cols-3 ">
<li v-for="recipe in recipes" :key="recipe.id"
class="col-span-1 flex flex-col divide-y divide-gray-200 rounded-lg text-center">
<recipe-search-result-card :recipe="recipe"/>
</li>
</ul>
</div>
</div>
</AuthenticatedLayout>
</template>
<style scoped>
</style>