import React, { useState, useContext, useEffect, useRef } from "react"; import { getAuth, updateProfile, signOut } from "firebase/auth"; import { db } from "../Firebase/FirebaseConfig"; import { ref, uploadBytesResumable, getDownloadURL, getStorage, } from "firebase/storage"; import { useNavigate } from "react-router-dom"; import { Fade } from "react-reveal"; import toast, { Toaster } from "react-hot-toast"; import { AuthContext } from "../Context/UserContext"; import WelcomePageBanner from "../images/WelcomePageBanner.jpg"; import "swiper/css"; import "swiper/css/navigation"; import "swiper/css/pagination"; function Profile() { const { User } = useContext(AuthContext); const [profilePic, setProfilePic] = useState(""); const [newProfielPicURL, setNewProfielPicURL] = useState(""); const [newProfielPic, setNewProfielPic] = useState(""); const [isUserNameChanged, setIsUserNameChanged] = useState(false); const [userName, setUserName] = useState(""); const [isMyListUpdated, setisMyListUpdated] = useState(false); const navigate = useNavigate(); useEffect(() => { if (User != null) { console.log(User.photoURL, "hello"); setProfilePic(User.photoURL); } }, []); const inputRef = useRef(null); const handleClick = () => { inputRef.current.click(); }; function notify() { toast.success(" Data Updated Sucessfuly "); } const handleFileChange = (event) => { const fileObj = event.target.files[0]; setNewProfielPic(fileObj); setNewProfielPicURL(URL.createObjectURL(fileObj)); if (!fileObj) { return; } console.log("fileObj is", fileObj); event.target.value = null; }; const changeUserName = (e) => { e.preventDefault(); if (isUserNameChanged) { if (userName !== "") { const auth = getAuth(); updateProfile(auth.currentUser, { displayName: userName }) .then(() => { notify(); }) .catch((error) => { alert(error.message); }); } else { setIsUserNameChanged(false); } } if (newProfielPic != "") { const storage = getStorage(); const storageRef = ref(storage, `/ProfilePics/${User.uid}`); const uploadTask = uploadBytesResumable(storageRef, newProfielPic); uploadTask.on( "state_changed", (snapshot) => { const prog = Math.round( (snapshot.bytesTransferred / snapshot.totalBytes) * 100 ); }, (error) => { alert(error.message); alert(error.code); }, () => { getDownloadURL(uploadTask.snapshot.ref).then((url) => { console.log(url, "This is the new Url for Profile Pic"); setProfilePic(url); const auth = getAuth(); updateProfile(auth.currentUser, { photoURL: url }) .then(() => { notify(); setisMyListUpdated(true); }) .catch((error) => { alert(error.message); }); }); } ); } }; const updateProfilePic = (imageURL) => { const auth = getAuth(); updateProfile(auth.currentUser, { photoURL: imageURL }) .then(() => { setProfilePic(User.photoURL); notify(); }) .catch((error) => { alert(error.message); }); }; const SignOut = () => { const auth = getAuth(); signOut(auth) .then(() => { navigate("/"); }) .catch((error) => { alert(error.message); }); }; return (
{isMyListUpdated ? ( ) : null}

Edit your Profile

NETFLIX

User Name

setUserName(e.target.value) || setIsUserNameChanged(true) } className="block w-full rounded-md bg-stone-900 text-white border-gray-300 p-2 mb-6 focus:border-indigo-500 focus:ring-indigo-500 sm:text-base" placeholder={User ? User.displayName : null} />

Email

{User ? User.email : null}

Unique ID : {User ? User.uid : null}


Who is Watching ?

updateProfilePic( "https://i.pinimg.com/originals/ba/2e/44/ba2e4464e0d7b1882cc300feceac683c.png" ) } className="w-16 h-16 rounded-md cursor-pointer" src="https://i.pinimg.com/originals/ba/2e/44/ba2e4464e0d7b1882cc300feceac683c.png" /> updateProfilePic( "https://i.pinimg.com/736x/db/70/dc/db70dc468af8c93749d1f587d74dcb08.jpg" ) } className="w-16 h-16 rounded-md cursor-pointer" src="https://i.pinimg.com/736x/db/70/dc/db70dc468af8c93749d1f587d74dcb08.jpg" /> updateProfilePic( "https://upload.wikimedia.org/wikipedia/commons/0/0b/Netflix-avatar.png" ) } className="w-16 h-16 rounded-md cursor-pointer" src="https://upload.wikimedia.org/wikipedia/commons/0/0b/Netflix-avatar.png" /> updateProfilePic( "https://ih0.redbubble.net/image.618363037.0853/flat,1000x1000,075,f.u2.jpg" ) } className="w-16 h-16 rounded-md cursor-pointer" src="https://ih0.redbubble.net/image.618363037.0853/flat,1000x1000,075,f.u2.jpg" />
{newProfielPicURL ? ( ) : null}
{userName != "" || newProfielPic != "" ? ( ) : ( )}
); } export default Profile;