main
|
Last change
on this file since 1579b4f was 1579b4f, checked in by Filip Gavrilovski <filipgavrilovski28@…>, 5 months ago |
|
refactor artist, collection, listener components to have similar style as other components; refactor some dto-s
|
-
Property mode
set to
100644
|
|
File size:
737 bytes
|
| Line | |
|---|
| 1 | import axiosInstance from "../../api/axiosInstance";
|
|---|
| 2 | import type { Song } from "../../utils/types";
|
|---|
| 3 | import SongItem from "../SongItem";
|
|---|
| 4 |
|
|---|
| 5 | interface SongResultProps {
|
|---|
| 6 | song: Song;
|
|---|
| 7 | /** Propagate like state change upward if needed */
|
|---|
| 8 | onLikeToggled?: (songId: number, isLiked: boolean) => void;
|
|---|
| 9 | }
|
|---|
| 10 |
|
|---|
| 11 | const SongResult = ({ song, onLikeToggled }: SongResultProps) => {
|
|---|
| 12 | const handleLike = async (songId: number) => {
|
|---|
| 13 | try {
|
|---|
| 14 | const response = await axiosInstance.post(
|
|---|
| 15 | `/musical-entity/${songId}/like`,
|
|---|
| 16 | );
|
|---|
| 17 | onLikeToggled?.(songId, response.data.isLiked);
|
|---|
| 18 | } catch (err) {
|
|---|
| 19 | console.error("Error toggling like:", err);
|
|---|
| 20 | }
|
|---|
| 21 | };
|
|---|
| 22 |
|
|---|
| 23 | return <SongItem song={song} label="Song" onLikeToggle={handleLike} />;
|
|---|
| 24 | };
|
|---|
| 25 |
|
|---|
| 26 | export default SongResult;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.