From f382f96fee127c9b4aec818e8e4edbaf563a4083 Mon Sep 17 00:00:00 2001 From: Arthur DANJOU Date: Sun, 3 Sep 2023 23:43:29 +0200 Subject: [PATCH] working on talents actualisation --- src/composables/useTalents.ts | 23 ++++++++- src/pages/talents.vue | 89 +++++++++++------------------------ src/store/color.ts | 2 +- src/store/talents.ts | 30 ++++++++++++ 4 files changed, 80 insertions(+), 64 deletions(-) create mode 100644 src/store/talents.ts diff --git a/src/composables/useTalents.ts b/src/composables/useTalents.ts index f212442..67f2d5e 100644 --- a/src/composables/useTalents.ts +++ b/src/composables/useTalents.ts @@ -1,7 +1,23 @@ +import { useTalentsStore } from '~/store/talents' + export async function useTalents() { const { $trpc } = useNuxtApp() + const { setCategory, setFavorite, getCategory, isFavorite } = useTalentsStore() - const getTalents = async (category: string, favorite: boolean) => await $trpc.talents.getTalents.query({ favorite, category }) + const { + data: talents, + refresh: refreshTalents, + } = await useAsyncData('talents:talents', async () => await $trpc.talents.getTalents.query({ favorite: isFavorite.value, category: getCategory.value })) + + async function switchCategory(category: string) { + setCategory(category) + await refreshTalents() + } + + async function toggleFavorite() { + setFavorite() + await refreshTalents() + } const { data: getCategories, @@ -12,8 +28,11 @@ export async function useTalents() { } return { - getTalents, + talents, getCategories, getCategoryById, + isFavorite, + switchCategory, + toggleFavorite, } } diff --git a/src/pages/talents.vue b/src/pages/talents.vue index 8577990..95e770e 100644 --- a/src/pages/talents.vue +++ b/src/pages/talents.vue @@ -1,31 +1,12 @@