mirror of
https://github.com/ArthurDanjou/website.git
synced 2026-01-23 16:30:38 +01:00
use h3 instead of trpc
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user