UPDATE/FEAT: Proper handling of profile pictures where a fallback to the default pfp is used;
REFACTOR: Remove unnecessary props from users on `ResultsPage`; REFACTOR: General formatting
This commit is contained in:
@@ -84,7 +84,11 @@ const UserListItem: React.FC<UserListItemProps> = ({ title, username, isLive, on
|
||||
onClick={onItemClick}
|
||||
>
|
||||
<img
|
||||
src="/images/monkey.png"
|
||||
src={`/user/${username}/profile_picture`}
|
||||
onError={(e) => {
|
||||
e.currentTarget.src = "/images/pfps/default.png";
|
||||
e.currentTarget.onerror = null;
|
||||
}}
|
||||
alt={`user ${username}`}
|
||||
className="rounded-xl border-[0.15em] border-[var(--bg-color)] cursor-pointer"
|
||||
/>
|
||||
|
||||
@@ -4,199 +4,164 @@ import { useNavigate } from "react-router-dom";
|
||||
import { useAuth } from "../../context/AuthContext";
|
||||
import { useSidebar } from "../../context/SidebarContext";
|
||||
import { ToggleButton } from "../Input/Button";
|
||||
import { getCategoryThumbnail } from "../../utils/thumbnailUtils";
|
||||
|
||||
interface Streamer {
|
||||
user_id: number;
|
||||
username: string;
|
||||
user_id: number;
|
||||
username: string;
|
||||
}
|
||||
|
||||
interface Category {
|
||||
category_id: number;
|
||||
category_name: string;
|
||||
category_id: number;
|
||||
category_name: string;
|
||||
}
|
||||
|
||||
interface SideBarProps {
|
||||
extraClasses?: string;
|
||||
extraClasses?: string;
|
||||
}
|
||||
|
||||
const Sidebar: React.FC<SideBarProps> = ({ extraClasses = "" }) => {
|
||||
const { showSideBar, setShowSideBar } = useSidebar();
|
||||
const navigate = useNavigate();
|
||||
const { username, isLoggedIn } = useAuth();
|
||||
const [followedStreamers, setFollowedStreamers] = useState<Streamer[]>([]);
|
||||
const [followedCategories, setFollowedCategories] = useState<Category[]>([]);
|
||||
const [justToggled, setJustToggled] = useState(false);
|
||||
const sidebarId = useRef(Math.floor(Math.random() * 1000000));
|
||||
const { showSideBar, setShowSideBar } = useSidebar();
|
||||
const navigate = useNavigate();
|
||||
const { username, isLoggedIn } = useAuth();
|
||||
const [followedStreamers, setFollowedStreamers] = useState<Streamer[]>([]);
|
||||
const [followedCategories, setFollowedCategories] = useState<Category[]>([]);
|
||||
const [justToggled, setJustToggled] = useState(false);
|
||||
const sidebarId = useRef(Math.floor(Math.random() * 1000000));
|
||||
|
||||
// Fetch followed streamers & categories
|
||||
useEffect(() => {
|
||||
if (!isLoggedIn) return;
|
||||
// Fetch followed streamers & categories
|
||||
useEffect(() => {
|
||||
if (!isLoggedIn) return;
|
||||
|
||||
const fetchFollowData = async () => {
|
||||
try {
|
||||
const response = await fetch("/api/user/following");
|
||||
if (!response.ok) throw new Error("Failed to fetch followed content");
|
||||
const data = await response.json();
|
||||
setFollowedStreamers(data.streams);
|
||||
setFollowedCategories(data.categories);
|
||||
} catch (error) {
|
||||
console.error("Error fetching followed content:", error);
|
||||
}
|
||||
};
|
||||
const fetchFollowData = async () => {
|
||||
try {
|
||||
const response = await fetch("/api/user/following");
|
||||
if (!response.ok) throw new Error("Failed to fetch followed content");
|
||||
const data = await response.json();
|
||||
setFollowedStreamers(data.streams);
|
||||
setFollowedCategories(data.categories);
|
||||
} catch (error) {
|
||||
console.error("Error fetching followed content:", error);
|
||||
}
|
||||
};
|
||||
|
||||
fetchFollowData();
|
||||
}, [isLoggedIn]);
|
||||
fetchFollowData();
|
||||
}, [isLoggedIn]);
|
||||
|
||||
const handleSideBar = () => {
|
||||
setShowSideBar(!showSideBar);
|
||||
setJustToggled(true);
|
||||
setTimeout(() => setJustToggled(false), 200);
|
||||
};
|
||||
const handleSideBar = () => {
|
||||
setShowSideBar(!showSideBar);
|
||||
setJustToggled(true);
|
||||
setTimeout(() => setJustToggled(false), 200);
|
||||
};
|
||||
|
||||
// Keyboard shortcut to toggle sidebar
|
||||
useEffect(() => {
|
||||
const handleKeyPress = (e: KeyboardEvent) => {
|
||||
if (
|
||||
e.key === "s" &&
|
||||
document.activeElement == document.body &&
|
||||
isLoggedIn
|
||||
)
|
||||
handleSideBar();
|
||||
};
|
||||
// Keyboard shortcut to toggle sidebar
|
||||
useEffect(() => {
|
||||
const handleKeyPress = (e: KeyboardEvent) => {
|
||||
if (e.key === "s" && document.activeElement == document.body && isLoggedIn) handleSideBar();
|
||||
};
|
||||
|
||||
document.addEventListener("keydown", handleKeyPress);
|
||||
document.addEventListener("keydown", handleKeyPress);
|
||||
|
||||
return () => {
|
||||
document.removeEventListener("keydown", handleKeyPress);
|
||||
};
|
||||
}, [showSideBar, setShowSideBar, isLoggedIn]);
|
||||
return () => {
|
||||
document.removeEventListener("keydown", handleKeyPress);
|
||||
};
|
||||
}, [showSideBar, setShowSideBar, isLoggedIn]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<ToggleButton
|
||||
onClick={() => handleSideBar()}
|
||||
extraClasses={`absolute group text-[1rem] top-[9vh] ${
|
||||
showSideBar
|
||||
? "left-[16vw] duration-[0.5s]"
|
||||
: "left-[20px] duration-[1s]"
|
||||
} ease-in-out cursor-pointer z-[50]`}
|
||||
toggled={showSideBar}
|
||||
>
|
||||
<SidebarIcon className="h-[2vw] w-[2vw]" />
|
||||
return (
|
||||
<>
|
||||
<ToggleButton
|
||||
onClick={() => handleSideBar()}
|
||||
extraClasses={`absolute group text-[1rem] top-[9vh] ${
|
||||
showSideBar ? "left-[16vw] duration-[0.5s]" : "left-[20px] duration-[1s]"
|
||||
} ease-in-out cursor-pointer z-[50]`}
|
||||
toggled={showSideBar}
|
||||
>
|
||||
<SidebarIcon className="h-[2vw] w-[2vw]" />
|
||||
|
||||
{!showSideBar && !justToggled && (
|
||||
<small className="absolute flex items-center top-0 ml-2 left-0 h-full my-auto w-fit text-nowrap font-bold my-auto group-hover:left-full opacity-0 group-hover:opacity-100 group-hover:bg-black/30 p-1 rounded-md text-white transition-all">
|
||||
Press S
|
||||
</small>
|
||||
)}
|
||||
</ToggleButton>
|
||||
<div
|
||||
id={`sidebar-${sidebarId.current}`}
|
||||
className={`fixed top-0 left-0 w-[15vw] h-screen overflow-x-hidden flex flex-col bg-[var(--sideBar-bg)] text-[var(--sideBar-text)] text-center overflow-y-auto scrollbar-hide
|
||||
transition-all duration-500 ease-in-out ${
|
||||
showSideBar ? "translate-x-0" : "-translate-x-full"
|
||||
} ${extraClasses}`}
|
||||
>
|
||||
{/* Profile Info */}
|
||||
<div className="flex flex-row items-center border-b-4 border-[var(--profile-border)] justify-evenly bg-[var(--sideBar-profile-bg)] py-[1em]">
|
||||
<img
|
||||
src="/images/monkey.png"
|
||||
alt="profile picture"
|
||||
className="w-[3em] h-[3em] rounded-full border-[0.15em] border-purple-500 cursor-pointer"
|
||||
onClick={() => navigate(`/user/${username}`)}
|
||||
/>
|
||||
<div className="text-center flex flex-col items-center justify-center">
|
||||
<h5 className="font-thin text-[0.85rem] cursor-default text-[var(--sideBar-profile-text)]">
|
||||
Logged in as
|
||||
</h5>
|
||||
<button
|
||||
className="font-black text-[1.4rem] hover:underline"
|
||||
onClick={() => navigate(`/user/${username}`)}
|
||||
>
|
||||
<div className="text-[var(--sideBar-profile-text)]">
|
||||
{username}
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{!showSideBar && !justToggled && (
|
||||
<small className="absolute flex items-center top-0 ml-2 left-0 h-full my-auto w-fit text-nowrap font-bold my-auto group-hover:left-full opacity-0 group-hover:opacity-100 group-hover:bg-black/30 p-1 rounded-md text-white transition-all">
|
||||
Press S
|
||||
</small>
|
||||
)}
|
||||
</ToggleButton>
|
||||
<div
|
||||
id={`sidebar-${sidebarId.current}`}
|
||||
className={`fixed top-0 left-0 w-[15vw] h-screen overflow-x-hidden flex flex-col bg-[var(--sideBar-bg)] text-[var(--sideBar-text)] text-center overflow-y-auto scrollbar-hide
|
||||
transition-all duration-500 ease-in-out ${showSideBar ? "translate-x-0" : "-translate-x-full"} z-50 ${extraClasses}`}
|
||||
>
|
||||
{/* Profile Info */}
|
||||
<div className="flex flex-row items-center border-b-4 border-[var(--profile-border)] justify-evenly bg-[var(--sideBar-profile-bg)] py-[1em]">
|
||||
<img
|
||||
src={`/user/${username}/profile_picture`}
|
||||
onError={(e) => {
|
||||
e.currentTarget.src = "/images/pfps/default.png";
|
||||
e.currentTarget.onerror = null;
|
||||
}}
|
||||
alt="profile picture"
|
||||
className="w-[3em] h-[3em] rounded-full border-[0.15em] border-purple-500 cursor-pointer"
|
||||
onClick={() => navigate(`/user/${username}`)}
|
||||
/>
|
||||
<div className="text-center flex flex-col items-center justify-center">
|
||||
<h5 className="font-thin text-[0.85rem] cursor-default text-[var(--sideBar-profile-text)]">Logged in as</h5>
|
||||
<button className="font-black text-[1.4rem] hover:underline" onClick={() => navigate(`/user/${username}`)}>
|
||||
<div className="text-[var(--sideBar-profile-text)]">{username}</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
id="following"
|
||||
className="flex flex-col flex-grow justify-evenly p-4 gap-4"
|
||||
>
|
||||
<div
|
||||
className="bg-[var(--follow-bg)] rounded-[1em] hover:scale-105 transition-all ease-in-out duration-300"
|
||||
onMouseEnter={(e) =>
|
||||
(e.currentTarget.style.boxShadow = "var(--follow-shadow)")
|
||||
}
|
||||
onMouseLeave={(e) => (e.currentTarget.style.boxShadow = "none")}
|
||||
>
|
||||
<h1 className="text-[2vw] font-bold text-2xl p-[0.75rem] cursor-default">
|
||||
Following
|
||||
</h1>
|
||||
</div>
|
||||
<div
|
||||
id="streamers-followed"
|
||||
className="flex flex-col flex-grow items-center"
|
||||
>
|
||||
<h2 className="border-b-4 border-t-4 w-[125%] text-2xl cursor-default">
|
||||
Streamers
|
||||
</h2>
|
||||
<div className="flex flex-col flex-grow justify-evenly w-full">
|
||||
{followedStreamers.map((streamer) => (
|
||||
<button
|
||||
key={`${sidebarId.current}-streamer-${streamer.username}`}
|
||||
className="cursor-pointer bg-black w-full py-2 border border-[--text-color] rounded-lg text-white hover:text-purple-500 font-bold transition-colors"
|
||||
onClick={() => navigate(`/user/${streamer.username}`)}
|
||||
>
|
||||
{streamer.username}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<div id="following" className="flex flex-col flex-grow justify-evenly p-4 gap-4">
|
||||
<div
|
||||
className="bg-[var(--follow-bg)] rounded-[1em] hover:scale-105 transition-all ease-in-out duration-300"
|
||||
onMouseEnter={(e) => (e.currentTarget.style.boxShadow = "var(--follow-shadow)")}
|
||||
onMouseLeave={(e) => (e.currentTarget.style.boxShadow = "none")}
|
||||
>
|
||||
<h1 className="text-[2vw] font-bold text-2xl p-[0.75rem] cursor-default">Following</h1>
|
||||
</div>
|
||||
<div id="streamers-followed" className="flex flex-col flex-grow items-center">
|
||||
<h2 className="border-b-4 border-t-4 w-[125%] text-2xl cursor-default">Streamers</h2>
|
||||
<div className="flex flex-col flex-grow justify-evenly w-full">
|
||||
{followedStreamers.map((streamer) => (
|
||||
<button
|
||||
key={`${sidebarId.current}-streamer-${streamer.username}`}
|
||||
className="cursor-pointer bg-black w-full py-2 border border-[--text-color] rounded-lg text-white hover:text-purple-500 font-bold transition-colors"
|
||||
onClick={() => navigate(`/user/${streamer.username}`)}
|
||||
>
|
||||
{streamer.username}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
id="categories-followed"
|
||||
className="flex flex-col flex-grow items-center"
|
||||
>
|
||||
<h2 className="border-b-4 border-t-4 w-[125%] text-2xl cursor-default">
|
||||
Categories
|
||||
</h2>
|
||||
<div id="categories-followed" className="flex flex-col flex-grow items-center">
|
||||
<h2 className="border-b-4 border-t-4 w-[125%] text-2xl cursor-default">Categories</h2>
|
||||
|
||||
{/* Followed Categories */}
|
||||
<div
|
||||
id="categories-followed"
|
||||
className="grid grid-cols-1 gap-4 p-4 w-full"
|
||||
>
|
||||
{followedCategories.map((category) => {
|
||||
return (
|
||||
<div
|
||||
key={`${sidebarId.current}-category-${category.category_id}`}
|
||||
className="group relative flex flex-col items-center justify-center h-full max-h-[50px] border border-[--text-color]
|
||||
{/* Followed Categories */}
|
||||
<div id="categories-followed" className="grid grid-cols-1 gap-4 p-4 w-full">
|
||||
{followedCategories.map((category) => {
|
||||
return (
|
||||
<div
|
||||
key={`${sidebarId.current}-category-${category.category_id}`}
|
||||
className="group relative flex flex-col items-center justify-center h-full max-h-[50px] border border-[--text-color]
|
||||
rounded-lg overflow-hidden hover:shadow-lg transition-all text-white hover:text-purple-500 cursor-pointer"
|
||||
onClick={() =>
|
||||
(window.location.href = `/category/${category.category_name}`)
|
||||
}
|
||||
>
|
||||
<img
|
||||
src={`/images/category_thumbnails/${category.category_name
|
||||
.toLowerCase()
|
||||
.replace(/ /g, "_")}.webp`}
|
||||
alt={category.category_name}
|
||||
className="w-full h-28 object-cover group-hover:blur-[3px] transition-all"
|
||||
/>
|
||||
<div className="absolute bottom-2 bg-black bg-opacity-60 font-bold w-full text-center py-1">
|
||||
{category.category_name}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
onClick={() => (window.location.href = `/category/${category.category_name}`)}
|
||||
>
|
||||
<img
|
||||
src={getCategoryThumbnail(category.category_name)}
|
||||
alt={category.category_name}
|
||||
className="w-full h-28 object-cover group-hover:blur-[3px] transition-all"
|
||||
/>
|
||||
<div className="absolute bottom-2 bg-black bg-opacity-60 font-bold w-full text-center py-1">
|
||||
{category.category_name}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Sidebar;
|
||||
|
||||
@@ -183,7 +183,11 @@ const ChatPanel: React.FC<ChatPanelProps> = ({ streamId, onViewerCountChange })
|
||||
onClick={() => (msg.chatter_username === username ? null : (window.location.href = `/user/${msg.chatter_username}`))}
|
||||
>
|
||||
<img
|
||||
src="/images/monkey.png"
|
||||
src={`/user/${msg.chatter_username}/profile_picture`}
|
||||
onError={(e) => {
|
||||
e.currentTarget.src = "/images/pfps/default.png";
|
||||
e.currentTarget.onerror = null;
|
||||
}}
|
||||
alt="User Avatar"
|
||||
className="w-full h-full object-cover"
|
||||
style={{ width: "2.5em", height: "2.5em" }}
|
||||
|
||||
@@ -7,8 +7,8 @@ import { useAuthModal } from "../hooks/useAuthModal";
|
||||
import FollowUserButton from "../components/Input/FollowUserButton";
|
||||
|
||||
interface Streamer {
|
||||
user_id: number;
|
||||
username: string;
|
||||
user_id: number;
|
||||
username: string;
|
||||
}
|
||||
|
||||
interface FollowingStreamerProps {
|
||||
@@ -45,10 +45,10 @@ const Following: React.FC<FollowingStreamerProps> = ({ extraClasses = "" }) => {
|
||||
}
|
||||
};
|
||||
|
||||
if (isLoggedIn) {
|
||||
fetchFollowedStreamers();
|
||||
}
|
||||
}, [isLoggedIn]);
|
||||
if (isLoggedIn) {
|
||||
fetchFollowedStreamers();
|
||||
}
|
||||
}, [isLoggedIn]);
|
||||
|
||||
|
||||
const handleFollowToggle = async (userId: number) => {
|
||||
|
||||
@@ -84,9 +84,7 @@ const ResultsPage: React.FC = ({ }) => {
|
||||
id: user.user_id,
|
||||
type: "user",
|
||||
title: `${user.is_live ? "🔴" : ""} ${user.username}`,
|
||||
viewers: 0,
|
||||
username: user.username,
|
||||
thumbnail: user.profile_picture,
|
||||
username: user.username
|
||||
}))}
|
||||
title="Users"
|
||||
onItemClick={(username: string) =>
|
||||
|
||||
@@ -14,343 +14,295 @@ import { getCategoryThumbnail } from "../utils/thumbnailUtils";
|
||||
import { useSameUser } from "../hooks/useSameUser";
|
||||
|
||||
interface UserProfileData {
|
||||
id: number;
|
||||
username: string;
|
||||
bio: string;
|
||||
followerCount: number;
|
||||
isPartnered: boolean;
|
||||
isLive: boolean;
|
||||
currentStreamTitle?: string;
|
||||
currentStreamCategory?: string;
|
||||
currentStreamViewers?: number;
|
||||
currentStreamStartTime?: string;
|
||||
currentStreamThumbnail?: string;
|
||||
id: number;
|
||||
username: string;
|
||||
bio: string;
|
||||
followerCount: number;
|
||||
isPartnered: boolean;
|
||||
isLive: boolean;
|
||||
currentStreamTitle?: string;
|
||||
currentStreamCategory?: string;
|
||||
currentStreamViewers?: number;
|
||||
currentStreamStartTime?: string;
|
||||
currentStreamThumbnail?: string;
|
||||
}
|
||||
|
||||
const UserPage: React.FC = () => {
|
||||
const [userPageVariant, setUserPageVariant] = useState<
|
||||
"personal" | "streamer" | "user" | "admin"
|
||||
>("user");
|
||||
const [profileData, setProfileData] = useState<UserProfileData>();
|
||||
const { isFollowing, checkFollowStatus, followUser, unfollowUser } =
|
||||
useFollow();
|
||||
const { showAuthModal, setShowAuthModal } = useAuthModal();
|
||||
const { username: loggedInUsername } = useAuth();
|
||||
const { username } = useParams();
|
||||
const isUser = useSameUser({username});
|
||||
const navigate = useNavigate();
|
||||
const [userPageVariant, setUserPageVariant] = useState<"personal" | "streamer" | "user" | "admin">("user");
|
||||
const [profileData, setProfileData] = useState<UserProfileData>();
|
||||
const { isFollowing, checkFollowStatus, followUser, unfollowUser } = useFollow();
|
||||
const { showAuthModal, setShowAuthModal } = useAuthModal();
|
||||
const { username: loggedInUsername } = useAuth();
|
||||
const { username } = useParams();
|
||||
const isUser = useSameUser({ username });
|
||||
const navigate = useNavigate();
|
||||
|
||||
// Saves uploaded image as profile picture for the user
|
||||
const saveUploadedImage = async (event) => {
|
||||
const img = event.target.files[0];
|
||||
if (img) {
|
||||
const formData = new FormData();
|
||||
formData.append('image', img);
|
||||
// Saves uploaded image as profile picture for the user
|
||||
const saveUploadedImage = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const files = event.target.files;
|
||||
if (!files) return;
|
||||
const img = files[0];
|
||||
if (img) {
|
||||
const formData = new FormData();
|
||||
formData.append("image", img);
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/user/profile_picture/upload', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
});
|
||||
try {
|
||||
const response = await fetch("/api/user/profile_picture/upload", {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
console.log("Success");
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("Failure");
|
||||
}
|
||||
}
|
||||
};
|
||||
if (response.ok) {
|
||||
console.log("Success");
|
||||
window.location.reload();
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("Failure");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
// Fetch user profile data
|
||||
fetch(`/api/user/${username}`)
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
setProfileData({
|
||||
id: data.user_id,
|
||||
username: data.username,
|
||||
bio: data.bio || "This user hasn't written a bio yet.",
|
||||
followerCount: data.num_followers || 0,
|
||||
isPartnered: data.isPartnered || false,
|
||||
isLive: data.is_live,
|
||||
currentStreamTitle: "",
|
||||
currentStreamCategory: "",
|
||||
currentStreamViewers: 0,
|
||||
currentStreamThumbnail: "",
|
||||
});
|
||||
useEffect(() => {
|
||||
// Fetch user profile data
|
||||
fetch(`/api/user/${username}`)
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
setProfileData({
|
||||
id: data.user_id,
|
||||
username: data.username,
|
||||
bio: data.bio || "This user hasn't written a bio yet.",
|
||||
followerCount: data.num_followers || 0,
|
||||
isPartnered: data.isPartnered || false,
|
||||
isLive: data.is_live,
|
||||
currentStreamTitle: "",
|
||||
currentStreamCategory: "",
|
||||
currentStreamViewers: 0,
|
||||
currentStreamThumbnail: "",
|
||||
});
|
||||
|
||||
if (data.is_live) {
|
||||
// Fetch stream data for this streamer
|
||||
fetch(`/api/streams/${data.user_id}/data`)
|
||||
.then((res) => res.json())
|
||||
.then((streamData) => {
|
||||
setProfileData((prevData) => {
|
||||
if (!prevData) return prevData;
|
||||
return {
|
||||
...prevData,
|
||||
currentStreamTitle: streamData.title,
|
||||
currentStreamCategory: streamData.category_id,
|
||||
currentStreamViewers: streamData.num_viewers,
|
||||
currentStreamStartTime: streamData.start_time,
|
||||
currentStreamThumbnail: getCategoryThumbnail(
|
||||
streamData.category_name,
|
||||
streamData.thumbnail
|
||||
),
|
||||
};
|
||||
});
|
||||
let variant: "user" | "streamer" | "personal" | "admin";
|
||||
if (username === loggedInUsername) variant = "personal";
|
||||
else if (streamData.title) variant = "streamer";
|
||||
// else if (data.isAdmin) variant = "admin";
|
||||
else variant = "user";
|
||||
setUserPageVariant(variant);
|
||||
})
|
||||
.catch((err) => console.error("Error fetching stream data:", err));
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("Error fetching profile data:", err);
|
||||
navigate("/404");
|
||||
});
|
||||
if (data.is_live) {
|
||||
// Fetch stream data for this streamer
|
||||
fetch(`/api/streams/${data.user_id}/data`)
|
||||
.then((res) => res.json())
|
||||
.then((streamData) => {
|
||||
setProfileData((prevData) => {
|
||||
if (!prevData) return prevData;
|
||||
return {
|
||||
...prevData,
|
||||
currentStreamTitle: streamData.title,
|
||||
currentStreamCategory: streamData.category_id,
|
||||
currentStreamViewers: streamData.num_viewers,
|
||||
currentStreamStartTime: streamData.start_time,
|
||||
currentStreamThumbnail: getCategoryThumbnail(streamData.category_name, streamData.thumbnail),
|
||||
};
|
||||
});
|
||||
let variant: "user" | "streamer" | "personal" | "admin";
|
||||
if (username === loggedInUsername) variant = "personal";
|
||||
else if (streamData.title) variant = "streamer";
|
||||
// else if (data.isAdmin) variant = "admin";
|
||||
else variant = "user";
|
||||
setUserPageVariant(variant);
|
||||
})
|
||||
.catch((err) => console.error("Error fetching stream data:", err));
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("Error fetching profile data:", err);
|
||||
navigate("/404");
|
||||
});
|
||||
|
||||
// Check if the *logged-in* user is following this user
|
||||
if (loggedInUsername && username) checkFollowStatus(username);
|
||||
}, [username]);
|
||||
// Check if the *logged-in* user is following this user
|
||||
if (loggedInUsername && username) checkFollowStatus(username);
|
||||
}, [username]);
|
||||
|
||||
if (!profileData) return <LoadingScreen />;
|
||||
console.log(isUser)
|
||||
return (
|
||||
<DynamicPageContent
|
||||
className={`min-h-screen text-white flex flex-col`}
|
||||
>
|
||||
<div className="flex justify-evenly justify-self-center items-center h-full px-4 py-8 max-w-[80vw] w-full">
|
||||
<div className="grid grid-cols-4 grid-rows-[0.1fr_4fr] w-full gap-8">
|
||||
{/* Profile Section - TOP */}
|
||||
if (!profileData) return <LoadingScreen />;
|
||||
|
||||
<div
|
||||
id="profile"
|
||||
className="col-span-4 row-span-1 h-full bg-[var(--user-bg)]
|
||||
return (
|
||||
<DynamicPageContent className="min-h-screen text-white flex flex-col">
|
||||
<div className="flex justify-evenly self-center items-center h-full px-4 pt-14 pb-8 mx-auto max-w-[80vw] w-full">
|
||||
<div className="grid grid-cols-4 grid-rows-[0.1fr_4fr] w-full gap-8">
|
||||
{/* Profile Section - TOP */}
|
||||
|
||||
<div
|
||||
id="profile"
|
||||
className="col-span-4 row-span-1 h-full bg-[var(--user-bg)]
|
||||
rounded-[30px] p-3 shadow-lg
|
||||
relative flex flex-col items-center"
|
||||
>
|
||||
{/* Border Overlay (Always on Top) */}
|
||||
<div className="absolute left-[0px] inset-0 border-[5px] border-[var(--user-borderBg)] rounded-[20px] z-20"></div>
|
||||
>
|
||||
{/* Border Overlay (Always on Top) */}
|
||||
<div className="absolute left-[0px] inset-0 border-[5px] border-[var(--user-borderBg)] rounded-[20px] z-20"></div>
|
||||
|
||||
{/* Background Box */}
|
||||
<div
|
||||
className="absolute flex top-0 left-[0.55px] w-[99.9%] h-[5vh] min-h-[1em] max-h-[10em] rounded-t-[25.5px]
|
||||
{/* Background Box */}
|
||||
<div
|
||||
className="absolute flex top-0 left-[0.55px] w-[99.9%] h-[5vh] min-h-[1em] max-h-[10em] rounded-t-[25.5px]
|
||||
bg-[var(--user-box)] z-10 flex-shrink justify-center"
|
||||
style={{ boxShadow: "var(--user-box-shadow)" }}
|
||||
>
|
||||
{/* <div className="absolute top-4 w-[99.8%] h-[1vh] min-h-[1em] max-h-[2em] bg-[var(--user-box-strip)]"></div> */}
|
||||
</div>
|
||||
{/* Profile Picture */}
|
||||
<div
|
||||
className="relative -top-[40px] sm:-top-[90px] w-[16vw] h-[16vw] sm:w-[20vw] sm:h-[20vw] max-w-[10em] max-h-[10em]
|
||||
style={{ boxShadow: "var(--user-box-shadow)" }}
|
||||
>
|
||||
{/* <div className="absolute top-4 w-[99.8%] h-[1vh] min-h-[1em] max-h-[2em] bg-[var(--user-box-strip)]"></div> */}
|
||||
</div>
|
||||
{/* Profile Picture */}
|
||||
<div
|
||||
className="relative -top-[40px] sm:-top-[90px] w-[16vw] h-[16vw] sm:w-[20vw] sm:h-[20vw] max-w-[10em] max-h-[10em]
|
||||
rounded-full flex-shrink-0 border-4 border-[var(--user-pfp-border)] inset-0 z-20"
|
||||
style={{ boxShadow: "var(--user-pfp-border-shadow)" }}
|
||||
>
|
||||
<label
|
||||
className={`relative ${isUser ? "cursor-pointer group" : ""} overflow-visible`}
|
||||
>
|
||||
{/* If user is live then displays a live div */}
|
||||
{Boolean(profileData.isLive) && (
|
||||
<div className="absolute -bottom-2 left-1/2 transform -translate-x-1/2 bg-red-600 text-white text-sm font-bold py-1 sm:px-5 px-4 z-30 flex items-center justify-center rounded-tr-xl rounded-bl-xl rounded-tl-xl rounded-br-xl">
|
||||
LIVE
|
||||
</div>
|
||||
)}
|
||||
<img
|
||||
src="/images/monkey.png"
|
||||
alt={`${profileData.username}'s profile`}
|
||||
className="sm:w-full h-full object-cover rounded-full relative z-0"
|
||||
/>
|
||||
style={{ boxShadow: "var(--user-pfp-border-shadow)" }}
|
||||
>
|
||||
<label className={`relative ${isUser ? "cursor-pointer group" : ""} overflow-visible`}>
|
||||
{/* If user is live then displays a live div */}
|
||||
{Boolean(profileData.isLive) && (
|
||||
<div className="absolute -bottom-2 left-1/2 transform -translate-x-1/2 bg-red-600 text-white text-sm font-bold py-1 sm:px-5 px-4 z-30 flex items-center justify-center rounded-tr-xl rounded-bl-xl rounded-tl-xl rounded-br-xl">
|
||||
LIVE
|
||||
</div>
|
||||
)}
|
||||
<img
|
||||
src={`/user/${profileData.username}/profile_picture`}
|
||||
onError={(e) => {
|
||||
e.currentTarget.src = "/images/pfps/default.png";
|
||||
e.currentTarget.onerror = null;
|
||||
}}
|
||||
alt={`${profileData.username}'s profile`}
|
||||
className="sm:w-full h-full object-cover rounded-full relative z-0"
|
||||
/>
|
||||
|
||||
{/* If current user is the profile user then allow profile picture swap */}
|
||||
{isUser && (
|
||||
<>
|
||||
<div className="absolute inset-0 bg-black/20 opacity-0 group-hover:opacity-100 transition-opacity duration-200 rounded-full"></div>
|
||||
<div className="absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity duration-200">
|
||||
<CameraIcon
|
||||
size={32}
|
||||
className="text-white bg-black/50 p-1 rounded-full"
|
||||
/>
|
||||
</div>
|
||||
<input
|
||||
type="file"
|
||||
className="hidden"
|
||||
onChange={saveUploadedImage}
|
||||
accept="image/*" />
|
||||
</>
|
||||
)}
|
||||
</label>
|
||||
</div>
|
||||
{/* If current user is the profile user then allow profile picture swap */}
|
||||
{isUser && (
|
||||
<>
|
||||
<div className="absolute top-0 bg-black/20 opacity-0 group-hover:opacity-100 transition-opacity duration-200 rounded-full"></div>
|
||||
<div className="absolute top-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity duration-200">
|
||||
<CameraIcon size={32} className="text-white bg-black/50 p-1 rounded-full" />
|
||||
</div>
|
||||
<input type="file" className="hidden" onChange={saveUploadedImage} accept="image/*" />
|
||||
</>
|
||||
)}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{/* Username - Now Directly Below PFP */}
|
||||
<h1 className="text-[var(--user-name)] text-[1.5em] sm:text-[2em] font-bold -mt-[45px] sm:-mt-[90px] text-center">
|
||||
{profileData.username}
|
||||
</h1>
|
||||
{/* Username - Now Directly Below PFP */}
|
||||
<h1 className="text-[var(--user-name)] text-[1.5em] sm:text-[2em] font-bold -mt-[45px] sm:-mt-[90px] text-center">
|
||||
{profileData.username}
|
||||
</h1>
|
||||
|
||||
{/* Follower Count */}
|
||||
{userPageVariant === "streamer" && (
|
||||
<>
|
||||
<div className="flex items-center space-x-2 mb-6">
|
||||
<span className="text-gray-400">
|
||||
{profileData.followerCount.toLocaleString()} followers
|
||||
</span>
|
||||
{profileData.isPartnered && (
|
||||
<span className="bg-purple-600 text-white text-sm px-2 py-1 rounded">
|
||||
Partner
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{/* Follower Count */}
|
||||
{userPageVariant === "streamer" && (
|
||||
<>
|
||||
<div className="flex items-center space-x-2 mb-6">
|
||||
<span className="text-gray-400">{profileData.followerCount.toLocaleString()} followers</span>
|
||||
{profileData.isPartnered && <span className="bg-purple-600 text-white text-sm px-2 py-1 rounded">Partner</span>}
|
||||
</div>
|
||||
|
||||
{/* (Un)Follow Button */}
|
||||
{!isFollowing ? (
|
||||
<Button
|
||||
extraClasses="w-full bg-purple-700 hover:bg-[#28005e]"
|
||||
onClick={() => followUser(profileData.id, setShowAuthModal)}
|
||||
>
|
||||
Follow
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
extraClasses="w-full bg-[#a80000]"
|
||||
onClick={() =>
|
||||
unfollowUser(profileData?.id, setShowAuthModal)
|
||||
}
|
||||
>
|
||||
Unfollow
|
||||
</Button>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
{/* (Un)Follow Button */}
|
||||
{!isFollowing ? (
|
||||
<Button
|
||||
extraClasses="w-full bg-purple-700 hover:bg-[#28005e]"
|
||||
onClick={() => followUser(profileData.id, setShowAuthModal)}
|
||||
>
|
||||
Follow
|
||||
</Button>
|
||||
) : (
|
||||
<Button extraClasses="w-full bg-[#a80000] z-50" onClick={() => unfollowUser(profileData?.id, setShowAuthModal)}>
|
||||
Unfollow
|
||||
</Button>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div
|
||||
id="settings"
|
||||
className="col-span-1 bg-[var(--user-sideBox)] rounded-lg p-6 grid grid-rows-[auto_1fr] text-center items-center justify-center"
|
||||
>
|
||||
{/* User Type (e.g., "USER") */}
|
||||
<small className="text-green-400">
|
||||
{userPageVariant.toUpperCase()}
|
||||
</small>
|
||||
<div
|
||||
id="settings"
|
||||
className="col-span-1 bg-[var(--user-sideBox)] rounded-lg p-6 grid grid-rows-[auto_1fr] text-center items-center justify-center"
|
||||
>
|
||||
{/* User Type (e.g., "USER") */}
|
||||
<small className="text-green-400">{userPageVariant.toUpperCase()}</small>
|
||||
|
||||
<div className="mt-6 text-center">
|
||||
<h2 className="text-xl font-semibold mb-3">
|
||||
About {profileData.username}
|
||||
</h2>
|
||||
<p className="text-gray-300 whitespace-pre-wrap">
|
||||
{profileData.bio}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-6 text-center">
|
||||
<h2 className="text-xl font-semibold mb-3">About {profileData.username}</h2>
|
||||
<p className="text-gray-300 whitespace-pre-wrap">{profileData.bio}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Content Section */}
|
||||
<div
|
||||
id="content"
|
||||
className="col-span-2 bg-[var(--user-contentBox)] rounded-lg p-6 grid grid-rows-[auto_1fr] text-center items-center justify-center"
|
||||
>
|
||||
{userPageVariant === "streamer" && (
|
||||
<>
|
||||
{profileData.isLive ? (
|
||||
<div className="mb-8">
|
||||
<h2 className="text-2xl bg-[#ff0000] border py-4 px-12 font-black mb-4 rounded-[4rem]">
|
||||
Currently Live!
|
||||
</h2>
|
||||
<StreamListItem
|
||||
id={profileData.id}
|
||||
title={profileData.currentStreamTitle || ""}
|
||||
streamCategory=""
|
||||
username=""
|
||||
viewers={profileData.currentStreamViewers || 0}
|
||||
thumbnail={profileData.currentStreamThumbnail}
|
||||
onItemClick={() => {
|
||||
navigate(`/${profileData.username}`);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<h1>Currently not live</h1>
|
||||
)}
|
||||
{/* Content Section */}
|
||||
<div
|
||||
id="content"
|
||||
className="col-span-2 bg-[var(--user-contentBox)] rounded-lg p-6 grid grid-rows-[auto_1fr] text-center items-center justify-center"
|
||||
>
|
||||
{userPageVariant === "streamer" && (
|
||||
<>
|
||||
{profileData.isLive ? (
|
||||
<div className="mb-8">
|
||||
<h2 className="text-2xl bg-[#ff0000] border py-4 px-12 font-black mb-4 rounded-[4rem]">Currently Live!</h2>
|
||||
<StreamListItem
|
||||
id={profileData.id}
|
||||
title={profileData.currentStreamTitle || ""}
|
||||
streamCategory=""
|
||||
username=""
|
||||
viewers={profileData.currentStreamViewers || 0}
|
||||
thumbnail={profileData.currentStreamThumbnail}
|
||||
onItemClick={() => {
|
||||
navigate(`/${profileData.username}`);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<h1>Currently not live</h1>
|
||||
)}
|
||||
|
||||
{/* ↓↓ VODS ↓↓ */}
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold mb-4">Past Broadcasts</h2>
|
||||
<div className="text-gray-400 rounded-none">
|
||||
No past broadcasts found
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{/* ↓↓ VODS ↓↓ */}
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold mb-4">Past Broadcasts</h2>
|
||||
<div className="text-gray-400 rounded-none">No past broadcasts found</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{userPageVariant === "user" && (
|
||||
<>
|
||||
{/* ↓↓ VODS ↓↓ */}
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold mb-4">Past Broadcasts</h2>
|
||||
<div className="text-gray-400 rounded-none">
|
||||
No past broadcasts found
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
{userPageVariant === "user" && (
|
||||
<>
|
||||
{/* ↓↓ VODS ↓↓ */}
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold mb-4">Past Broadcasts</h2>
|
||||
<div className="text-gray-400 rounded-none">No past broadcasts found</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div
|
||||
id="mini"
|
||||
className="bg-[var(--user-sideBox)] col-span-1 rounded-lg text-center items-center justify-center
|
||||
<div
|
||||
id="mini"
|
||||
className="bg-[var(--user-sideBox)] col-span-1 rounded-lg text-center items-center justify-center
|
||||
flex flex-col flex-grow gap-4 p-[2rem]"
|
||||
>
|
||||
<div
|
||||
className="bg-[var(--user-follow-bg)] rounded-[1em] hover:scale-105 transition-all ease-in-out duration-300
|
||||
>
|
||||
<div
|
||||
className="bg-[var(--user-follow-bg)] rounded-[1em] hover:scale-105 transition-all ease-in-out duration-300
|
||||
flex items-center justify-center w-full p-4 content-start"
|
||||
onMouseEnter={(e) =>
|
||||
(e.currentTarget.style.boxShadow = "var(--follow-shadow)")
|
||||
}
|
||||
onMouseLeave={(e) => (e.currentTarget.style.boxShadow = "none")}
|
||||
>
|
||||
<button
|
||||
className="text-[var(--follow-text)] whitespace-pre-wrap"
|
||||
onClick={() => navigate(`/user/${username}/following`)}
|
||||
>
|
||||
Following
|
||||
</button>
|
||||
</div>
|
||||
<div
|
||||
className="bg-[var(--user-follow-bg)] rounded-[1em] hover:scale-105 transition-all ease-in-out duration-300
|
||||
onMouseEnter={(e) => (e.currentTarget.style.boxShadow = "var(--follow-shadow)")}
|
||||
onMouseLeave={(e) => (e.currentTarget.style.boxShadow = "none")}
|
||||
>
|
||||
<button className="text-[var(--follow-text)] whitespace-pre-wrap" onClick={() => navigate(`/user/${username}/following`)}>
|
||||
Following
|
||||
</button>
|
||||
</div>
|
||||
<div
|
||||
className="bg-[var(--user-follow-bg)] rounded-[1em] hover:scale-105 transition-all ease-in-out duration-300
|
||||
flex items-center justify-center w-full p-4 content-start"
|
||||
onMouseEnter={(e) =>
|
||||
(e.currentTarget.style.boxShadow = "var(--follow-shadow)")
|
||||
}
|
||||
onMouseLeave={(e) => (e.currentTarget.style.boxShadow = "none")}
|
||||
>
|
||||
<ul className="list-none">
|
||||
<li className="text-[var(--follow-text)] whitespace-pre-wrap list-none">
|
||||
Streamers
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div
|
||||
className="bg-[var(--user-follow-bg)] rounded-[1em] hover:scale-105 transition-all ease-in-out duration-300
|
||||
onMouseEnter={(e) => (e.currentTarget.style.boxShadow = "var(--follow-shadow)")}
|
||||
onMouseLeave={(e) => (e.currentTarget.style.boxShadow = "none")}
|
||||
>
|
||||
<ul className="list-none">
|
||||
<li className="text-[var(--follow-text)] whitespace-pre-wrap list-none">Streamers</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div
|
||||
className="bg-[var(--user-follow-bg)] rounded-[1em] hover:scale-105 transition-all ease-in-out duration-300
|
||||
flex items-center justify-center w-full p-4 content-start"
|
||||
onMouseEnter={(e) =>
|
||||
(e.currentTarget.style.boxShadow = "var(--follow-shadow)")
|
||||
}
|
||||
onMouseLeave={(e) => (e.currentTarget.style.boxShadow = "none")}
|
||||
>
|
||||
<button
|
||||
onClick={() => navigate(`/user/${username}/yourCategories`)}
|
||||
>
|
||||
Categories
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{showAuthModal && <AuthModal onClose={() => setShowAuthModal(false)} />}
|
||||
</DynamicPageContent>
|
||||
);
|
||||
onMouseEnter={(e) => (e.currentTarget.style.boxShadow = "var(--follow-shadow)")}
|
||||
onMouseLeave={(e) => (e.currentTarget.style.boxShadow = "none")}
|
||||
>
|
||||
<button onClick={() => navigate(`/user/${username}/yourCategories`)}>Categories</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{showAuthModal && <AuthModal onClose={() => setShowAuthModal(false)} />}
|
||||
</DynamicPageContent>
|
||||
);
|
||||
};
|
||||
|
||||
export default UserPage;
|
||||
|
||||
@@ -16,245 +16,228 @@ import { StreamType } from "../types/StreamType";
|
||||
const CheckoutForm = lazy(() => import("../components/Checkout/CheckoutForm"));
|
||||
|
||||
interface VideoPageProps {
|
||||
streamerId: number;
|
||||
streamerId: number;
|
||||
}
|
||||
|
||||
const VideoPage: React.FC<VideoPageProps> = ({ streamerId }) => {
|
||||
const { isLoggedIn } = useAuth();
|
||||
const { streamerName } = useParams<{ streamerName: string }>();
|
||||
const [streamData, setStreamData] = useState<StreamType>();
|
||||
const [viewerCount, setViewerCount] = useState(0);
|
||||
const { showSideBar } = useSidebar();
|
||||
const { isFollowing, checkFollowStatus, followUser, unfollowUser } =
|
||||
useFollow();
|
||||
const { showAuthModal, setShowAuthModal } = useAuthModal();
|
||||
const [isStripeReady, setIsStripeReady] = useState(false);
|
||||
const [showCheckout, setShowCheckout] = useState(false);
|
||||
const { showChat } = useChat();
|
||||
const navigate = useNavigate();
|
||||
const [timeStarted, setTimeStarted] = useState("");
|
||||
const { isLoggedIn } = useAuth();
|
||||
const { streamerName } = useParams<{ streamerName: string }>();
|
||||
const [streamData, setStreamData] = useState<StreamType>();
|
||||
const [viewerCount, setViewerCount] = useState(0);
|
||||
const { showSideBar } = useSidebar();
|
||||
const { isFollowing, checkFollowStatus, followUser, unfollowUser } = useFollow();
|
||||
const { showAuthModal, setShowAuthModal } = useAuthModal();
|
||||
const [isStripeReady, setIsStripeReady] = useState(false);
|
||||
const [showCheckout, setShowCheckout] = useState(false);
|
||||
const { showChat } = useChat();
|
||||
const navigate = useNavigate();
|
||||
const [timeStarted, setTimeStarted] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
// Prevent scrolling when checkout is open
|
||||
if (showCheckout) {
|
||||
document.body.style.overflow = "hidden";
|
||||
} else {
|
||||
document.body.style.overflow = "unset";
|
||||
}
|
||||
// Cleanup function to ensure overflow is restored when component unmounts
|
||||
return () => {
|
||||
document.body.style.overflow = "unset";
|
||||
};
|
||||
}, [showCheckout]);
|
||||
useEffect(() => {
|
||||
// Prevent scrolling when checkout is open
|
||||
if (showCheckout) {
|
||||
document.body.style.overflow = "hidden";
|
||||
} else {
|
||||
document.body.style.overflow = "unset";
|
||||
}
|
||||
// Cleanup function to ensure overflow is restored when component unmounts
|
||||
return () => {
|
||||
document.body.style.overflow = "unset";
|
||||
};
|
||||
}, [showCheckout]);
|
||||
|
||||
// Increment minutes of stream time every minute
|
||||
useEffect;
|
||||
// Increment minutes of stream time every minute
|
||||
useEffect;
|
||||
|
||||
useEffect(() => {
|
||||
// Fetch stream data for this streamer
|
||||
fetch(`/api/streams/${streamerId}/data`).then((res) => {
|
||||
if (!res.ok) {
|
||||
console.error("Failed to load stream data:", res.statusText);
|
||||
}
|
||||
res
|
||||
.json()
|
||||
.then((data) => {
|
||||
const transformedData: StreamType = {
|
||||
type: "stream",
|
||||
id: data.stream_id,
|
||||
username: data.username,
|
||||
title: data.title,
|
||||
startTime: data.start_time,
|
||||
streamCategory: data.category_name,
|
||||
viewers: data.viewers,
|
||||
};
|
||||
setStreamData(transformedData);
|
||||
useEffect(() => {
|
||||
// Fetch stream data for this streamer
|
||||
fetch(`/api/streams/${streamerId}/data`).then((res) => {
|
||||
if (!res.ok) {
|
||||
console.error("Failed to load stream data:", res.statusText);
|
||||
}
|
||||
res
|
||||
.json()
|
||||
.then((data) => {
|
||||
const transformedData: StreamType = {
|
||||
type: "stream",
|
||||
id: data.stream_id,
|
||||
username: data.username,
|
||||
title: data.title,
|
||||
startTime: data.start_time,
|
||||
streamCategory: data.category_name,
|
||||
viewers: data.viewers,
|
||||
};
|
||||
setStreamData(transformedData);
|
||||
|
||||
// Check if the logged-in user is following this streamer
|
||||
if (isLoggedIn) checkFollowStatus(data.username);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error fetching stream data:", error);
|
||||
});
|
||||
});
|
||||
}, [streamerId]);
|
||||
// Check if the logged-in user is following this streamer
|
||||
if (isLoggedIn) checkFollowStatus(data.username);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error fetching stream data:", error);
|
||||
});
|
||||
});
|
||||
}, [streamerId]);
|
||||
|
||||
// Time counter using DD:HH:MM:SS format
|
||||
useEffect(() => {
|
||||
if (!streamData?.startTime) return;
|
||||
// Time counter using DD:HH:MM:SS format
|
||||
useEffect(() => {
|
||||
if (!streamData?.startTime) return;
|
||||
|
||||
// Initial calculation
|
||||
const startTime = new Date(streamData.startTime).getTime();
|
||||
// Initial calculation
|
||||
const startTime = new Date(streamData.startTime).getTime();
|
||||
|
||||
const calculateTimeDifference = () => {
|
||||
// Get the difference in seconds
|
||||
const diffInSeconds = Math.floor((Date.now() - startTime) / 1000);
|
||||
const calculateTimeDifference = () => {
|
||||
// Get the difference in seconds
|
||||
const diffInSeconds = Math.floor((Date.now() - startTime) / 1000);
|
||||
|
||||
// Calculate days, hours, minutes, seconds
|
||||
const days = Math.floor(diffInSeconds / 86400);
|
||||
const hours = Math.floor((diffInSeconds % 86400) / 3600);
|
||||
const minutes = Math.floor((diffInSeconds % 3600) / 60);
|
||||
const seconds = diffInSeconds % 60;
|
||||
// Calculate days, hours, minutes, seconds
|
||||
const days = Math.floor(diffInSeconds / 86400);
|
||||
const hours = Math.floor((diffInSeconds % 86400) / 3600);
|
||||
const minutes = Math.floor((diffInSeconds % 3600) / 60);
|
||||
const seconds = diffInSeconds % 60;
|
||||
|
||||
// Format as DD:HH:MM:SS
|
||||
setTimeStarted(
|
||||
`${days.toString().padStart(2, "0")}:${hours
|
||||
.toString()
|
||||
.padStart(2, "0")}:${minutes.toString().padStart(2, "0")}:${seconds
|
||||
.toString()
|
||||
.padStart(2, "0")}`
|
||||
);
|
||||
};
|
||||
// Format as DD:HH:MM:SS
|
||||
setTimeStarted(
|
||||
`${days.toString().padStart(2, "0")}:${hours.toString().padStart(2, "0")}:${minutes.toString().padStart(2, "0")}:${seconds
|
||||
.toString()
|
||||
.padStart(2, "0")}`
|
||||
);
|
||||
};
|
||||
|
||||
// Calculate immediately
|
||||
calculateTimeDifference();
|
||||
// Calculate immediately
|
||||
calculateTimeDifference();
|
||||
|
||||
// Set up interval to update every second
|
||||
const intervalId = setInterval(calculateTimeDifference, 1000);
|
||||
// Set up interval to update every second
|
||||
const intervalId = setInterval(calculateTimeDifference, 1000);
|
||||
|
||||
// Clean up interval on component unmount
|
||||
return () => clearInterval(intervalId);
|
||||
}, [streamData?.startTime]); // Re-run if startTime changes
|
||||
// Clean up interval on component unmount
|
||||
return () => clearInterval(intervalId);
|
||||
}, [streamData?.startTime]); // Re-run if startTime changes
|
||||
|
||||
// Load Stripe in the background when component mounts
|
||||
useEffect(() => {
|
||||
const loadStripe = async () => {
|
||||
await import("@stripe/stripe-js");
|
||||
setIsStripeReady(true);
|
||||
};
|
||||
loadStripe();
|
||||
}, []);
|
||||
// Load Stripe in the background when component mounts
|
||||
useEffect(() => {
|
||||
const loadStripe = async () => {
|
||||
await import("@stripe/stripe-js");
|
||||
setIsStripeReady(true);
|
||||
};
|
||||
loadStripe();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<SocketProvider>
|
||||
<DynamicPageContent className="w-full min-h-screen">
|
||||
<div
|
||||
id="container"
|
||||
className={`bg-gray-900 h-full grid ${
|
||||
showChat
|
||||
? showSideBar
|
||||
? "w-[85vw] duration-[1s]"
|
||||
: "w-[100vw] duration-[0.5s]"
|
||||
: showSideBar
|
||||
? "w-[110vw] duration-[1s]"
|
||||
: "w-[125vw] duration-[0.5s]"
|
||||
} grid-rows-[auto_1fr] grid-cols-[auto_25vw] transition-all ease-in-out`}
|
||||
>
|
||||
<div className="relative">
|
||||
<VideoPlayer />
|
||||
</div>
|
||||
return (
|
||||
<SocketProvider>
|
||||
<DynamicPageContent className="w-full min-h-screen">
|
||||
<div
|
||||
id="container"
|
||||
className={`bg-gray-900 h-full grid ${
|
||||
showChat
|
||||
? showSideBar
|
||||
? "w-[85vw] duration-[1s]"
|
||||
: "w-[100vw] duration-[0.5s]"
|
||||
: showSideBar
|
||||
? "w-[110vw] duration-[1s]"
|
||||
: "w-[125vw] duration-[0.5s]"
|
||||
} grid-rows-[auto_1fr] grid-cols-[auto_25vw] transition-all ease-in-out`}
|
||||
>
|
||||
<div className="relative">
|
||||
<VideoPlayer />
|
||||
</div>
|
||||
|
||||
<ChatPanel
|
||||
streamId={streamerId}
|
||||
onViewerCountChange={(count: number) => setViewerCount(count)}
|
||||
/>
|
||||
<ChatPanel streamId={streamerId} onViewerCountChange={(count: number) => setViewerCount(count)} />
|
||||
|
||||
{/* Stream Data */}
|
||||
<div
|
||||
id="stream-info"
|
||||
className="flex flex-row items-center justify-between gap-4 p-4 bg-[#18181b] text-white text-lg rounded-md shadow-lg"
|
||||
>
|
||||
{/* Streamer Icon */}
|
||||
<div className="flex flex-col items-center mb-[1em]">
|
||||
<img
|
||||
src="/images/monkey.png"
|
||||
alt="streamer"
|
||||
className="w-[3em] h-[3em] rounded-full border-[0.15em] border-purple-500 cursor-pointer"
|
||||
onClick={() => navigate(`/user/${streamerName}`)}
|
||||
/>
|
||||
<button
|
||||
className="text-white font-bold hover:underline mt-[0.5em]"
|
||||
onClick={() => navigate(`/user/${streamerName}`)}
|
||||
>
|
||||
{streamerName}
|
||||
</button>
|
||||
</div>
|
||||
{/* Stream Data */}
|
||||
<div
|
||||
id="stream-info"
|
||||
className="flex flex-row items-center justify-between gap-4 p-4 bg-[#18181b] text-white text-lg rounded-md shadow-lg"
|
||||
>
|
||||
{/* Streamer Icon */}
|
||||
<div className="flex flex-col items-center mb-[1em]">
|
||||
<img
|
||||
src={`/user/${streamerName}/profile_picture`}
|
||||
onError={(e) => {
|
||||
e.currentTarget.src = "/images/pfps/default.png";
|
||||
e.currentTarget.onerror = null;
|
||||
}}
|
||||
alt="streamer"
|
||||
className="w-[3em] h-[3em] rounded-full border-[0.15em] border-purple-500 cursor-pointer"
|
||||
onClick={() => navigate(`/user/${streamerName}`)}
|
||||
/>
|
||||
<button className="text-white font-bold hover:underline mt-[0.5em]" onClick={() => navigate(`/user/${streamerName}`)}>
|
||||
{streamerName}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Stream Title */}
|
||||
<div className="flex flex-col items-start flex-grow">
|
||||
<h2 className="text-[0.75em] lg:text-[0.85em] xl:text-[1em] font-bold">
|
||||
{streamData ? streamData.title : "Loading..."}
|
||||
</h2>
|
||||
<a href={streamData ? `/category/${streamData.streamCategory}` : "#"} className="text-[0.75em] lg:text-[0.85em] xl:text-[1em] text-gray-400">
|
||||
{streamData ? streamData.streamCategory : "Loading..."}
|
||||
</a>
|
||||
</div>
|
||||
{/* Stream Title */}
|
||||
<div className="flex flex-col items-start flex-grow">
|
||||
<h2 className="text-[0.75em] lg:text-[0.85em] xl:text-[1em] font-bold">{streamData ? streamData.title : "Loading..."}</h2>
|
||||
<a
|
||||
href={streamData ? `/category/${streamData.streamCategory}` : "#"}
|
||||
className="text-[0.75em] lg:text-[0.85em] xl:text-[1em] text-gray-400"
|
||||
>
|
||||
{streamData ? streamData.streamCategory : "Loading..."}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{/* Streamer Info */}
|
||||
<div className="flex items-center gap-[0.75em] flex-col lg:flex-row">
|
||||
<div className="group flex flex-col items-center lg:items-start">
|
||||
{!isFollowing ? (
|
||||
<button
|
||||
className="bg-purple-600 text-white font-bold px-[1.5em] py-[0.5em] rounded-md hover:bg-purple-700 text-sm"
|
||||
onClick={() => followUser(streamerId, setShowAuthModal)}
|
||||
>
|
||||
Follow
|
||||
</button>
|
||||
) : (
|
||||
<button
|
||||
className="bg-gray-700 text-white font-bold px-[1.5em] py-[0.5em] rounded-md hover:bg-red-600 text-sm transition-all"
|
||||
onClick={() => unfollowUser(streamerId, setShowAuthModal)}
|
||||
>
|
||||
<span className="group-hover:hidden">Following</span>
|
||||
<span className="hidden group-hover:block">Unfollow</span>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{/* Streamer Info */}
|
||||
<div className="flex items-center gap-[0.75em] flex-col lg:flex-row">
|
||||
<div className="group flex flex-col items-center lg:items-start">
|
||||
{!isFollowing ? (
|
||||
<button
|
||||
className="bg-purple-600 text-white font-bold px-[1.5em] py-[0.5em] rounded-md hover:bg-purple-700 text-sm"
|
||||
onClick={() => followUser(streamerId, setShowAuthModal)}
|
||||
>
|
||||
Follow
|
||||
</button>
|
||||
) : (
|
||||
<button
|
||||
className="bg-gray-700 text-white font-bold px-[1.5em] py-[0.5em] rounded-md hover:bg-red-600 text-sm transition-all"
|
||||
onClick={() => unfollowUser(streamerId, setShowAuthModal)}
|
||||
>
|
||||
<span className="group-hover:hidden">Following</span>
|
||||
<span className="hidden group-hover:block">Unfollow</span>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Stream Stats */}
|
||||
<div className="flex flex-col items-center">
|
||||
<div className="flex items-center gap-[0.5em]">
|
||||
<img
|
||||
src="../../../images/icons/user.png"
|
||||
alt="Viewers Icon"
|
||||
className="w-[1em] h-[1em] md:w-[1.2em] md:h-[1.2em]"
|
||||
/>
|
||||
<span className="font-bold text-[1.2em]">{viewerCount}</span>
|
||||
</div>
|
||||
</div>
|
||||
{/* Stream Stats */}
|
||||
<div className="flex flex-col items-center">
|
||||
<div className="flex items-center gap-[0.5em]">
|
||||
<img src="/images/icons/user.png" alt="Viewers Icon" className="w-[1em] h-[1em] md:w-[1.2em] md:h-[1.2em]" />
|
||||
<span className="font-bold text-[1.2em]">{viewerCount}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col items-center p-4 min-w-fit">
|
||||
<span className="text-[0.75em]">
|
||||
{streamData ? timeStarted : "Loading..."}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex flex-col items-center p-4 min-w-fit">
|
||||
<span className="text-[0.75em]">{streamData ? timeStarted : "Loading..."}</span>
|
||||
</div>
|
||||
|
||||
{/* Subscribe Button */}
|
||||
<div className="flex flex-col items-center">
|
||||
<button
|
||||
className={`bg-red-600 text-white font-bold px-[1.5em] py-[0.5em] rounded-md
|
||||
${
|
||||
isStripeReady ? "hover:bg-red-700" : "opacity-20 cursor-not-allowed"
|
||||
} transition-all`}
|
||||
onClick={() => {
|
||||
if (!isLoggedIn) {
|
||||
setShowAuthModal(true);
|
||||
} else if (isStripeReady) {
|
||||
setShowCheckout(true);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{isStripeReady ? "Subscribe" : "Loading..."}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{showCheckout && (
|
||||
<Suspense fallback={<div>Loading checkout...</div>}>
|
||||
<CheckoutForm
|
||||
onClose={() => setShowCheckout(false)}
|
||||
streamerID={streamerId}
|
||||
/>
|
||||
</Suspense>
|
||||
)}
|
||||
{/* {showReturn && <Return />} */}
|
||||
{showAuthModal && (
|
||||
<AuthModal onClose={() => setShowAuthModal(false)} />
|
||||
)}
|
||||
</div>
|
||||
</DynamicPageContent>
|
||||
</SocketProvider>
|
||||
);
|
||||
{/* Subscribe Button */}
|
||||
<div className="flex flex-col items-center">
|
||||
<button
|
||||
className={`bg-red-600 text-white font-bold px-[1.5em] py-[0.5em] rounded-md
|
||||
${isStripeReady ? "hover:bg-red-700" : "opacity-20 cursor-not-allowed"} transition-all`}
|
||||
onClick={() => {
|
||||
if (!isLoggedIn) {
|
||||
setShowAuthModal(true);
|
||||
} else if (isStripeReady) {
|
||||
setShowCheckout(true);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{isStripeReady ? "Subscribe" : "Loading..."}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{showCheckout && (
|
||||
<Suspense fallback={<div>Loading checkout...</div>}>
|
||||
<CheckoutForm onClose={() => setShowCheckout(false)} streamerID={streamerId} />
|
||||
</Suspense>
|
||||
)}
|
||||
{/* {showReturn && <Return />} */}
|
||||
{showAuthModal && <AuthModal onClose={() => setShowAuthModal(false)} />}
|
||||
</div>
|
||||
</DynamicPageContent>
|
||||
</SocketProvider>
|
||||
);
|
||||
};
|
||||
|
||||
export default VideoPage;
|
||||
|
||||
Reference in New Issue
Block a user