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:
21
frontend/src/hooks/useAuthModal.ts
Normal file
21
frontend/src/hooks/useAuthModal.ts
Normal 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,
|
||||
};
|
||||
}
|
||||
65
frontend/src/hooks/useFollow.ts
Normal file
65
frontend/src/hooks/useFollow.ts
Normal 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
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user