From 05607dc845a1dd111fd393478acf084ca3532081 Mon Sep 17 00:00:00 2001 From: A Farzat Date: Wed, 8 Oct 2025 15:26:43 +0300 Subject: Add the ability to add subscriptions --- front-end/src/App.jsx | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) (limited to 'front-end/src/App.jsx') diff --git a/front-end/src/App.jsx b/front-end/src/App.jsx index 92d0adf..4215650 100644 --- a/front-end/src/App.jsx +++ b/front-end/src/App.jsx @@ -13,6 +13,12 @@ function App() { const [error, setError] = useState(null); const [selectedChannelId, setSelectedChannelId] = useState(''); const [expandedDescriptions, setExpandedDescriptions] = useState({}); + const [showAddSubscription, setShowAddSubscription] = useState(false); + const [subscriptionUrl, setSubscriptionUrl] = useState(''); + const [timeBetweenFetches, setTimeBetweenFetches] = useState(300); // Default 5 minutes + const [addingSubscription, setAddingSubscription] = useState(false); + const [subscriptionError, setSubscriptionError] = useState(null); + const [subscriptionSuccess, setSubscriptionSuccess] = useState(null); const fetchChannels = async () => { try { @@ -138,6 +144,59 @@ function App() { } }; + const handleAddSubscription = async (e) => { + e.preventDefault(); + + if (!subscriptionUrl.trim()) { + setSubscriptionError('Please enter a YouTube channel/playlist URL'); + return; + } + + try { + setAddingSubscription(true); + setSubscriptionError(null); + setSubscriptionSuccess(null); + + const formData = new FormData(); + formData.append('url', subscriptionUrl.trim()); + formData.append('time_between_fetches', timeBetweenFetches.toString()); + + const response = await axios.post(`${API_BASE_URL}/add-sub/`, formData, { + headers: { + 'Content-Type': 'multipart/form-data', + }, + }); + + if (response.data) { + setSubscriptionSuccess('Subscription added successfully!'); + setSubscriptionUrl(''); + setTimeBetweenFetches(300); + setShowAddSubscription(false); + + // Refresh the subs list to include the new subscription + fetchChannels(); + } else { + throw new Error(response.data.error || 'Failed to add subscription'); + } + } catch (err) { + console.error('Error adding subscription:', err); + setSubscriptionError( + err.response?.data?.error || + err.message || + 'Failed to add subscription. Please check the URL and try again.' + ); + } finally { + setAddingSubscription(false); + } + }; + + const resetSubscriptionForm = () => { + setSubscriptionUrl(''); + setTimeBetweenFetches(300); + setSubscriptionError(null); + setSubscriptionSuccess(null); + }; + return (
@@ -189,6 +248,75 @@ function App() {
)} +
+ + + {showAddSubscription && ( +
+
+

Add New Subscription

+ +
+ + setSubscriptionUrl(e.target.value)} + placeholder="https://www.youtube.com/channel/UCxxxxxxxxxxxxxxxxxx" + className="subscription-input" + disabled={addingSubscription} + /> +
+ +
+ + setTimeBetweenFetches(parseInt(e.target.value) || 300)} + min="60" + max="86400" + className="subscription-input" + disabled={addingSubscription} + /> + + How often to check for new videos (default: 300s = 5 minutes) + +
+ + {subscriptionError && ( +
{subscriptionError}
+ )} + + {subscriptionSuccess && ( +
{subscriptionSuccess}
+ )} + +
+ +
+
+
+ )} +
-- cgit v1.2.3-70-g09d2