Changeset 1579b4f for frontend/src/pages/SongDetail.tsx
- Timestamp:
- 02/10/26 21:58:39 (5 months ago)
- Branches:
- main
- Children:
- 92db381
- Parents:
- 0808ef2
- File:
-
- 1 edited
-
frontend/src/pages/SongDetail.tsx (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
frontend/src/pages/SongDetail.tsx
r0808ef2 r1579b4f 1 1 import { useEffect, useRef, useState } from "react"; 2 2 import { Link, useParams } from "react-router-dom"; 3 import { toast } from "react-toastify"; 3 4 import axiosInstance from "../api/axiosInstance"; 4 5 import { useAuth } from "../context/authContext"; 5 6 import { usePlayer } from "../context/playerContext"; 6 7 import type { SongDetail as SongDetailType } from "../utils/types"; 8 import { toEmbedUrl } from "../utils/utils"; 7 9 8 10 const ROLE_LABELS: Record<string, string> = { … … 18 20 const formatRole = (role: string): string => { 19 21 return ROLE_LABELS[role] || role.replace(/_/g, " "); 20 };21 22 // convert a regular youtube URL to an embeddable URL23 const toEmbedUrl = (url: string): string => {24 try {25 const parsed = new URL(url);26 // youtube.com/watch?v=ID27 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/ID35 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-is39 return url;40 } catch {41 return url;42 }43 22 }; 44 23 … … 137 116 setSong(response.data); 138 117 } catch (err) { 139 // todo :add toast118 toast.error("Failed to delete review"); 140 119 console.error("Error deleting review:", err); 141 120 } … … 152 131 ); 153 132 } catch (err) { 133 toast.error("Failed to toggle like"); 154 134 console.error("Error toggling like:", err); 155 135 }
Note:
See TracChangeset
for help on using the changeset viewer.
