From ed8ab47bdd19143c884d5ecf9d977b280f587d3e Mon Sep 17 00:00:00 2001 From: t0is Date: Fri, 25 Apr 2025 15:01:38 +0200 Subject: [PATCH] has clips filter --- src/app/Http/Controllers/VideoController.php | 4 ++ src/resources/js/Pages/Videos.tsx | 48 +++++++++++++------- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/app/Http/Controllers/VideoController.php b/src/app/Http/Controllers/VideoController.php index eae5a13..ae1dea1 100644 --- a/src/app/Http/Controllers/VideoController.php +++ b/src/app/Http/Controllers/VideoController.php @@ -37,6 +37,10 @@ class VideoController extends Controller $query->whereBetween('external_date', [$request->input('start_date'), $request->input('end_date')]); } + if ($request->get('clipExists') === "true") { + $query->has('clips'); + } + // Retrieve the videos (you can add pagination if desired) $videos = $query->orderBy('external_date', 'desc')->get(); diff --git a/src/resources/js/Pages/Videos.tsx b/src/resources/js/Pages/Videos.tsx index 77e8403..4ce0183 100644 --- a/src/resources/js/Pages/Videos.tsx +++ b/src/resources/js/Pages/Videos.tsx @@ -21,10 +21,12 @@ export default function Videos() { // Filter states const [selectedChannelIds, setSelectedChannelIds] = useState([]); const [selectedLanguages, setSelectedLanguages] = useState([]); + const [clipExistsCheckbox, setClipExistsCheckbox] = useState(false); const [startDate, setStartDate] = useState(''); const [endDate, setEndDate] = useState(''); + // (1) Initial fetch on mount to get all channels and compute distinct languages (runs only once) useEffect(() => { setLoadingChannels(true); @@ -64,7 +66,7 @@ export default function Videos() { // Fetch clips when filters change (including videoId) useEffect(() => { setLoadingVideos(true); - const params: Record = {}; + const params: Record = {}; if (selectedChannelIds.length > 0) { params.channel_ids = selectedChannelIds.filter(id => id !== ''); @@ -74,6 +76,7 @@ export default function Videos() { } if (startDate) params.start_date = startDate; if (endDate) params.end_date = endDate; + params.clipExists = clipExistsCheckbox; axios.get('/api/videos/get', { params }) .then(response => { @@ -84,7 +87,7 @@ export default function Videos() { console.error('Error fetching clips:', error); setLoadingVideos(false); }); - }, [selectedChannelIds, selectedLanguages, startDate, endDate]); + }, [selectedChannelIds, selectedLanguages, startDate, endDate, clipExistsCheckbox]); return (
{/* Filter Options */} -
+
{/* Channel Filter */} -
+
{loadingChannels ? ( @@ -120,9 +123,9 @@ export default function Videos() { )}
{/* Language Filter */} -
+
{loadingChannels ? ( @@ -138,10 +141,26 @@ export default function Videos() { /> )}
- {/* Start Date Filter */} -
+ {/* Clip exists filter */} +
+ {loadingChannels ? ( + + ) : ( + setClipExistsCheckbox(e.target.checked)} + /> + )} +
+ {/* Start Date Filter */} +
+
{/* End Date Filter */} -
+
setEndDate(e.target.value)} />
-
- -
- +
{/* head */}