From cbed467589d74022c4a1b49167d237d85663ab96 Mon Sep 17 00:00:00 2001 From: A Farzat Date: Mon, 6 Oct 2025 14:29:43 +0300 Subject: Add the front-end component --- front-end/src/App.css | 322 +++++++++++++++++++++++++++++++++++++++++ front-end/src/App.jsx | 298 ++++++++++++++++++++++++++++++++++++++ front-end/src/assets/react.svg | 1 + front-end/src/main.jsx | 9 ++ 4 files changed, 630 insertions(+) create mode 100644 front-end/src/App.css create mode 100644 front-end/src/App.jsx create mode 100644 front-end/src/assets/react.svg create mode 100644 front-end/src/main.jsx (limited to 'front-end/src') diff --git a/front-end/src/App.css b/front-end/src/App.css new file mode 100644 index 0000000..1548a0d --- /dev/null +++ b/front-end/src/App.css @@ -0,0 +1,322 @@ +/* src/App.css */ +body { + margin: 0; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', + 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', + sans-serif; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +.App { + text-align: center; + min-height: 100vh; + background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); +} + +.App-header { + background: rgba(255, 255, 255, 0.1); + padding: 2rem; + backdrop-filter: blur(10px); + border-bottom: 1px solid rgba(255, 255, 255, 0.2); +} + +.App-header h1 { + color: white; + margin-bottom: 1.5rem; + font-size: 2.5rem; + text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3); +} + +.channel-selector { + max-width: 600px; + margin: 0 auto; +} + +.selector-header { + display: flex; + justify-content: space-between; + align-items: center; + margin-bottom: 0.5rem; +} + +.selector-header label { + color: white; + font-size: 1.1rem; + font-weight: bold; +} + +.refresh-button { + padding: 0.4rem 0.8rem; + border: none; + border-radius: 15px; + background: rgba(255, 255, 255, 0.2); + color: white; + cursor: pointer; + font-size: 0.9rem; + transition: all 0.3s ease; +} + +.refresh-button:hover:not(:disabled) { + background: rgba(255, 255, 255, 0.3); + transform: rotate(45deg); +} + +.refresh-button:disabled { + opacity: 0.6; + cursor: not-allowed; +} + +.channel-select { + width: 100%; + padding: 0.8rem 1.2rem; + border: none; + border-radius: 25px; + font-size: 1rem; + background: rgba(255, 255, 255, 0.9); + box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1); + margin-bottom: 1rem; +} + +.channel-select:focus { + outline: none; + box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2); +} + +.channel-info { + color: rgba(255, 255, 255, 0.9); + font-size: 0.9rem; +} + +.channel-info strong { + color: #74b9ff; +} + +.main-content { + padding: 2rem; + max-width: 1200px; + margin: 0 auto; +} + +.loading, .error, .no-channels, .no-videos, .no-selection { + color: white; + font-size: 1.2rem; + padding: 2rem; + background: rgba(255, 255, 255, 0.1); + border-radius: 15px; + backdrop-filter: blur(10px); + margin: 1rem 0; +} + +.error { + color: #ff6b6b; +} + +.no-channels, .no-selection { + color: #ffd93d; +} + +.no-videos { + color: #ffd93d; +} + +.retry-button { + margin-top: 1rem; + padding: 0.5rem 1rem; + border: none; + border-radius: 20px; + background: rgba(255, 255, 255, 0.2); + color: white; + cursor: pointer; + transition: all 0.3s ease; +} + +.retry-button:hover { + background: rgba(255, 255, 255, 0.3); +} + +.videos-container h2 { + color: white; + margin-bottom: 2rem; + font-size: 2rem; + text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3); +} + +.videos-grid { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); + gap: 2rem; + margin-top: 2rem; +} + +.video-card { + background: rgba(255, 255, 255, 0.1); + border-radius: 15px; + overflow: hidden; + backdrop-filter: blur(10px); + border: 1px solid rgba(255, 255, 255, 0.2); + transition: all 0.3s ease; + box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1); +} + +.video-card:hover { + transform: translateY(-5px); + box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2); + border-color: rgba(255, 255, 255, 0.3); +} + +.video-thumbnail { + position: relative; + height: 180px; + overflow: hidden; +} + +.thumbnail-image { + width: 100%; + height: 100%; + object-fit: cover; + transition: transform 0.3s ease; +} + +.video-card:hover .thumbnail-image { + transform: scale(1.05); +} + +.play-button { + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + font-size: 3rem; + color: white; + text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.7); + opacity: 0.9; + transition: all 0.3s ease; +} + +.video-card:hover .play-button { + opacity: 1; + transform: translate(-50%, -50%) scale(1.1); +} + +.video-info { + padding: 1.5rem; + text-align: left; +} + +.video-title { + color: white; + font-size: 1.1rem; + font-weight: bold; + margin-bottom: 0.8rem; + line-height: 1.4; + display: -webkit-box; + -webkit-line-clamp: 2; + -webkit-box-orient: vertical; + overflow: hidden; + position: relative; + cursor: help; +} + +.video-author, .video-date { + color: rgba(255, 255, 255, 0.8); + font-size: 0.9rem; + margin-bottom: 0.5rem; +} + +.channel-link { + color: #74b9ff; + text-decoration: none; +} + +.channel-link:hover { + text-decoration: underline; +} + +.video-summary { + margin: 1rem 0; + padding: 0.8rem; + background: rgba(255, 255, 255, 0.1); + border-radius: 8px; + border-left: 3px solid #74b9ff; +} + +.video-summary p { + color: rgba(255, 255, 255, 0.9); + font-size: 0.85rem; + line-height: 1.4; + margin: 0; + transition: all 0.3s ease; +} + +.video-summary p.collapsed { + display: -webkit-box; + -webkit-line-clamp: 3; + -webkit-box-orient: vertical; + overflow: hidden; +} + +.video-summary p.expanded { + display: block; + overflow: visible; +} + +.expand-button { + background: rgba(255, 255, 255, 0.15); + border: 1px solid rgba(255, 255, 255, 0.3); + color: #74b9ff; + padding: 0.3rem 0.8rem; + border-radius: 12px; + font-size: 0.75rem; + cursor: pointer; + margin-top: 0.5rem; + transition: all 0.3s ease; +} + +.expand-button:hover { + background: rgba(255, 255, 255, 0.25); + transform: translateY(-1px); +} + +.video-actions { + margin-top: 1rem; +} + +.watch-button { + display: inline-block; + padding: 0.6rem 1.2rem; + background: #ff4757; + color: white; + text-decoration: none; + border-radius: 20px; + font-weight: bold; + transition: all 0.3s ease; + font-size: 0.9rem; +} + +.watch-button:hover { + background: #ff6b81; + transform: translateY(-2px); + box-shadow: 0 4px 15px rgba(255, 71, 87, 0.3); +} + +/* Responsive design */ +@media (max-width: 768px) { + .selector-header { + flex-direction: column; + gap: 0.5rem; + align-items: flex-start; + } + + .videos-grid { + grid-template-columns: 1fr; + } + + .App-header h1 { + font-size: 2rem; + } + + .video-info { + padding: 1rem; + } +} diff --git a/front-end/src/App.jsx b/front-end/src/App.jsx new file mode 100644 index 0000000..a540e47 --- /dev/null +++ b/front-end/src/App.jsx @@ -0,0 +1,298 @@ +// src/App.js +import React, { useState, useEffect } from 'react'; +import axios from 'axios'; +import './App.css'; + +const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://127.0.0.1:4000'; + +function App() { + const [videos, setVideos] = useState([]); + const [channels, setChannels] = useState([]); + const [loading, setLoading] = useState(true); + const [channelsLoading, setChannelsLoading] = useState(true); + const [error, setError] = useState(null); + const [selectedChannelId, setSelectedChannelId] = useState(''); + const [expandedDescriptions, setExpandedDescriptions] = useState({}); + + const fetchChannels = async () => { + try { + setChannelsLoading(true); + const response = await axios.get(`${API_BASE_URL}/subs-info`); + + if (response.data && Array.isArray(response.data)) { + const formattedChannels = response.data.map(channel => { + // Extract the channel ID from the _id field + const channelId = channel._id.replace('yt:channel:', ''); + return { + id: channelId, + _id: channel._id, + last_video_update: channel.last_video_update, + new_vids: channel.new_vids, + time_between_fetches: channel.time_between_fetches, + videos: channel.videos + }; + }); + setChannels(formattedChannels); + } + } catch (err) { + console.error('Error fetching channels:', err); + setError('Failed to fetch available channels.'); + } finally { + setChannelsLoading(false); + } + }; + + const fetchVideos = async (channelId) => { + try { + setLoading(true); + setError(null); + setExpandedDescriptions({}); // Reset expanded states when fetching new videos + + const apiUrl = `${API_BASE_URL}/vid-from-link/yt:channel:${channelId}`; + const response = await axios.get(apiUrl); + + if (response.data && Array.isArray(response.data)) { + setVideos(response.data); + } else { + throw new Error('Invalid response format'); + } + } catch (err) { + setError('Failed to fetch videos. Please check the channel and ensure the API is running.'); + console.error('Error fetching videos:', err); + } finally { + setLoading(false); + } + }; + + useEffect(() => { + fetchChannels(); + }, []); + + useEffect(() => { + if (selectedChannelId) { + fetchVideos(selectedChannelId); + } + }, [selectedChannelId]); + + const handleChannelChange = (e) => { + setSelectedChannelId(e.target.value); + }; + + const handleRefreshChannels = () => { + fetchChannels(); + }; + + const toggleDescription = (videoId) => { + setExpandedDescriptions(prev => ({ + ...prev, + [videoId]: !prev[videoId] + })); + }; + + const formatDate = (dateString) => { + try { + return new Date(dateString).toLocaleDateString('en-US', { + year: 'numeric', + month: 'short', + day: 'numeric', + hour: '2-digit', + minute: '2-digit' + }); + } catch { + return dateString; + } + }; + + const formatRelativeTime = (dateString) => { + try { + const date = new Date(dateString); + const now = new Date(); + const diffInHours = Math.floor((now - date) / (1000 * 60 * 60)); + + if (diffInHours < 1) { + return 'Just now'; + } else if (diffInHours < 24) { + return `${diffInHours}h ago`; + } else { + const diffInDays = Math.floor(diffInHours / 24); + return `${diffInDays}d ago`; + } + } catch { + return dateString; + } + }; + + return ( +
+
+

YouTube Channel Videos

+ +
+
+ + +
+ + + + {selectedChannelId && channels.length > 0 && ( +
+

+ Selected: {selectedChannelId} + {channels.find(ch => ch.id === selectedChannelId)?.last_video_update && ( + • Last updated: {formatRelativeTime(channels.find(ch => ch.id === selectedChannelId).last_video_update)} + )} +

+
+ )} +
+
+ +
+ {channelsLoading &&
Loading channels...
} + + {error && ( +
+ {error} + +
+ )} + + {!channelsLoading && channels.length === 0 && !error && ( +
+

No channels available

+

No YouTube channels found in the subscription list.

+ +
+ )} + + {loading && selectedChannelId && ( +
Loading videos for {selectedChannelId}...
+ )} + + {!loading && !error && selectedChannelId && ( +
+

+ Latest Videos from {selectedChannelId} + {videos.length > 0 && ` (${videos.length})`} +

+
+ {videos.sort((a, b) => new Date(b.published) - new Date(a.published)).map((video) => ( +
+
+ {video.title} { + e.target.src = 'https://via.placeholder.com/300x180/333/fff?text=No+Thumbnail'; + }} + /> +
+
+ +
+

+ {video.title} +

+

+ By: + {video.author} + +

+

Published: {formatDate(video.published)}

+ {video.updated && ( +

Updated: {formatDate(video.updated)}

+ )} + + {video.summary && ( +
+

+ {video.summary} +

+ {video.summary.length > 100 && ( + + )} +
+ )} + + +
+
+ ))} +
+
+ )} + + {!loading && !error && selectedChannelId && videos.length === 0 && ( +
+

No videos found for this channel

+

The channel might not have any videos or there was an issue loading them.

+
+ )} + + {!channelsLoading && !selectedChannelId && channels.length > 0 && ( +
+

Please select a channel to view videos

+

Choose a channel from the dropdown above to see its latest videos.

+
+ )} +
+
+ ); +} + +export default App; diff --git a/front-end/src/assets/react.svg b/front-end/src/assets/react.svg new file mode 100644 index 0000000..6c87de9 --- /dev/null +++ b/front-end/src/assets/react.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/front-end/src/main.jsx b/front-end/src/main.jsx new file mode 100644 index 0000000..3d9da8a --- /dev/null +++ b/front-end/src/main.jsx @@ -0,0 +1,9 @@ +import { StrictMode } from 'react' +import { createRoot } from 'react-dom/client' +import App from './App.jsx' + +createRoot(document.getElementById('root')).render( + + + , +) -- cgit v1.2.3-70-g09d2