Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Richmond-Andoh committed Apr 11, 2024
1 parent c8c44cf commit 0df894c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
3 changes: 1 addition & 2 deletions client/src/components/likeProfile/LikeProfile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const LikeProfile = ({ userProfile }) => {

const handleLikes = async () => {
try {
const res = await fetch(`/api/users/likes/${userProfile.login}`, {
const res = await fetch(`/api/users/like/${userProfile.login}`, {
method: "POST",
credentials: "include"
});
Expand All @@ -21,7 +21,6 @@ const LikeProfile = ({ userProfile }) => {
if(data.error) throw new Error(data.error);
toast.success(data.message);

toast.success(data.message);
} catch (error) {
toast.error(error.message);
}
Expand Down
13 changes: 6 additions & 7 deletions client/src/pages/likes/Likes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const Likes = () => {
const getLikes = async () => {
try {
const res = await fetch("api/users/likes", {
method: "POST",
credentials: "include"
});

Expand All @@ -32,7 +31,7 @@ const Likes = () => {
<thead className="text-xs uppercase bg-glass">
<tr>
<th scope="col" className="p-4">
<div className="flex items-center">No</div>
<div className="flex items-center">No:</div>
</th>
<th scope="col" className="px-6 py-2">
Username
Expand All @@ -50,8 +49,8 @@ const Likes = () => {

<tbody>
{
likes.map((like, idx) => (
<tr className='bg-glass border-b' key={like.username}>
likes.map((user, idx) => (
<tr className='bg-glass border-b' key={user.username}>
<td className='w-4 p-4'>
<div className='flex items-center'>
<span>{ idx + 1}</span>
Expand All @@ -60,14 +59,14 @@ const Likes = () => {
<th scope='row' className='flex items-center px-6 py-4 whitespace-nowrap '>
<img
className='w-10 h-10 rounded-full'
src={like.avatarUrl}
src={user.avatarUrl}
alt='User Avatar Image'
/>
<div className='ps-3'>
<div className='text-base font-semibold'>{like.username}</div>
<div className='text-base font-semibold'>{user.username}</div>
</div>
</th>
<td className='px-6 py-4'>{ formatDate(like.likedDate)}</td>
<td className='px-6 py-4'>{ formatDate(user.likedDate)}</td>
<td className='px-6 py-4'>
<div className='flex items-center'>
<FaHeart size={22} className='text-red-500 mx-2' />
Expand Down
4 changes: 2 additions & 2 deletions server/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export const likeProfile = async (req, res) => {
userToLike.likedBy.push({ username: user.username, avatarUrl: user.avatarUrl, likeDate: Date.now()});
user.likedProfiles.push(userToLike.username);

await userToLike.save();
await user.save();
// await userToLike.save();
// await user.save();

await Promise.all([
user.save(),
Expand Down
2 changes: 1 addition & 1 deletion server/routes/userRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const userRoute = express.Router();
// @route GET api/users
userRoute.get("/profile/:username", getUserProfileAndRepos);
userRoute.get("/likes", ensureAuthenticated, getLikes);
userRoute.get("/likes/:username", ensureAuthenticated, likeProfile)
userRoute.get("/like/:username", ensureAuthenticated, likeProfile)


export default userRoute;

0 comments on commit 0df894c

Please sign in to comment.