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
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
30 changes: 19 additions & 11 deletions src/services/recipeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,28 +537,36 @@ export const getRecipeStats = async (userId?: string): Promise<{
userRecipes: number;
approved: number;
}> => {
const { count: total } = await supabase
const totalPromise = supabase
.from('crazy_recipes')
.select('*', { count: 'exact', head: true });

const { count: approved } = await supabase
const approvedPromise = supabase
.from('crazy_recipes')
.select('*', { count: 'exact', head: true })
.eq('is_approved', true);

let userRecipes = 0;
if (userId) {
const { count } = await supabase
.from('crazy_recipes')
.select('*', { count: 'exact', head: true })
.eq('author_id', userId);
userRecipes = count || 0;
}
const userRecipesPromise = userId
? supabase
.from('crazy_recipes')
.select('*', { count: 'exact', head: true })
.eq('author_id', userId)
: Promise.resolve({ count: 0 });

const [
{ count: total },
{ count: approved },
{ count: userRecipesCount }
] = await Promise.all([
totalPromise,
approvedPromise,
userRecipesPromise
]);

return {
total: total || 0,
approved: approved || 0,
userRecipes
userRecipes: userRecipesCount || 0
};
};

Expand Down