This commit is contained in:
marzban-dev
2025-11-01 20:35:55 +03:30
parent 6524ae7605
commit 4fde6357d1
16 changed files with 292 additions and 67 deletions
+14 -13
View File
@@ -15,6 +15,10 @@ const useGetChat = (productId: string | number, enabled: Ref<boolean>) => {
const { isLoggedIn } = useAuth();
const isEnabled = computed(() => {
return enabled.value && isLoggedIn.value;
});
// methods
const handleGetChat = async ({
@@ -26,23 +30,20 @@ const useGetChat = (productId: string | number, enabled: Ref<boolean>) => {
limit: number;
offset: number;
}) => {
const { data } = await axios.get<GetChatResponse>(
`${API_ENDPOINTS.chat.messages}/${productId}`,
{
params: {
offset,
limit,
},
headers: {
Authorization: `Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoyMTY3ODE2OTAwLCJpYXQiOjE3MzU4MTY5MDAsImp0aSI6ImQwN2E2Y2Y2NzgwZjRlNTE5NWIzOGQxMTAzYzU4NDQ3IiwidXNlcl9pZCI6NX0.slwd7ZSV7nUXEuDTYwwHUOo9ekCefwEEL4kVv2vSTFo`,
},
}
);
const { data } = await axios.get<GetChatResponse>(`${API_ENDPOINTS.chat.messages}/${productId}`, {
params: {
offset,
limit,
},
headers: {
Authorization: `Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoyMTY3ODE2OTAwLCJpYXQiOjE3MzU4MTY5MDAsImp0aSI6ImQwN2E2Y2Y2NzgwZjRlNTE5NWIzOGQxMTAzYzU4NDQ3IiwidXNlcl9pZCI6NX0.slwd7ZSV7nUXEuDTYwwHUOo9ekCefwEEL4kVv2vSTFo`,
},
});
return data;
};
return useInfiniteQuery({
enabled: isLoggedIn,
enabled: isEnabled,
queryKey: [QUERY_KEYS.chat],
initialPageParam: {
limit: 10,
@@ -0,0 +1,29 @@
// imports
import { useMutation } from "@tanstack/vue-query";
import { API_ENDPOINTS } from "~/constants";
// types
export type SaveProductRequest = {
product_slug: string;
};
const useSaveProduct = () => {
// state
const { $axios: axios } = useNuxtApp();
// methods
const handleSaveProduct = async (variables: SaveProductRequest) => {
const { data } = await axios.post(`${API_ENDPOINTS.product.save}`, variables);
return data;
};
return useMutation({
mutationFn: (variables: SaveProductRequest) => handleSaveProduct(variables),
});
};
export default useSaveProduct;
@@ -0,0 +1,40 @@
// imports
import { useQuery } from "@tanstack/vue-query";
import { useAppParams } from "~/composables/global/useAppParams";
import { API_ENDPOINTS, QUERY_KEYS } from "~/constants";
// types
export type GetSavedProductsResponse = ApiPaginated<ProductListItem>;
// composable
const useGetSavedProducts = () => {
// state
const { $axios: axios } = useNuxtApp();
const { page } = useAppParams();
// methods
const handleGetSavedProducts = async ({ signal }: { signal: AbortSignal }) => {
const { data } = await axios.get<GetSavedProductsResponse>(`${API_ENDPOINTS.products.saved}`, {
params: {
offset: Number(page.value) * 15 - 15,
limit: 15,
},
signal,
});
return data;
};
return useQuery({
queryKey: [QUERY_KEYS.saved_products, page],
queryFn: ({ signal }) => handleGetSavedProducts({ signal }),
});
};
export default useGetSavedProducts;