merge
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
// imports
|
||||
|
||||
import { useQuery } from "@tanstack/vue-query";
|
||||
import { API_ENDPOINTS, QUERY_KEYS } from "~/constants";
|
||||
|
||||
// types
|
||||
|
||||
export type GetArticleResponse = Article;
|
||||
|
||||
const useGetArticle = (id: number | string | undefined) => {
|
||||
|
||||
// state
|
||||
|
||||
const { $axios: axios } = useNuxtApp();
|
||||
|
||||
// methods
|
||||
|
||||
const handleGetArticle = async () => {
|
||||
const { data } = await axios.get<GetArticleResponse>(`${API_ENDPOINTS.blog.article}/${id}`);
|
||||
return data;
|
||||
};
|
||||
|
||||
return useQuery({
|
||||
queryKey: [QUERY_KEYS.article, id],
|
||||
queryFn: () => handleGetArticle()
|
||||
});
|
||||
};
|
||||
|
||||
export default useGetArticle;
|
||||
@@ -5,11 +5,11 @@ import { API_ENDPOINTS, QUERY_KEYS } from "~/constants";
|
||||
|
||||
// types
|
||||
|
||||
export type GetArticlesResponse = ApiPaginated<UserComment>;
|
||||
export type GetArticlesResponse = ApiPaginated<Article>;
|
||||
|
||||
const useGetArticles = (
|
||||
page: Ref<number>,
|
||||
search: Ref<string>
|
||||
search?: Ref<string>
|
||||
) => {
|
||||
|
||||
// state
|
||||
@@ -23,7 +23,7 @@ const useGetArticles = (
|
||||
params: {
|
||||
offset: (page.value * 10) - 10,
|
||||
limit: 10,
|
||||
search: search.value.length > 0 ? search.value : undefined,
|
||||
search: search ? (search.value.length > 0 ? search.value : undefined) : undefined,
|
||||
}
|
||||
});
|
||||
return data;
|
||||
|
||||
Reference in New Issue
Block a user