Skip to content

Commit

Permalink
delete deploy.yml file
Browse files Browse the repository at this point in the history
  • Loading branch information
Somnath-Chattaraj committed Oct 13, 2024
2 parents 4dad0dd + 98dee5f commit f239b9b
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 29 deletions.
4 changes: 3 additions & 1 deletion backend/src/controllers/userControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ const googleSignInOrSignUp = asyncHandler(
sameSite: "lax",
});
const username = user.username;
res.status(200).json({ isCollegeEmail, username });
const userId = user.user_id;
res.status(200).json({ isCollegeEmail, username, userId });
}
);

Expand Down Expand Up @@ -318,6 +319,7 @@ const getCurrentUserDetails = asyncHandler(
user_id: true,
email: true,
username: true,
pic: true,
userCourses: {
select: {
Course: {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/AddUsername.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const AddUsername = () => {
setLoading(false);
toast({
title: "Error",
description: "Error adding username.",
description: err.response?.data.message || "An error occurred",
status: "error",
duration: 3000,
isClosable: true,
Expand Down
66 changes: 40 additions & 26 deletions frontend/src/components/EditDetails.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import {
Box,
FormControl,
Expand All @@ -8,6 +8,8 @@ import {
VStack,
useToast,
Flex,
Avatar,
Text,
} from "@chakra-ui/react";
import { z } from "zod";
import axios from "axios";
Expand Down Expand Up @@ -41,24 +43,31 @@ const EditDetails = () => {
setFormData({ ...formData, pic: e.target.files[0] });
};

if (loadingUser) {
return (
<Flex minH="100vh" align="center" justify="center" bg="black">
<InfinitySpin color="#3182CE" size={80} />
</Flex>
);
}
if (!userDetails) {
toast({
title: "Error",
description: "You need to be logged in to access this page.",
status: "error",
duration: 3000,
isClosable: true,
});
navigate("/login");
return;
}
useEffect(() => {
if (loadingUser) return;

if (!userDetails) {
toast({
title: "Error",
description: "You need to be logged in to access this page.",
status: "error",
duration: 3000,
isClosable: true,
});
navigate("/login");
} else if (userDetails.username === null) {
navigate(`/addusername/${userDetails.user_id}`);
}
}, [userDetails, loadingUser, navigate, toast]);

useEffect(() => {
if (userDetails) {
setFormData({
username: userDetails.username || "",
pic: "",
});
}
}, [userDetails]);

const handleSubmit = async (e) => {
e.preventDefault();
Expand Down Expand Up @@ -92,13 +101,6 @@ const EditDetails = () => {
pic: picUrl,
};

const user = await axios.get("/api/user/me", {
withCredentials: true,
});
if (!updatedFormData.username) {
updatedFormData.username = user.data.username;
}

EditDetailsSchema.parse(updatedFormData);
setError({});

Expand Down Expand Up @@ -130,8 +132,20 @@ const EditDetails = () => {
}
};

if (loadingUser) {
return (
<Flex minH="100vh" align="center" justify="center" bg="black">
<InfinitySpin color="#3182CE" size={80} />
</Flex>
);
}

return (
<Box w="100%" maxW="500px" mx="auto" mt="5">
<Box textAlign="center" mb={6}>
<Avatar size="xl" src={userDetails.pic} mb={2} />
<Text fontSize="lg">{userDetails?.username || "Your Username"}</Text>
</Box>
<form onSubmit={handleSubmit}>
<VStack spacing={4}>
<FormControl id="username">
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/Posts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ const Posts = () => {
withCredentials: true,
});
setAllCommunities(response.data.college);
console.log(response.data.college);
setLoading(false);
} catch (err) {
setLoading(false);
Expand Down Expand Up @@ -167,6 +166,9 @@ const Posts = () => {
if (!userDetails) {
return <Navigate to="/login" />;
}
if (userDetails.username === null) {
return <Navigate to={`/addusername/${userDetails.user_id}`} />;
}
return (
<Container centerContent>
<SearchBar />
Expand Down
18 changes: 18 additions & 0 deletions frontend/src/components/SinglePost.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ import {
} from "@chakra-ui/react";
import axios from "axios";
import CreateComment from "./CreateComment"; // Import the CreateComment component
import { useUser } from "../hook/useUser";
import { InfinitySpin } from "react-loader-spinner";

const SinglePost = () => {
const { id } = useParams();
const [post, setPost] = useState(null);
const [loading, setLoading] = useState(true);
const [postLiked, setPostLiked] = useState(false);
const { userDetails, loadingUser } = useUser();

useEffect(() => {
const fetchPost = async () => {
Expand Down Expand Up @@ -55,6 +58,21 @@ const SinglePost = () => {
checkIfLiked();
}, [id]);

if (loadingUser) {
return (
<Center h="100vh">
<InfinitySpin />
</Center>
);
}

if (!userDetails) {
return <Navigate to="/login" />;
}
if (userDetails.username === null) {
return <Navigate to={`/addusername/${userDetails.userId}`} />;
}

const handleLike = async (postId) => {
if (postLiked) {
try {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/chatroomui/joinRoom1.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ const JoinRoom1 = () => {
);
}

if (userDetails.username == null) {
navigate(`/addusername/${userDetails.user_id}`);
}

function handleClick(roomId) {
localStorage.removeItem("roomId");
localStorage.removeItem("userId");
Expand Down

0 comments on commit f239b9b

Please sign in to comment.