use h3 instead of trpc

This commit is contained in:
2023-12-09 21:26:41 +01:00
parent f0aa9ebdf4
commit ba067cf533
25 changed files with 1395 additions and 940 deletions

View File

@@ -1,23 +1,24 @@
export async function usePost(slug: string) {
const { $trpc } = useNuxtApp()
const {
data: post,
refresh: refreshPost,
} = await useAsyncData(`blog:post-db:${slug}`, async () => await $trpc.post.createOrUpdate.mutate({
slug,
}))
} = useFetch('/api/article', {
method: 'POST',
body: {
slug,
},
})
const likes = ref(post.value!.likes)
const likes = ref(post.value?.likes)
const like = async () => {
const data = await $trpc.post.like.mutate({ slug })
likes.value = data.likes
const { data } = await useFetch('/api/like', { method: 'PUT' })
likes.value = data
}
const views = ref(post.value!.views)
const view = async () => {
const data = await $trpc.post.view.mutate({ slug })
views.value = data.views
const { data } = await useFetch('/api/view', { method: 'PUT' })
likes.value = data
}
return {

View File

@@ -1,40 +0,0 @@
import { useTalentsStore } from '~/store/talents'
export async function useTalents() {
const { $trpc } = useNuxtApp()
const { setCategory, setFavorite, getCategory, isFavorite } = useTalentsStore()
const {
data: talents,
refresh: refreshTalents,
pending,
} = 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()
}
function isCategory(category: string) {
return getCategory.value === category
}
const {
data: getCategories,
} = await $trpc.talents.getCategories.useQuery()
return {
talents,
getCategories,
isFavorite,
switchCategory,
toggleFavorite,
pending,
isCategory,
}
}