import Navbar from "../components/Navbar.jsx"; import {useEffect, useState} from "react"; import {useNavigate, useParams} from "react-router-dom"; import {useAuth} from "../contexts/AuthContext.jsx"; import VideoStatListElement from "../components/VideoStatListElement.jsx"; import {fetchChannelDetails, fetchChannelStats, updateChannel} from "../services/channel.service.js"; export default function ManageChannel() { const {id} = useParams(); const {user} = useAuth(); const navigate = useNavigate(); const [channel, setChannel] = useState(); const [channelStats, setChannelStats] = useState(); const [channelName, setChannelName] = useState(null); const [description, setDescription] = useState(null); const [editMode, setEditMode] = useState(false); const [alerts, setAlerts] = useState([]); const token = localStorage.getItem("token"); const nonEditModeClasses = "text-2xl font-bold text-white p-2 focus:text-white focus:outline-none w-full font-montserrat resizable-none text-center"; const editModeClasses = nonEditModeClasses + " glassmorphism"; const nonEditModeClassesTextArea = "text-md font-normal text-white p-2 focus:text-white focus:outline-none w-full font-montserrat resizable-none w-full" const editModeClassesTextArea = nonEditModeClassesTextArea + " glassmorphism h-48"; useEffect(() => { fetchChannelData() fetchStats() }, []); const fetchChannelData = async () => { setChannel(await fetchChannelDetails(id, addAlert)); } const fetchStats = async () => { setChannelStats(await fetchChannelStats(id, token, addAlert)); } const handleUpdateChannel = async () => { if (!editMode) return; const data = { name: channelName || channel.name, description: description || channel.description, }; const response = await updateChannel(id, data, token, addAlert); if (response) { setEditMode(false); } } const onCloseAlert = (alertToRemove) => { setAlerts(alerts.filter(alert => alert !== alertToRemove)); }; const addAlert = (type, message) => { const newAlert = { type, message, id: Date.now() }; // Add unique ID setAlerts([...alerts, newAlert]); }; return (
{/* LEFT SIDE */}
setChannelName(e.target.value)} placeholder="Nom d'utilisateur" disabled={!editMode} /> { editMode ? (
) : ( ) }
{/* RIGHT SIDE */}
{/* VIEW / SUBSCRIBERS STATS */}
{/* TOTAL VIEWS */}

Vues totales

{channelStats ? channelStats.views : "0"}

{/* TOTAL SUBSCRIBERS */}

Abonnés

{channelStats ? channelStats.subscribers : "0"}

{/* VIDEOS */}

Vidéos

{ channel?.videos?.length > 0 ? (
{channel.videos.map((video) => ( navigate("/manage-video/" + video.id)} key={video.id} /> ))}
) : (

Aucune vidéo trouvée pour cette chaîne.

)}
) }