FEAT: Added more info & functionality to UserPage & Added ability to follow streamers on both UserPage and VideoPage;

Added shortcut to toggle chat;
This commit is contained in:
Chris-1010
2025-02-07 02:11:22 +00:00
parent 1499e042cb
commit 16dc8f1ea2
16 changed files with 438 additions and 240 deletions

View File

@@ -0,0 +1,21 @@
import { useState, useEffect } from 'react';
export function useAuthModal() {
const [showAuthModal, setShowAuthModal] = useState(false);
useEffect(() => {
if (showAuthModal) {
document.body.style.overflow = "hidden";
} else {
document.body.style.overflow = "unset";
}
return () => {
document.body.style.overflow = "unset";
};
}, [showAuthModal]);
return {
showAuthModal,
setShowAuthModal,
};
}

View File

@@ -0,0 +1,65 @@
import { useState } from 'react';
import { useAuth } from '../context/AuthContext';
export function useFollow() {
const [isFollowing, setIsFollowing] = useState<boolean>(false);
const { isLoggedIn } = useAuth();
const checkFollowStatus = async (username: string) => {
try {
const response = await fetch(`/api/user/following/${username}`);
const data = await response.json();
setIsFollowing(data.following);
} catch (error) {
console.error("Error checking follow status:", error);
}
};
const followUser = async (userId: number, setShowAuthModal?: (show: boolean) => void) => {
if (!isLoggedIn) {
setShowAuthModal?.(true);
return;
}
try {
const response = await fetch(`/api/user/follow/${userId}`);
const data = await response.json();
if (data.success) {
console.log(`Now following user ${userId}`);
setIsFollowing(true);
} else {
console.error(`Failed to follow user ${userId}`);
}
} catch (error) {
console.error("Error following user:", error);
}
};
const unfollowUser = async (userId: number, setShowAuthModal?: (show: boolean) => void) => {
if (!isLoggedIn) {
setShowAuthModal?.(true);
return;
}
try {
const response = await fetch(`/api/user/unfollow/${userId}`);
const data = await response.json();
if (data.success) {
console.log(`Unfollowed user ${userId}`);
setIsFollowing(false);
} else {
console.error(`Failed to unfollow user ${userId}`);
}
} catch (error) {
console.error("Error unfollowing user:", error);
}
};
return {
isFollowing,
setIsFollowing,
checkFollowStatus,
followUser,
unfollowUser
};
}