feat(dimentorin): articles page integrated with API (list, filter, detail)
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import { useMutation, useQuery, UseQueryResult } from '@tanstack/react-query';
|
||||
import {
|
||||
getArticleById,
|
||||
getArticleBySlug,
|
||||
getArticleCategories,
|
||||
getArticles,
|
||||
getMentorAvailability,
|
||||
getMentorDetail,
|
||||
getMentorMe,
|
||||
@@ -11,6 +15,9 @@ import {
|
||||
postSessionFeedback,
|
||||
} from '../../api/dimentorin';
|
||||
import {
|
||||
TArticleDetail,
|
||||
TArticleListItem,
|
||||
TArticleListParams,
|
||||
TBookSessionRequest,
|
||||
TMentorAvailability,
|
||||
TMentorDetail,
|
||||
@@ -105,4 +112,43 @@ export const usePostSessionFeedback = (sessionId: string) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetArticles = (
|
||||
params?: TArticleListParams
|
||||
): UseQueryResult<TArticleListItem[], TResponseError> => {
|
||||
return useQuery({
|
||||
queryKey: ['get-articles', params],
|
||||
queryFn: async () => await getArticles(params),
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetArticleCategories = (): UseQueryResult<
|
||||
string[],
|
||||
TResponseError
|
||||
> => {
|
||||
return useQuery({
|
||||
queryKey: ['get-article-categories'],
|
||||
queryFn: async () => await getArticleCategories(),
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetArticleBySlug = (
|
||||
slug: string
|
||||
): UseQueryResult<TArticleDetail, TResponseError> => {
|
||||
return useQuery({
|
||||
queryKey: ['get-article-by-slug', slug],
|
||||
queryFn: async () => await getArticleBySlug(slug),
|
||||
enabled: !!slug,
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetArticleById = (
|
||||
id: string
|
||||
): UseQueryResult<TArticleDetail, TResponseError> => {
|
||||
return useQuery({
|
||||
queryKey: ['get-article-by-id', id],
|
||||
queryFn: async () => await getArticleById(id),
|
||||
enabled: !!id,
|
||||
});
|
||||
};
|
||||
|
||||
export type { TResponseMessage };
|
||||
|
||||
Reference in New Issue
Block a user