From 99d29646e281352e69ecf02eae448a754eacc399 Mon Sep 17 00:00:00 2001 From: sebastjanartic <45803536-sebastjanartic@users.noreply.replit.com> Date: Thu, 28 Aug 2025 17:12:21 +0000 Subject: [PATCH] Improve video recommendations with server-side search filtering Refactors the video recommendation fetching logic to utilize the existing search endpoint on the backend for filtering, improving efficiency and consistency. Replit-Commit-Author: Agent Replit-Commit-Session-Id: d7424866-83d1-4486-a212-ac12b4c7becf Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/8cc42625-c1f5-4e43-99bd-77f2c4dedee2/d7424866-83d1-4486-a212-ac12b4c7becf/ROSfcPv --- client/src/pages/VideoPage.tsx | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/client/src/pages/VideoPage.tsx b/client/src/pages/VideoPage.tsx index 3757617..dd04ab8 100644 --- a/client/src/pages/VideoPage.tsx +++ b/client/src/pages/VideoPage.tsx @@ -62,29 +62,21 @@ export default function VideoPage() { enabled: !!videoId, }); - // Fetch recommended videos (excluding current video) + // Fetch recommended videos using the same search endpoint as main page const { data: recommendedResponse } = useQuery({ - queryKey: ["/api/videos"], - queryFn: () => fetch("/api/videos?limit=20&offset=0").then(res => res.json()), + queryKey: ["/api/videos", sidebarSearchQuery], + queryFn: () => { + const url = sidebarSearchQuery && sidebarSearchQuery.length >= 2 + ? `/api/videos?limit=50&offset=0&search=${encodeURIComponent(sidebarSearchQuery)}` + : "/api/videos?limit=50&offset=0"; + return fetch(url).then(res => res.json()); + }, enabled: !!videoId, }); - // Filter recommended videos based on search and exclude current video + // Simply exclude current video - search filtering is now done server-side const filteredRecommendedVideos = (recommendedResponse?.videos || []) - .filter(v => v.id !== videoId) - .filter(video => { - if (!sidebarSearchQuery || sidebarSearchQuery.length < 2) return true; - const searchLower = sidebarSearchQuery.toLowerCase(); - const titleMatch = video.title?.toLowerCase().includes(searchLower); - const descMatch = video.description?.toLowerCase().includes(searchLower); - - // Debug logging - if (sidebarSearchQuery.length >= 2) { - console.log(`Search "${sidebarSearchQuery}": Video "${video.title}" - Title match: ${titleMatch}, Desc match: ${descMatch}`); - } - - return titleMatch || descMatch; - }); + .filter(v => v.id !== videoId);