1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-08-02 20:15:24 +02:00

refator: reuse search page component (#2240)

* wip: fix recipe card section

* refactor basic search to share composable

* fix dialog results

* use search for cat/tag/tool pages

* update organizer to support name edits

* fix composable typing
This commit is contained in:
Hayden 2023-03-12 12:59:28 -08:00 committed by GitHub
parent b06517fdf4
commit 9650ba9b00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 205 additions and 538 deletions

View file

@ -0,0 +1,64 @@
import { Ref, ref } from "@nuxtjs/composition-api";
import { watchDebounced } from "@vueuse/core";
import { UserApi } from "~/lib/api";
import { Recipe } from "~/lib/api/types/recipe";
export interface UseRecipeSearchReturn {
query: Ref<string>;
error: Ref<string>;
loading: Ref<boolean>;
data: Ref<Recipe[]>;
}
/**
* `useRecipeSearch` constructs a basic reactive search query
* that when `query` is changed, will search for recipes based
* on the query. Useful for searchable list views. For advanced
* search, use the `useRecipeQuery` composable.
*/
export function useRecipeSearch(api: UserApi): UseRecipeSearchReturn {
const query = ref("");
const error = ref("");
const loading = ref(false);
const recipes = ref<Recipe[]>([]);
async function searchRecipes(term: string) {
loading.value = true;
const { data, error } = await api.recipes.search({
search: term,
page: 1,
orderBy: "name",
orderDirection: "asc",
perPage: 20,
});
if (error) {
console.error(error);
loading.value = false;
recipes.value = [];
return;
}
if (data) {
recipes.value= data.items;
}
loading.value = false;
}
watchDebounced(
() => query.value,
async (term: string) => {
await searchRecipes(term);
},
{ debounce: 500 }
);
return {
query,
error,
loading,
data: recipes,
}
}

View file

@ -7,7 +7,13 @@ export interface ContextMenuItem {
color?: string;
}
export function useContextPresets(): { [key: string]: ContextMenuItem } {
export interface ContextMenuPresets {
delete: ContextMenuItem;
edit: ContextMenuItem;
save: ContextMenuItem;
}
export function useContextPresets(): ContextMenuPresets {
const { $globals, i18n } = useContext();
return {