From 902c745065d889ef1d6530b1f046314a6152d951 Mon Sep 17 00:00:00 2001 From: JustIceO7 Date: Tue, 18 Feb 2025 02:47:23 +0000 Subject: [PATCH] FEAT: Added variable to keep track of user subscription within VideoPage FIX: Added .env back into frontend --- docker-compose.yml | 2 ++ frontend/src/pages/VideoPage.tsx | 25 +++++++++++++++++++------ web_server/blueprints/user.py | 10 ++++++---- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 17806c4..80ccab0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -38,6 +38,8 @@ services: - app_network environment: - VITE_API_URL=/api + env_file: + - .env depends_on: - web_server diff --git a/frontend/src/pages/VideoPage.tsx b/frontend/src/pages/VideoPage.tsx index 4ae082a..3eaf7a4 100644 --- a/frontend/src/pages/VideoPage.tsx +++ b/frontend/src/pages/VideoPage.tsx @@ -35,6 +35,7 @@ const VideoPage: React.FC = ({ streamerId }) => { const [showCheckout, setShowCheckout] = useState(false); const showReturn = window.location.search.includes("session_id"); const navigate = useNavigate(); + const [isSubscribed, setIsSubscribed] = useState(false); useEffect(() => { // Prevent scrolling when checkout is open @@ -95,6 +96,19 @@ const VideoPage: React.FC = ({ streamerId }) => { setIsChatOpen((prev) => !prev); }; + // Checks if user is subscribed + useEffect(() => { + fetch(`/api/user/subscription/${streamerName}/expiration`) + .then(response => response.json()) + .then(data => { + console.log(data.remaining_time); + if (data.remaining_time > 0) { + setIsSubscribed(true); + } + }) + .catch(error => console.error("Error fetching subscription:", error)); + }, [streamerName]); + return (
@@ -102,9 +116,8 @@ const VideoPage: React.FC = ({ streamerId }) => {
@@ -197,9 +210,9 @@ const VideoPage: React.FC = ({ streamerId }) => { {streamData ? `${Math.floor( - (Date.now() - new Date(streamData.startTime).getTime()) / - 3600000 - )} hours ago` + (Date.now() - new Date(streamData.startTime).getTime()) / + 3600000 + )} hours ago` : "Loading..."}
diff --git a/web_server/blueprints/user.py b/web_server/blueprints/user.py index 2f6c4ca..9096838 100644 --- a/web_server/blueprints/user.py +++ b/web_server/blueprints/user.py @@ -23,24 +23,26 @@ def user_data(username: str): ## Subscription Routes @login_required -@user_bp.route('/user/subscription/') -def user_subscribed(subscribed_id: int): +@user_bp.route('/user/subscription/') +def user_subscribed(streamer_name: str): """ Checks to see if user is subscribed to another user """ user_id = session.get("user_id") + subscribed_id = get_user_id(streamer_name) if is_subscribed(user_id, subscribed_id): return jsonify({"subscribed": True}) return jsonify({"subscribed": False}) @login_required -@user_bp.route('/user/subscription//expiration') -def user_subscription_expiration(subscribed_id: int): +@user_bp.route('/user/subscription//expiration') +def user_subscription_expiration(streamer_name: str): """ Returns remaining time until subscription expiration """ user_id = session.get("user_id") + subscribed_id = get_user_id(streamer_name) remaining_time = subscription_expiration(user_id, subscribed_id) # Remove any expired subscriptions from the table if remaining_time == 0: