Skip to content

Commit 8a9db2d

Browse files
committed
Update controllers, models, routes, and frontend components
- Updated backend controllers (`auth.controller.js`, `comments.controller.js`, `playlists.controller.js`, `songs.controller.js`, `users.controller.js`) with new logic and bug fixes. - Modified backend models (`comment.model.js`, `song.model.js`, `user.model.js`) for improved data handling and added new properties. - Updated backend routes (`comments.route.js`, `songs.route.js`, `users.route.js`) to reflect the latest API changes. - Made changes to backend server initialization in `server.js`. - Enhanced helper functions in `helpers.js` to improve utility methods. - Updated package dependencies (`package.json`, `package-lock.json`). - Refactored frontend components for better UI and functionality (`Navbar/RightContent.jsx`, `SingleSongCard.jsx`, `TrackList.jsx`, `UserView/index.jsx`, `LoggedInHomePage.jsx`, `SignUpPage.jsx`, `FeedPage.jsx`, `StorePage.jsx`, `authStore.js`). - Removed unnecessary component `CommentSection.jsx` from `src/pages/feed`. - Added new untracked files for orders and Paypal integration (`order.controller.js`, `order.model.js`, `order.route.js`, `paypal.js`). - Updated `HomeSlider` component and other minor improvements. Changes include various updates for backend APIs, frontend UI components, and improvements to state management and routing.
1 parent ba55cb3 commit 8a9db2d

15 files changed

Lines changed: 843 additions & 277 deletions

File tree

frontend/package-lock.json

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,16 @@
5252
"react-hot-toast": "^2.4.1",
5353
"react-icons": "^5.3.0",
5454
"react-router-dom": "^6.28.0",
55+
"react-slick": "^0.30.2",
5556
"react-toastify": "^10.0.6",
5657
"recharts": "^2.13.3",
5758
"routes": "^2.1.0",
5859
"sass": "^1.80.4",
60+
"slick-carousel": "^1.8.1",
5961
"stripe": "^17.3.1",
6062
"styled-components": "^6.1.13",
6163
"stylis-plugin-rtl": "^2.1.1",
64+
"swiper": "^11.1.15",
6265
"tailwind-merge": "^2.5.4",
6366
"tailwindcss-animate": "^1.0.7",
6467
"ws": "^8.18.0",
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import React, { useState, useEffect } from "react";
2+
import { FaComment, FaPaperPlane } from "react-icons/fa";
3+
import {
4+
makeUnAuthenticatedPOSTRequest,
5+
makeUnAuthenticatedGETRequest,
6+
} from "@/utils/serverHelper";
7+
8+
export default function CommentSection({ trackId, userId }) {
9+
const [comments, setComments] = useState([]);
10+
const [newComment, setNewComment] = useState("");
11+
12+
useEffect(() => {
13+
fetchComments();
14+
}, [trackId]);
15+
16+
const fetchComments = async () => {
17+
try {
18+
const response = await makeUnAuthenticatedGETRequest(
19+
`/song/get/comments/${trackId}`
20+
);
21+
if (response.error) {
22+
console.error("Error fetching comments:", response.error);
23+
return;
24+
}
25+
setComments(response.comments);
26+
} catch (error) {
27+
console.error("Error fetching comments:", error);
28+
}
29+
};
30+
31+
const handleAddComment = async (e) => {
32+
e.preventDefault();
33+
if (!newComment.trim()) return;
34+
35+
try {
36+
const response = await makeUnAuthenticatedPOSTRequest(
37+
"/song/post/comment",
38+
{
39+
trackId,
40+
userId,
41+
text: newComment,
42+
}
43+
);
44+
45+
if (response.error) {
46+
console.error("Error adding comment:", response.error);
47+
return;
48+
}
49+
50+
setComments((prevComments) => [response.comment, ...prevComments]);
51+
setNewComment("");
52+
} catch (error) {
53+
console.error("Error adding comment:", error);
54+
}
55+
};
56+
57+
return (
58+
<div className="mt-6">
59+
<h3 className="text-lg font-semibold mb-4">Comments</h3>
60+
<div className="space-y-4 mb-4">
61+
{comments.map((comment) => (
62+
<div key={comment._id} className="bg-gray-100 rounded-lg p-3">
63+
<p className="font-semibold">{comment.user.username}</p>
64+
<p>{comment.text}</p>
65+
<p className="text-xs text-gray-500 mt-1">
66+
{new Date(comment.createdAt).toLocaleString()}
67+
</p>
68+
</div>
69+
))}
70+
</div>
71+
<form onSubmit={handleAddComment} className="flex items-center">
72+
<input
73+
type="text"
74+
value={newComment}
75+
onChange={(e) => setNewComment(e.target.value)}
76+
placeholder="Add a comment..."
77+
className="flex-grow border rounded-l-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-orange-500"
78+
/>
79+
<button
80+
type="submit"
81+
className="bg-orange-500 text-white rounded-r-lg px-4 py-2 hover:bg-orange-600 focus:outline-none focus:ring-2 focus:ring-orange-500"
82+
>
83+
<FaPaperPlane />
84+
</button>
85+
</form>
86+
</div>
87+
);
88+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const Card = ({ title, description, imgUrl, onClick }) => {
2+
return (
3+
<div
4+
className="bg-black bg-opacity-40 p-4 rounded-lg cursor-pointer transform w-60 transition duration-300 ease-in-out hover:scale-105 hover:shadow-xl"
5+
onClick={onClick} // Thêm sự kiện onClick để gọi hàm phát nhạc
6+
>
7+
<div className="pb-4 pt-2 relative">
8+
<img
9+
className="w-full h-60 object-cover rounded-md"
10+
src={imgUrl}
11+
alt={title}
12+
/>
13+
</div>
14+
<div className="text-white font-semibold py-3 text-xl hover:underline">
15+
{title}
16+
</div>
17+
<div className="text-gray-300 text-sm hover:underline">{description}</div>
18+
</div>
19+
);
20+
};
21+
22+
export default Card;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import React from "react";
2+
import Slider from "react-slick";
3+
import "slick-carousel/slick/slick.css";
4+
import "slick-carousel/slick/slick-theme.css";
5+
6+
const HomeSlider = () => {
7+
const settings = {
8+
dots: true,
9+
infinite: true,
10+
speed: 500,
11+
slidesToShow: 1,
12+
slidesToScroll: 1,
13+
autoplay: true,
14+
autoplaySpeed: 3000,
15+
};
16+
17+
const slides = [
18+
{
19+
id: 1,
20+
image:
21+
"https://ss-images.saostar.vn/2018/08/31/3582800/ava-usuk-ngang-copy.jpg",
22+
alt: "Slide 1",
23+
},
24+
{
25+
id: 2,
26+
image:
27+
"https://www.shutterstock.com/shutterstock/videos/3438942789/thumb/1.jpg?ip=x480",
28+
alt: "Slide 2",
29+
},
30+
{
31+
id: 3,
32+
image:
33+
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRhaO4J3W42OsDi5jhvpfdqF8RGvWkvoUdXbA&s",
34+
alt: "Slide 3",
35+
},
36+
];
37+
38+
return (
39+
<div className="w-full max-w-4xl mx-auto mb-8">
40+
<Slider {...settings}>
41+
{slides.map((slide) => (
42+
<div key={slide.id} className="outline-none">
43+
<img
44+
src={slide.image}
45+
alt={slide.alt}
46+
className="w-full h-auto object-cover rounded-lg"
47+
/>
48+
</div>
49+
))}
50+
</Slider>
51+
</div>
52+
);
53+
};
54+
55+
export default HomeSlider;

0 commit comments

Comments
 (0)