{userChannel.channel.name}
Chaîne
Aucune chaîne associée à ce compte.
import Navbar from "../components/Navbar.jsx"; import {useEffect, useState} from "react"; import PlaylistCard from "../components/PlaylistCard.jsx"; import VideoCard from "../components/VideoCard.jsx"; import {useNavigate} from "react-router-dom"; import CreateChannelModal from "../modals/CreateChannelModal.jsx"; import { getChannel, getUserHistory, getPlaylists, updateUser } from "../services/user.service.js"; export default function Account() { let user = JSON.parse(localStorage.getItem("user")) || {}; let token = localStorage.getItem("token") || ""; const [username, setUsername] = useState(user.username || ""); const [email, setEmail] = useState(user.email || ""); const [password, setPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const [isPictureEditActive, setIsPictureEditActive] = useState(false); const [userHistory, setUserHistory] = useState([]); const [userPlaylists, setUserPlaylists] = useState([]); const [userChannel, setUserChannel] = useState(null); const [isModalOpen, setIsModalOpen] = useState(false); const [alerts, setAlerts] = useState([]); const navigation = useNavigate(); const fetchUserChannel = async () => { setUserChannel(await getChannel(user.id, token, addAlert)); // Reset before fetching } const fetchUserHistory = async () => { setUserHistory(await getUserHistory(user.id, token, addAlert)); } const fetchUserPlaylists = async () => { setUserPlaylists(await getPlaylists(user.id, token, addAlert)); } useEffect(() => { fetchUserChannel(); fetchUserHistory(); fetchUserPlaylists(); }, []); const [editMode, setEditMode] = useState(false); const nonEditModeClasses = "text-2xl font-bold text-white p-2 focus:text-white focus:outline-none w-full font-montserrat"; const editModeClasses = nonEditModeClasses + " glassmorphism"; const handlePlaylistClick = (playlistId) => { navigation(`/playlist/${playlistId}`); } const handleUpdateUser = async () => { if (password !== confirmPassword) { addAlert('error', "Les mots de passe ne correspondent pas."); return; } const updatedUser = { username, email, password: password || undefined, // Only send password if it's not empty }; const result = await updateUser(user.id, token, updatedUser, addAlert); if (result) { localStorage.setItem("user", JSON.stringify(result)); setEditMode(false); addAlert('success', "Profil mis à jour avec succès."); } } const addAlert = (type, message) => { const newAlert = { type, message, id: Date.now() }; // Add unique ID setAlerts([...alerts, newAlert]); }; const onCloseAlert = (alertToRemove) => { setAlerts(alerts.filter(alert => alert !== alertToRemove)); }; const closeModal = () => { setIsModalOpen(false); fetchUserChannel(); } return (
{userChannel.channel.name}
Aucune chaîne associée à ce compte.