FEAT: Added variable to keep track of user subscription within VideoPage
FIX: Added .env back into frontend
This commit is contained in:
@@ -38,6 +38,8 @@ services:
|
|||||||
- app_network
|
- app_network
|
||||||
environment:
|
environment:
|
||||||
- VITE_API_URL=/api
|
- VITE_API_URL=/api
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
depends_on:
|
depends_on:
|
||||||
- web_server
|
- web_server
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ const VideoPage: React.FC<VideoPageProps> = ({ streamerId }) => {
|
|||||||
const [showCheckout, setShowCheckout] = useState(false);
|
const [showCheckout, setShowCheckout] = useState(false);
|
||||||
const showReturn = window.location.search.includes("session_id");
|
const showReturn = window.location.search.includes("session_id");
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const [isSubscribed, setIsSubscribed] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Prevent scrolling when checkout is open
|
// Prevent scrolling when checkout is open
|
||||||
@@ -95,6 +96,19 @@ const VideoPage: React.FC<VideoPageProps> = ({ streamerId }) => {
|
|||||||
setIsChatOpen((prev) => !prev);
|
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 (
|
return (
|
||||||
<SocketProvider>
|
<SocketProvider>
|
||||||
<div id="videoPage" className="w-full">
|
<div id="videoPage" className="w-full">
|
||||||
@@ -102,8 +116,7 @@ const VideoPage: React.FC<VideoPageProps> = ({ streamerId }) => {
|
|||||||
|
|
||||||
<div
|
<div
|
||||||
id="container"
|
id="container"
|
||||||
className={`grid ${
|
className={`grid ${isChatOpen ? "w-[100vw]" : "w-[125vw]"
|
||||||
isChatOpen ? "w-[100vw]" : "w-[125vw]"
|
|
||||||
} grid-rows-[auto_1fr] bg-gray-900 h-full grid-cols-[auto_25vw] transition-all`}
|
} grid-rows-[auto_1fr] bg-gray-900 h-full grid-cols-[auto_25vw] transition-all`}
|
||||||
>
|
>
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
|
|||||||
@@ -23,24 +23,26 @@ def user_data(username: str):
|
|||||||
|
|
||||||
## Subscription Routes
|
## Subscription Routes
|
||||||
@login_required
|
@login_required
|
||||||
@user_bp.route('/user/subscription/<int:subscribed_id>')
|
@user_bp.route('/user/subscription/<string:streamer_name>')
|
||||||
def user_subscribed(subscribed_id: int):
|
def user_subscribed(streamer_name: str):
|
||||||
"""
|
"""
|
||||||
Checks to see if user is subscribed to another user
|
Checks to see if user is subscribed to another user
|
||||||
"""
|
"""
|
||||||
user_id = session.get("user_id")
|
user_id = session.get("user_id")
|
||||||
|
subscribed_id = get_user_id(streamer_name)
|
||||||
if is_subscribed(user_id, subscribed_id):
|
if is_subscribed(user_id, subscribed_id):
|
||||||
return jsonify({"subscribed": True})
|
return jsonify({"subscribed": True})
|
||||||
return jsonify({"subscribed": False})
|
return jsonify({"subscribed": False})
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@user_bp.route('/user/subscription/<int:subscribed_id>/expiration')
|
@user_bp.route('/user/subscription/<string:streamer_name>/expiration')
|
||||||
def user_subscription_expiration(subscribed_id: int):
|
def user_subscription_expiration(streamer_name: str):
|
||||||
"""
|
"""
|
||||||
Returns remaining time until subscription expiration
|
Returns remaining time until subscription expiration
|
||||||
"""
|
"""
|
||||||
|
|
||||||
user_id = session.get("user_id")
|
user_id = session.get("user_id")
|
||||||
|
subscribed_id = get_user_id(streamer_name)
|
||||||
remaining_time = subscription_expiration(user_id, subscribed_id)
|
remaining_time = subscription_expiration(user_id, subscribed_id)
|
||||||
# Remove any expired subscriptions from the table
|
# Remove any expired subscriptions from the table
|
||||||
if remaining_time == 0:
|
if remaining_time == 0:
|
||||||
|
|||||||
Reference in New Issue
Block a user