Files
Folo/apps/ssr/client/query/list.ts
T
Innei a92bdb89b3 feat(user-profile): integrate user lists and subscriptions in profile page
- Added functionality to fetch and display user-created lists alongside subscriptions.
- Introduced new components for rendering lists and subscriptions with loading states.
- Updated metadata fetching to include lists data for user profiles.
- Refactored user subscriptions query for better data handling.

Signed-off-by: Innei <tukon479@gmail.com>
2025-06-09 21:20:22 +08:00

33 lines
1.0 KiB
TypeScript

import { apiClient } from "@client/lib/api-fetch"
import { getHydrateData } from "@client/lib/helper"
import { useQuery } from "@tanstack/react-query"
const fetchListById = async (id: string) => {
const res = await apiClient.lists.$get({ query: { listId: id } })
return res.data
}
export const useList = ({ id }: { id?: string }) =>
useQuery({
queryKey: ["lists", id],
queryFn: () => fetchListById(id!),
enabled: !!id,
initialData: getHydrateData(`lists.$get,query:listId=${id}`) as any as Awaited<
ReturnType<typeof fetchListById>
>,
})
const fetchListsByUserId = async (userId: string) => {
const res = await apiClient.lists.list.$get({ query: { userId } })
return res.data
}
export const useListsByUserId = (userId: string) =>
useQuery({
queryKey: ["lists", userId],
queryFn: () => fetchListsByUserId(userId),
enabled: !!userId,
initialData: getHydrateData(`lists.list.$get,query:userId=${userId}`) as any as Awaited<
ReturnType<typeof fetchListsByUserId>
>,
})