fix(front): fix tag loading

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2023-12-05 08:28:11 +01:00
parent c4d2ec69ad
commit f81472e081
5 changed files with 14 additions and 36 deletions

View File

@@ -1,24 +1,7 @@
import { FILTER_TAGS } from "@/graphql/tags";
import { ITag } from "@/types/tag.model";
import { apolloClient } from "@/vue-apollo";
import { provideApolloClient, useLazyQuery } from "@vue/apollo-composable";
import { useLazyQuery } from "@vue/apollo-composable";
export async function fetchTags(text: string): Promise<ITag[]> {
try {
const { load: loadFetchTagsQuery } = useLazyQuery<
{ tags: ITag[] },
{ filter: string }
>(FILTER_TAGS);
const res = await provideApolloClient(apolloClient)(() =>
loadFetchTagsQuery(FILTER_TAGS, {
filter: text,
})
);
if (!res) return [];
return res.tags;
} catch (e) {
console.error(e);
return [];
}
export function useFetchTags() {
return useLazyQuery<{ tags: ITag[] }, { filter: string }>(FILTER_TAGS);
}