From 9fb20553d9f9e21c012f730a728c33d368e09bf2 Mon Sep 17 00:00:00 2001 From: A Farzat Date: Thu, 9 Oct 2025 09:51:14 +0300 Subject: Add methods to modify/delete subscriptions --- front-end/src/App.jsx | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) (limited to 'front-end/src/App.jsx') diff --git a/front-end/src/App.jsx b/front-end/src/App.jsx index da6057e..1bdcdaf 100644 --- a/front-end/src/App.jsx +++ b/front-end/src/App.jsx @@ -19,6 +19,10 @@ function App() { const [addingSubscription, setAddingSubscription] = useState(false); const [subscriptionError, setSubscriptionError] = useState(null); const [subscriptionSuccess, setSubscriptionSuccess] = useState(null); + const [editingSubscription, setEditingSubscription] = useState(null); + const [newTimeBetweenFetches, setNewTimeBetweenFetches] = useState(300); + const [updatingSubscription, setUpdatingSubscription] = useState(false); + const [deletingSubscription, setDeletingSubscription] = useState(false); const fetchChannels = async () => { try { @@ -72,6 +76,57 @@ function App() { } }; + const updateTimeBetweenFetches = async (subscriptionId, newTime) => { + try { + setUpdatingSubscription(true); + const formData = new FormData(); + formData.append('_id', subscriptionId); + formData.append('time_between_fetches', newTime.toString()); + + await axios.post(`${API_BASE_URL}/set-time-between-fetches/`, formData, { + headers: { + 'Content-Type': 'multipart/form-data', + }, + }); + + // Refresh the channels list to show updated data + fetchChannels(); + setEditingSubscription(null); + setSubscriptionSuccess('Fetch interval updated successfully!'); + } catch (err) { + console.error('Error updating fetch interval:', err); + setSubscriptionError('Failed to update fetch interval. Please try again.'); + } finally { + setUpdatingSubscription(false); + } + }; + + const deleteSubscription = async (subscriptionId) => { + if (!window.confirm('Are you sure you want to delete this subscription? This action cannot be undone.')) { + return; + } + + try { + setDeletingSubscription(true); + await axios.delete(`${API_BASE_URL}/delete-sub/${subscriptionId}`); + + // If the deleted subscription was selected, clear the selection + if (selectedChannelId === subscriptionId.replace('yt:channel:', '').replace('yt:playlist:', '')) { + setSelectedChannelId(''); + setVideos([]); + } + + // Refresh the channels list + fetchChannels(); + setSubscriptionSuccess('Subscription deleted successfully!'); + } catch (err) { + console.error('Error deleting subscription:', err); + setSubscriptionError('Failed to delete subscription. Please try again.'); + } finally { + setDeletingSubscription(false); + } + }; + const fetchVideos = async (channelId) => { try { setLoading(true); @@ -228,6 +283,16 @@ function App() { setSubscriptionSuccess(null); }; + const startEditingSubscription = (subscription) => { + setEditingSubscription(subscription); + setNewTimeBetweenFetches(subscription.time_between_fetches); + }; + + const cancelEditing = () => { + setEditingSubscription(null); + setNewTimeBetweenFetches(300); + }; + return (
@@ -286,9 +351,67 @@ function App() { )}

)} +
+ + +
)} + + {editingSubscription && ( +
+
+

Edit Subscription

+
+ + setNewTimeBetweenFetches(parseInt(e.target.value) || 0)} + min="60" + max="86400" + className="subscription-input" + disabled={updatingSubscription} + /> + + How often to check for new videos (current: {editingSubscription.time_between_fetches}s) + +
+
+ + +
+
+
+ )} +