Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix email issue #592

Merged
merged 3 commits into from
Jun 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 29 additions & 31 deletions src/pages/Profile/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,28 @@ import firebase from "firebase/compat/app";
import { useSnackbar } from "notistack";

function Profile() {
const location = useLocation();
const navigate = useNavigate();
const isNonMobile = useMediaQuery("(min-width: 768px)");
const { enqueueSnackbar } = useSnackbar();

const [user, setUser] = useState(null);
const [image, setImage] = useState("");
const [visible, setVisible] = useState(false);
const [feed, setFeed] = useState([]);
const [profilepic, setProfilePic] = useState("");
const [profilePic, setProfilePic] = useState("");
const [open, setOpen] = useState(false);
const [username, setUsername] = useState("");

const navigate = useNavigate();
const [friendRequestSent, setFriendRequestSent] = useState(false);
const [name, setName] = useState("");
const [email, setEmail] = useState("");
const [avatar, setAvatar] = useState("");

const handleClose = () => setOpen(false);

const handleSendFriendRequest = () => {
const currentUser = auth.currentUser;
const currentUserUid = currentUser.uid;
const targetUserUid = currentUserUid;
const currentUserUid = auth.currentUser.uid;
const targetUserUid = currentUserUid; // TODO: Change this to the user whose profile is being viewed
const friendRequestData = {
sender: currentUserUid,
recipient: targetUserUid,
Expand All @@ -49,7 +56,7 @@ function Profile() {
});
const notificationData = {
recipient: targetUserUid,
message: "You have received a friend request.",
message: `You have received a friend request from ${name}.`,
timestamp: firebase.firestore.FieldValue.serverTimestamp(),
};
db.collection("notifications").add(notificationData);
Expand All @@ -63,9 +70,8 @@ function Profile() {

useEffect(() => {
const checkFriendRequestSent = async () => {
const currentUser = auth.currentUser;
const currentUserUid = currentUser.uid;
const targetUserUid = currentUserUid;
const currentUserUid = auth.currentUser.uid;
const targetUserUid = currentUserUid; // TODO: Change this to the user whose profile is being viewed
const friendRequestsRef = db.collection("friendRequests");
const query = friendRequestsRef
.where("sender", "==", currentUserUid)
Expand All @@ -79,20 +85,9 @@ function Profile() {
checkFriendRequestSent();
}, []);

const location = useLocation();
const isNonMobile = useMediaQuery("(min-width: 768px)");
const { enqueueSnackbar } = useSnackbar();

let name = location?.state?.name || user?.displayName;
let email = location?.state?.email || user?.email;
let avatar = location?.state?.avatar || user?.photoURL;

const handleClose = () => setOpen(false);

useEffect(() => {
if (auth.currentUser) {
setUser(auth.currentUser);
setProfilePic(auth.currentUser.photoURL);
} else {
navigate("/dummygram/login");
}
Expand All @@ -102,11 +97,14 @@ function Profile() {
const unsubscribe = auth.onAuthStateChanged((authUser) => {
if (authUser) {
setUser(authUser);
name = location?.state?.name || authUser.displayName;
avatar = location?.state?.avatar || authUser.photoURL;
email = location?.state?.email || authUser.email;
setName(location?.state?.name || authUser.displayName);
setAvatar(location?.state?.avatar || authUser.photoURL);
setEmail(
location?.state?.name === authUser?.displayName
? location?.state?.email || authUser.email
: ""
);
} else {
setUser(null);
navigate("/dummygram/login");
}
});
Expand Down Expand Up @@ -227,7 +225,7 @@ function Profile() {
}}
width={isNonMobile ? "50%" : "50%"}
height={isNonMobile ? "50%" : "50%"}
src={profilepic}
src={profilePic}
alt="user"
/>
</Box>
Expand All @@ -254,7 +252,7 @@ function Profile() {
<Avatar
onClick={() => setOpen((on) => !on)}
alt={name}
src={profilepic}
src={profilePic}
sx={{
width: "22vh",
height: "22vh",
Expand Down Expand Up @@ -300,16 +298,16 @@ function Profile() {
</Button>
)}
<Divider sx={{ marginTop: "1rem" }} />
<Typography fontSize="1.3rem" fontWeight="600" fontFamily="Poppins">
<Typography fontSize="1.3rem" fontWeight="600">
{username}
</Typography>
<Divider />
<Typography fontSize="1.3rem" fontWeight="600" fontFamily="Poppins">
<Typography fontSize="1.3rem" fontWeight="600">
{name}
</Typography>
<Divider />
<Typography fontSize="1.5rem" fontWeight="600" fontFamily="Poppins">
{email && email}
<Typography fontSize="1.5rem" fontWeight="600">
{name === auth.currentUser.displayName && email}
</Typography>
{!friendRequestSent && name !== auth.currentUser.displayName && (
<Button
Expand Down