Ignore:
Timestamp:
02/10/26 21:58:39 (5 months ago)
Author:
Filip Gavrilovski <filipgavrilovski28@…>
Branches:
main
Children:
92db381
Parents:
0808ef2
Message:

refactor artist, collection, listener components to have similar style as other components; refactor some dto-s

File:
1 edited

Legend:

Unmodified
Added
Removed
  • frontend/src/pages/SongDetail.tsx

    r0808ef2 r1579b4f  
    11import { useEffect, useRef, useState } from "react";
    22import { Link, useParams } from "react-router-dom";
     3import { toast } from "react-toastify";
    34import axiosInstance from "../api/axiosInstance";
    45import { useAuth } from "../context/authContext";
    56import { usePlayer } from "../context/playerContext";
    67import type { SongDetail as SongDetailType } from "../utils/types";
     8import { toEmbedUrl } from "../utils/utils";
    79
    810const ROLE_LABELS: Record<string, string> = {
     
    1820const formatRole = (role: string): string => {
    1921        return ROLE_LABELS[role] || role.replace(/_/g, " ");
    20 };
    21 
    22 // convert a regular youtube URL to an embeddable URL
    23 const toEmbedUrl = (url: string): string => {
    24         try {
    25                 const parsed = new URL(url);
    26                 // youtube.com/watch?v=ID
    27                 if (
    28                         (parsed.hostname === "www.youtube.com" ||
    29                                 parsed.hostname === "youtube.com") &&
    30                         parsed.searchParams.has("v")
    31                 ) {
    32                         return `https://www.youtube.com/embed/${parsed.searchParams.get("v")}`;
    33                 }
    34                 // youtu.be/ID
    35                 if (parsed.hostname === "youtu.be") {
    36                         return `https://www.youtube.com/embed${parsed.pathname}`;
    37                 }
    38                 // already an embed URL or other provider – return as-is
    39                 return url;
    40         } catch {
    41                 return url;
    42         }
    4322};
    4423
     
    137116                        setSong(response.data);
    138117                } catch (err) {
    139                         // todo :add toast
     118                        toast.error("Failed to delete review");
    140119                        console.error("Error deleting review:", err);
    141120                }
     
    152131                        );
    153132                } catch (err) {
     133                        toast.error("Failed to toggle like");
    154134                        console.error("Error toggling like:", err);
    155135                }
Note: See TracChangeset for help on using the changeset viewer.