Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions src/hooks/useRecipeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState, useEffect, useCallback } from 'react';
import { useToast } from '@/hooks/use-toast';
import { useAuth } from '@/hooks/useAuth';
import * as recipeService from '@/services/recipeService';
import type { CrazyRecipe, RecipeReview } from '@/services/recipeService';
import type { CrazyRecipe, RecipeReview, GetRecipesOptions } from '@/services/recipeService';

export const useRecipeService = () => {
const { user } = useAuth();
Expand Down Expand Up @@ -155,16 +155,14 @@ export const useRecipeService = () => {
}
}, [toast]);

const getRecipesWithPagination = useCallback(async (
page: number = 1,
limit: number = 10,
approvedOnly: boolean = true
const getRecipes = useCallback(async (
options: GetRecipesOptions
): Promise<{recipes: CrazyRecipe[], total: number}> => {
setLoading(true);
setError(null);

try {
const result = await recipeService.getRecipesWithPagination(page, limit, approvedOnly);
const result = await recipeService.getRecipes(options);
return {
recipes: result.data,
total: result.count
Expand All @@ -183,6 +181,20 @@ export const useRecipeService = () => {
}
}, [toast]);

const getRecipesWithPagination = useCallback(async (
page: number = 1,
limit: number = 10,
approvedOnly: boolean = true
): Promise<{recipes: CrazyRecipe[], total: number}> => {
return getRecipes({
page,
pageSize: limit,
approvedOnly,
filterType: 'all',
sortBy: 'newest'
});
}, [getRecipes]);

// ========================================
// CREATE OPERATIONS
// ========================================
Expand Down Expand Up @@ -503,6 +515,7 @@ export const useRecipeService = () => {
getRecipesByAuthorName,
searchRecipes,
filterRecipesByType,
getRecipes,
getRecipesWithPagination,

// Create operations
Expand Down
2 changes: 0 additions & 2 deletions src/pages/CrazyRecipeDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { Label } from '@/components/ui/label';
import Navbar from '@/components/Navbar';
import Footer from '@/components/Footer';
import { useAuth } from '@/hooks/useAuth';
import { useAdmin } from '@/hooks/useAdmin';
import { useToast } from '@/hooks/use-toast';
import { useRecipeService } from '@/hooks/useRecipeService';
import type { CrazyRecipe, RecipeReview } from '@/services/recipeService';
Expand All @@ -24,7 +23,6 @@ import {
const CrazyRecipeDetail = () => {
const { id } = useParams<{ id: string }>();
const { user } = useAuth();
const { isAdmin } = useAdmin();
const { toast } = useToast();
const navigate = useNavigate();
const { getRecipeById, deleteRecipe, incrementViews: serviceIncrementViews, getRecipeReviews, submitReview } = useRecipeService();
Expand Down
Loading