From d66c02b7fa99d0fd11be798606e31a8ddd573489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20=C4=B0pek?= Date: Sun, 23 Nov 2025 14:28:59 +0300 Subject: [PATCH] refactor: Remove useRecommendationProfile hook dependency and derive state from props in RecommendationsSection - Replace hook-based state management with direct prop-based state derivation - Implement getEffectiveOS and isProfileComplete as inline functions using profile prop - Remove effectiveProfile intermediate variable and use profile prop directly - Update all references from effectiveProfile to profile throughout component - Simplify component dependencies by removing hook coupling --- src/components/RecommendationsSection.tsx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/components/RecommendationsSection.tsx b/src/components/RecommendationsSection.tsx index f0e8fb9..c5a413f 100644 --- a/src/components/RecommendationsSection.tsx +++ b/src/components/RecommendationsSection.tsx @@ -32,9 +32,11 @@ export function RecommendationsSection({ profile }: RecommendationsSectionProps) { const { t } = useLocale() - const { getEffectiveOS, isProfileComplete } = useRecommendationProfile() - // Override profile from hook with prop - const effectiveProfile = profile + + // Derived state from props + const getEffectiveOS = () => profile.selectedOS || profile.detectedOS || "ubuntu" + const isProfileComplete = () => profile.categories.length > 0 && getEffectiveOS() !== "unknown" + const [recommendations, setRecommendations] = useState([]) const [loading, setLoading] = useState(false) const [error, setError] = useState(null) @@ -59,8 +61,8 @@ export function RecommendationsSection({ }, body: JSON.stringify({ platform_id: getEffectiveOS(), - categories: effectiveProfile.categories, - experienceLevel: effectiveProfile.experienceLevel, + categories: profile.categories, + experienceLevel: profile.experienceLevel, limit: 1000 }) }) @@ -103,7 +105,7 @@ export function RecommendationsSection({ // But for now, let's rely on the cache key changing which includes profile data fetchRecommendations() } - }, [effectiveProfile.categories, effectiveProfile.selectedOS, effectiveProfile.experienceLevel]) + }, [profile.categories, profile.selectedOS, profile.experienceLevel]) const isPackageSelected = (pkg: RecommendedPackage) => { return selectedPackages.some(selected => selected.id === pkg.id) @@ -239,7 +241,7 @@ export function RecommendationsSection({ {getEffectiveOS()} - {effectiveProfile.categories.map(cat => ( + {profile.categories.map(cat => ( All ({recommendations.length}) - {effectiveProfile.categories.map(cat => { + {profile.categories.map(cat => { const count = getCategoryCount(cat) const Icon = CATEGORY_ICONS[cat] return (