Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix0202 committed Oct 24, 2024
1 parent a234132 commit 7d4b8d2
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public Response getFollows(@HeaderParam("reqUserId") Long reqUserId, @PathParam(
@Path("/follow/{targetUserId}")
@Transactional
public Response followUser(@HeaderParam("reqUserId") Long reqUserId, @PathParam("targetUserId") Long targetUserId) {
System.out.println(targetUserId);
try {
return Response.ok(Relation.createRelation(reqUserId, targetUserId, RelationStatus.FRIEND)).build();
} catch (Exception e) {
Expand Down
5 changes: 3 additions & 2 deletions logic/frontend/web/src/app/FYP/ForYouComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ export default function ForYouComponent({ setShowPostComponent, setSelectedPost
sx={{
padding: "20px",
position: "sticky",
backgroundColor: "#22264B",
top: 0,
zIndex: 1,
}}
Expand All @@ -110,7 +109,6 @@ export default function ForYouComponent({ setShowPostComponent, setSelectedPost
<Grid container spacing={4}
sx={{
width: "100%",
overflowY: "scroll",
margin: "auto",
}}
>
Expand All @@ -130,6 +128,9 @@ export default function ForYouComponent({ setShowPostComponent, setSelectedPost
alignItems="center"
borderRadius="13px"
padding="10px"
sx={{
cursor: "pointer"
}}
onClick={() => handleGridItemClick(post)}
>
<Typography color="#ffffff" fontWeight={700}>
Expand Down
28 changes: 12 additions & 16 deletions logic/frontend/web/src/app/FYP/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,23 @@ export default function Page() {
<Grid size={8} component="div">
<Box
sx={{
width: "100%",
height: "80%",
display: "flex",
width: "90%",
height: "80vh",
justifyContent: "center",
alignItems: "center",
margin: "4em 5% 0 5%",
backgroundColor: "#22264B",
borderRadius: "1em",
overflow: "scroll"
}}
>
<Box
sx={{
width: "90%",
height: "90%",
backgroundColor: "#22264B",
borderRadius: "1em",
}}
>
{
showPostComponent && selectedPost &&
{
showPostComponent && selectedPost ?
<PostComponent post={selectedPost} onGoBack={handleGoBack}/>
}
<ForYouComponent setShowPostComponent={setShowPostComponent} setSelectedPost={setSelectedPost}/>
</Box>
:
<ForYouComponent setShowPostComponent={setShowPostComponent}
setSelectedPost={setSelectedPost}/>
}
</Box>
</Grid>
<Grid size={4}>
Expand Down
8 changes: 8 additions & 0 deletions logic/frontend/web/src/app/notification/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ export default function Page() {
<Box p={3} bgcolor="#1A1C40" color="white" borderRadius="8px">
<Typography variant="h4" mb={2}>Notifications</Typography>
<List>
{
notifications.length === 0 && (
<Typography component="span" color="grey">
No notifications yet
</Typography>
)
}

{notifications.map((notification) => (
<ListItem key={notification.id} sx={{ bgcolor: "#22264B", mb: 1, borderRadius: "8px" }}>
<ListItemText
Expand Down
104 changes: 60 additions & 44 deletions logic/frontend/web/src/app/profile/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use client";
import {useEffect, useState} from "react";
import React, {useEffect, useState} from "react";
import {Box, Typography, CircularProgress, Avatar, Grid, Button, Card, CardContent} from "@mui/material";
import axios from "axios";
import {useUser} from "@/provider/UserProvider";
Expand All @@ -11,45 +11,47 @@ export default function Page({params}: { params: { slug: string } }) {
const [loading, setLoading] = useState(true);
const {user} = useUser();

useEffect(() => {
async function fetchProfile() {
try {
// First request to get the user ID
const searchResponse = await axios.get(`https://www.boast.social/api/users/search/${params.slug}`, {
headers: {
'reqUserId': user?.userId.toString(),
'accept': '*/*'
}
});
async function fetchProfile() {
try {
// First request to get the user ID
const searchResponse = await axios.get(`https://www.boast.social/api/users/search/${params.slug}`, {
headers: {
'reqUserId': user?.userId.toString(),
'accept': '*/*'
}
});

const userId = searchResponse.data[0]?.userId;
if (!userId) {
throw new Error("User ID not found");
const userId = searchResponse.data[0]?.userId;
if (!userId) {
throw new Error("User ID not found");
}

// Second request to get the profile details
const profileResponse = await axios.get(`https://www.boast.social/api/users/profile/${userId}`, {
headers: {
'reqUserId': user?.userId.toString(),
'accept': '*/*'
}
});

// Second request to get the profile details
const profileResponse = await axios.get(`https://www.boast.social/api/users/profile/${userId}`, {
headers: {
'reqUserId': user?.userId.toString(),
'accept': '*/*'
}
});
console.log(profileResponse.data)

const postIds = profileResponse.data.posts;
const postResponses = await Promise.all(postIds.map((postId: number) =>
axios.get(`https://www.boast.social/api/posts/${postId}`)
));
const postIds = profileResponse.data.posts;
const postResponses = await Promise.all(postIds.map((postId: number) =>
axios.get(`https://www.boast.social/api/posts/${postId}`)
));

setPosts(postResponses.map(res => res.data));
setPosts(postResponses.map(res => res.data));

setProfile(profileResponse.data);
} catch (error) {
console.error("Error fetching profile:", error);
} finally {
setLoading(false);
}
setProfile(profileResponse.data);
} catch (error) {
console.error("Error fetching profile:", error);
} finally {
setLoading(false);
}
}

useEffect(() => {
fetchProfile();
}, [user?.userId, params.slug]);

Expand All @@ -62,7 +64,17 @@ export default function Page({params}: { params: { slug: string } }) {
}

const followToggle = () => {
console.log(profile.relationStatus === 'NO_RELATION' ? 'Following user' : 'Unfollowing user');
axios.post(`https://www.boast.social/api/relations/${profile.relationStatus === "NO_RELATION" ? "follow" : "unfollow"}/${profile.userId}`, {}, {
headers: {
'reqUserId': user?.userId.toString(),
'accept': '*/*'
}
}).then(() => {
console.log("User followed/unfollowed successfully");
fetchProfile()
}).catch(error => {
console.error("Error following user:", error);
})
};

return (
Expand Down Expand Up @@ -97,17 +109,21 @@ export default function Page({params}: { params: { slug: string } }) {
· {profile.following} following</Typography>
<Typography variant="body2">{profile.name}</Typography>

<Button
variant="contained"
onClick={followToggle}
sx={{
mt: 2,
bgcolor: profile.relationStatus === 'NO_RELATION' ? "#4ECA31" : "#C20B4E",
":hover": {bgcolor: profile.relationStatus === 'NO_RELATION' ? "#4ECA31" : "#C20B4E"},
}}
>
{profile.relationStatus === 'NO_RELATION' ? "Follow" : "Unfollow"}
</Button>
{
profile.userId !== user?.userId && (
<Button
variant="contained"
onClick={followToggle}
sx={{
mt: 2,
bgcolor: profile.relationStatus === 'NO_RELATION' ? "#4ECA31" : "#C20B4E",
":hover": {bgcolor: profile.relationStatus === 'NO_RELATION' ? "#4ECA31" : "#C20B4E"},
}}
>
{profile.relationStatus === 'NO_RELATION' ? "Follow" : "Unfollow"}
</Button>
)
}
</Grid>
</Grid>

Expand Down
25 changes: 0 additions & 25 deletions logic/frontend/web/src/app/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ export default function Page() {
);
}

const followToggle = () => {
console.log(profile.relationStatus === 'NO_RELATION' ? 'Following user' : 'Unfollowing user');
};

return (
<Box
p={3}
Expand Down Expand Up @@ -90,18 +86,6 @@ export default function Page() {
<Typography variant="body2">{profile.follower} followers
· {profile.following} following</Typography>
<Typography variant="body2">{profile.name}</Typography>

<Button
variant="contained"
onClick={followToggle}
sx={{
mt: 2,
bgcolor: profile.relationStatus === 'NO_RELATION' ? "#4ECA31" : "#C20B4E",
":hover": {bgcolor: profile.relationStatus === 'NO_RELATION' ? "#4ECA31" : "#C20B4E"},
}}
>
{profile.relationStatus === 'NO_RELATION' ? "Follow" : "Unfollow"}
</Button>
</Grid>
</Grid>

Expand Down Expand Up @@ -129,15 +113,6 @@ export default function Page() {
<Typography variant="caption" sx={{color: "#C0C0C0"}}>
{post.createdOn}
</Typography>
<Button
variant="outlined"
sx={{
borderColor: post.status === "ACTIVE" ? "#4ECA31" : "#C20B4E",
color: post.status === "ACTIVE" ? "#4ECA31" : "#C20B4E",
}}
>
{post.status === "ACTIVE" ? "Active" : "Inactive"}
</Button>
</Box>
</CardContent>
</Card>
Expand Down

0 comments on commit 7d4b8d2

Please sign in to comment.