From 873bf64a4e2baa6ccec32be3c47033405ef26946 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 2 Aug 2025 02:00:11 +0200 Subject: [PATCH 01/13] search bar, design update --- frontend/src/index.css | 1757 ++++++++++++++---------- frontend/src/screens/AddSongModal.jsx | 136 +- frontend/src/screens/CreateStation.jsx | 110 +- frontend/src/screens/Home.jsx | 64 +- frontend/src/screens/JoinStation.jsx | 110 +- frontend/src/screens/StationPage.jsx | 147 +- frontend/src/utils/spotifyAuth.js | 36 + 7 files changed, 1438 insertions(+), 922 deletions(-) diff --git a/frontend/src/index.css b/frontend/src/index.css index 673a327..fa303ed 100644 --- a/frontend/src/index.css +++ b/frontend/src/index.css @@ -5,590 +5,794 @@ } body { - font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', - 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', - sans-serif; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; - background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); - min-height: 100vh; - color: #333; -} - -/* Home Component Styles */ -.home-container { - min-height: 100vh; - display: flex; - align-items: center; - justify-content: center; - padding: 20px; -} - -.content { - background: rgba(255, 255, 255, 0.95); - backdrop-filter: blur(10px); - border-radius: 24px; - padding: 40px 30px; - text-align: center; - box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1); - border: 1px solid rgba(255, 255, 255, 0.2); - max-width: 500px; - width: 100%; -} - -.title { - font-size: 2.5rem; - font-weight: 700; - background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); - -webkit-background-clip: text; - -webkit-text-fill-color: transparent; - background-clip: text; - margin-bottom: 12px; - line-height: 1.2; -} - -.subtitle { - font-size: 1.1rem; - color: #666; - margin-bottom: 40px; - line-height: 1.5; -} - -.button-container { - display: flex; - flex-direction: column; - gap: 16px; -} - -.action-button { - padding: 16px 32px; - border: none; - border-radius: 12px; - font-size: 1.1rem; - font-weight: 600; - cursor: pointer; - transition: all 0.3s ease; - text-decoration: none; - display: inline-block; - position: relative; - overflow: hidden; -} - -.action-button.primary { - background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); + font-family: 'Arial', sans-serif; + background: #1a1a1a; color: white; - box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3); -} - -.action-button.primary:hover { - transform: translateY(-2px); - box-shadow: 0 12px 35px rgba(102, 126, 234, 0.4); -} - -.action-button.secondary { - background: white; - color: #667eea; - border: 2px solid #667eea; -} - -.action-button.secondary:hover { - background: #667eea; - color: white; - transform: translateY(-2px); - box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3); -} - -/* Create Station Component Styles */ -.create-station { - min-height: 100vh; - padding: 20px; - display: flex; - flex-direction: column; - background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); -} - -.create-station-header { - text-align: center; - margin-bottom: 40px; - padding-top: 40px; -} - -.create-station-header h1 { - font-size: 2.2rem; - font-weight: 700; - color: white; - margin-bottom: 20px; - text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); -} - -.create-station-content { - flex: 1; - max-width: 600px; - margin: 0 auto; - width: 100%; - background: rgba(255, 255, 255, 0.95); - backdrop-filter: blur(10px); - border-radius: 24px; - padding: 40px 30px; - box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1); - border: 1px solid rgba(255, 255, 255, 0.2); -} - -.join-method-section h2 { - font-size: 1.4rem; - font-weight: 600; - color: #333; - margin-bottom: 30px; - line-height: 1.4; -} - -.radio-option { - margin-bottom: 24px; -} - -.radio-option label { - display: flex; - align-items: center; - font-size: 1.1rem; - font-weight: 500; - cursor: pointer; - padding: 16px 20px; - border: 2px solid #e9ecef; - border-radius: 12px; - transition: all 0.3s ease; - background: white; -} - -.radio-option label:hover { - border-color: #667eea; - background: #f8f9ff; -} - -.radio-option input[type="radio"]:checked + label, -.radio-option label:has(input[type="radio"]:checked) { - border-color: #667eea; - background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%); - color: #667eea; -} - -.radio-option input[type="radio"] { - margin-right: 12px; - transform: scale(1.3); - accent-color: #667eea; -} - -.password-input-section { - margin-top: 30px; - animation: slideIn 0.3s ease; -} - -@keyframes slideIn { - from { - opacity: 0; - transform: translateY(-10px); - } - to { - opacity: 1; - transform: translateY(0); - } -} - -.password-input-section label { - display: block; - font-size: 1rem; - font-weight: 600; - color: #333; - margin-bottom: 12px; -} - -.password-input-section input { - width: 100%; - padding: 16px 20px; - border: 2px solid #e9ecef; - border-radius: 12px; - font-size: 1rem; - transition: all 0.3s ease; - background: white; -} - -.password-input-section input:focus { - outline: none; - border-color: #667eea; - box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1); -} - -.create-station-final-btn { - width: 100%; - background: linear-gradient(135deg, #28a745 0%, #20c997 100%); - color: white; - border: none; - padding: 18px 32px; - font-size: 1.1rem; - font-weight: 600; - border-radius: 12px; - cursor: pointer; - margin-top: 40px; - transition: all 0.3s ease; - box-shadow: 0 8px 25px rgba(40, 167, 69, 0.3); -} - -.create-station-final-btn:hover:not(:disabled) { - transform: translateY(-2px); - box-shadow: 0 12px 35px rgba(40, 167, 69, 0.4); -} - -.create-station-final-btn:disabled { - background: #ccc; - cursor: not-allowed; - transform: none; - box-shadow: none; -} - -/* Join Station Component Styles */ -.join-station { - min-height: 100vh; - padding: 20px; - display: flex; - flex-direction: column; - background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); -} - -.join-station-header { - text-align: center; - margin-bottom: 40px; - padding-top: 40px; -} - -.join-station-header h1 { - font-size: 2.2rem; - font-weight: 700; - color: white; - margin-bottom: 20px; - text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); -} - -.join-station-content { - flex: 1; - max-width: 600px; - margin: 0 auto; - width: 100%; - background: rgba(255, 255, 255, 0.95); - backdrop-filter: blur(10px); - border-radius: 24px; - padding: 40px 30px; - box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1); - border: 1px solid rgba(255, 255, 255, 0.2); -} - -.verify-method-section h2 { - font-size: 1.4rem; - font-weight: 600; - color: #333; - margin-bottom: 30px; - line-height: 1.4; -} - -.join-station-final-btn { - width: 100%; - background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); - color: white; - border: none; - padding: 18px 32px; - font-size: 1.1rem; - font-weight: 600; - border-radius: 12px; - cursor: pointer; - margin-top: 40px; - transition: all 0.3s ease; - box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3); -} - -.join-station-final-btn:hover:not(:disabled) { - transform: translateY(-2px); - box-shadow: 0 12px 35px rgba(102, 126, 234, 0.4); -} - -.join-station-final-btn:disabled { - background: #ccc; - cursor: not-allowed; - transform: none; - box-shadow: none; -} - -/* Station Page Styles */ -.station-page { - min-height: 100vh; - background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); - position: relative; overflow-x: hidden; } -.animated-background { - position: fixed; +.station-page-desktop { + min-height: 100vh; + position: relative; + display: flex; + flex-direction: column; +} + +/* Main Layout */ +.desktop-main { + display: flex; + flex: 1; + padding: 40px 40px 0 40px; + gap: 60px; + max-width: 1400px; + margin: 0 auto; + width: 100%; + height: calc(100vh - 80px); /* Account for progress bar */ + position: relative; +} + +/* Left Section */ +.left-section { + flex: 0 0 400px; /* Fixed width instead of flex: 1 */ + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + max-width: 400px; +} + +/* Vinyl Container */ +.vinyl-container { + position: relative; + margin-bottom: 40px; +} + +.vinyl-record-desktop { + width: 300px; + height: 300px; + background: radial-gradient(circle, #1a1a1a 30%, #333 31%, #1a1a1a 32%, #333 33%, #1a1a1a 34%); + border-radius: 50%; + position: relative; + box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5); + transition: transform 0.3s ease; +} + +.vinyl-record-desktop.spinning { + animation: spin 3s linear infinite; +} + +@keyframes spin { + from { transform: rotate(0deg); } + to { transform: rotate(360deg); } +} + +.vinyl-center { + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + width: 60px; + height: 60px; + background: #8B4513; + border-radius: 50%; + box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.5); +} + +.vinyl-center::after { + content: ''; + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + width: 10px; + height: 10px; + background: #000; + border-radius: 50%; +} + +.vinyl-grooves { + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + width: 200px; + height: 200px; + border-radius: 50%; + border: 2px solid transparent; /* Changed from rgba(255, 255, 255, 0.1) to transparent */ +} + +.vinyl-grooves::before { + content: ''; + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + border-radius: 50%; + border: 1px solid transparent; /* Changed from rgba(255, 255, 255, 0.1) to transparent */ + width: 160px; + height: 160px; +} + +.vinyl-grooves::after { + content: ''; + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + border-radius: 50%; + border: 1px solid rgba(255, 255, 255, 0.1); + width: 240px; + height: 240px; +} + +/* Music Notes Animation */ +.music-notes-desktop { + position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; - z-index: 1; } -.star { +.music-note { position: absolute; - background: rgba(255, 255, 255, 0.6); - border-radius: 50%; - animation: float 6s ease-in-out infinite; + font-size: 24px; + color: #4A90E2; + animation: float 3s ease-in-out infinite; } -.star:nth-child(odd) { - width: 2px; - height: 2px; - animation-duration: 8s; +.note-1 { + top: 20%; + right: -40px; + animation-delay: 0s; } -.star:nth-child(even) { - width: 3px; - height: 3px; - animation-duration: 6s; +.note-2 { + top: 50%; + right: -60px; + animation-delay: 1s; } -.star:nth-child(3n) { - width: 1px; - height: 1px; - animation-duration: 10s; +.note-3 { + top: 80%; + right: -40px; + animation-delay: 2s; } -.star-1 { top: 10%; left: 20%; animation-delay: 0s; } -.star-2 { top: 20%; left: 80%; animation-delay: 1s; } -.star-3 { top: 30%; left: 40%; animation-delay: 2s; } -.star-4 { top: 40%; left: 10%; animation-delay: 1.5s; } -.star-5 { top: 50%; left: 70%; animation-delay: 3s; } -.star-6 { top: 60%; left: 30%; animation-delay: 0.5s; } -.star-7 { top: 70%; left: 90%; animation-delay: 2.5s; } -.star-8 { top: 80%; left: 50%; animation-delay: 1.8s; } -.star-9 { top: 15%; left: 60%; animation-delay: 2.2s; } -.star-10 { top: 25%; left: 15%; animation-delay: 3.5s; } -.star-11 { top: 35%; left: 85%; animation-delay: 0.8s; } -.star-12 { top: 45%; left: 25%; animation-delay: 4s; } -.star-13 { top: 55%; left: 75%; animation-delay: 1.2s; } -.star-14 { top: 65%; left: 5%; animation-delay: 2.8s; } -.star-15 { top: 75%; left: 95%; animation-delay: 0.3s; } -.star-16 { top: 85%; left: 35%; animation-delay: 3.2s; } -.star-17 { top: 5%; left: 45%; animation-delay: 1.7s; } -.star-18 { top: 95%; left: 65%; animation-delay: 2.1s; } -.star-19 { top: 12%; left: 2%; animation-delay: 3.8s; } -.star-20 { top: 88%; left: 98%; animation-delay: 0.9s; } - @keyframes float { - 0%, 100% { - transform: translateY(0px) translateX(0px); - opacity: 0.6; - } - 50% { - transform: translateY(-10px) translateX(5px); - opacity: 1; - } + 0%, 100% { transform: translateY(0) rotate(0deg); opacity: 0; } + 50% { transform: translateY(-30px) rotate(15deg); opacity: 1; } } -.station-content { - position: relative; - z-index: 2; +/* Next Song Info */ +.next-song-info { + text-align: center; + background: rgba(255, 255, 255, 0.05); padding: 20px; - max-width: 800px; - margin: 0 auto; -} - -.station-header { - text-align: center; - margin-bottom: 40px; - padding-top: 40px; -} - -.station-header h1 { - font-size: 2.5rem; - font-weight: 700; - color: white; - margin-bottom: 10px; - text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); -} - -.station-subtitle { - font-size: 1.1rem; - color: rgba(255, 255, 255, 0.9); - margin: 0; -} - -.media-controls-section { - background: rgba(255, 255, 255, 0.95); - backdrop-filter: blur(10px); - border-radius: 20px; - padding: 30px; + border-radius: 15px; margin-bottom: 30px; - box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1); - border: 1px solid rgba(255, 255, 255, 0.2); + width: 100%; + max-width: 300px; } -.current-song { - text-align: center; - margin-bottom: 25px; +.next-label { + font-size: 14px; + color: #aaa; + margin-bottom: 8px; + text-transform: uppercase; + letter-spacing: 1px; } -.current-song h3 { - font-size: 1.4rem; - font-weight: 600; - color: #333; +.next-song-info h4 { + font-size: 18px; margin-bottom: 5px; + color: #4A90E2; } -.current-song p { - font-size: 1rem; - color: #666; - margin: 0; +.next-artist { + font-size: 14px; + color: #ccc; } -.media-controls { +/* Bottom Play Icon */ +.bottom-play-icon { display: flex; justify-content: center; - align-items: center; - gap: 20px; } -.control-btn { - background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); - border: none; - border-radius: 50%; - width: 50px; - height: 50px; - display: flex; - align-items: center; - justify-content: center; - cursor: pointer; - transition: all 0.3s ease; - color: white; - box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3); -} - -.control-btn.play-pause { +.mini-play-btn { width: 60px; height: 60px; - box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4); + border: none; + border-radius: 50%; + background: linear-gradient(135deg, #4A90E2, #6BB6FF); + color: #fff; + cursor: pointer; + display: flex; + align-items: center; + justify-content: center; + transition: all 0.3s ease; + box-shadow: 0 10px 20px rgba(74, 144, 226, 0.3); } -.control-btn:hover { - transform: translateY(-2px); - box-shadow: 0 8px 25px rgba(102, 126, 234, 0.5); +.mini-play-btn:hover { + transform: scale(1.1); + box-shadow: 0 15px 30px rgba(74, 144, 226, 0.4); } -.songs-section { - background: rgba(255, 255, 255, 0.95); +/* Right Section */ +.right-section { + position: absolute; + left: 50%; + top: 20px; /* Add top margin */ + right: 20px; /* Reduced from 40px */ + bottom: 20px; /* Add bottom margin */ + display: flex; + flex-direction: column; +} + +.recommendations-container { + background: linear-gradient(135deg, #2a2a2a 0%, #1a1a1a 50%, #0a0a0a 100%); backdrop-filter: blur(10px); border-radius: 20px; padding: 30px; - box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1); - border: 1px solid rgba(255, 255, 255, 0.2); + height: 100%; /* Take full height of parent */ + display: flex; + flex-direction: column; } -.section-header { +.recommendations-header { display: flex; justify-content: space-between; align-items: center; - margin-bottom: 25px; + margin-bottom: 30px; + border-bottom: 2px solid rgba(74, 144, 226, 0.3); + padding-bottom: 15px; } -.section-header h2 { - font-size: 1.5rem; - font-weight: 600; - color: #333; - margin: 0; +.recommendations-header h2 { + font-size: 28px; + color: #4A90E2; + font-weight: bold; } -.add-song-btn { - background: linear-gradient(135deg, #28a745 0%, #20c997 100%); - color: white; +.add-suggestion-btn { + width: 50px; + height: 50px; border: none; - padding: 12px 20px; - border-radius: 10px; - font-size: 0.9rem; - font-weight: 600; + border-radius: 50%; + background: linear-gradient(135deg, #4A90E2, #6BB6FF); + color: #fff; cursor: pointer; - transition: all 0.3s ease; - box-shadow: 0 4px 15px rgba(40, 167, 69, 0.3); -} - -.add-song-btn:hover { - transform: translateY(-2px); - box-shadow: 0 6px 20px rgba(40, 167, 69, 0.4); -} - -.songs-list { - max-height: 400px; - overflow-y: auto; - margin: -5px; - padding: 5px; -} - -.songs-list::-webkit-scrollbar { - width: 6px; -} - -.songs-list::-webkit-scrollbar-track { - background: #f1f1f1; - border-radius: 3px; -} - -.songs-list::-webkit-scrollbar-thumb { - background: #c1c1c1; - border-radius: 3px; -} - -.songs-list::-webkit-scrollbar-thumb:hover { - background: #a8a8a8; -} - -.song-item { display: flex; - justify-content: space-between; align-items: center; - padding: 15px 20px; - border-radius: 12px; - margin-bottom: 8px; + justify-content: center; transition: all 0.3s ease; - cursor: pointer; - border: 2px solid transparent; + box-shadow: 0 5px 15px rgba(74, 144, 226, 0.3); } -.song-item:hover { - background: rgba(102, 126, 234, 0.05); - border-color: rgba(102, 126, 234, 0.2); +.add-suggestion-btn:hover { + transform: scale(1.1); + box-shadow: 0 8px 20px rgba(74, 144, 226, 0.4); +} + +.recommendations-list { + display: flex; + flex-direction: column; + gap: 15px; + flex: 1; /* Take remaining space */ + overflow-y: auto; +} + +.recommendations-list::-webkit-scrollbar { + width: 8px; +} + +.recommendations-list::-webkit-scrollbar-track { + background: rgba(255, 255, 255, 0.1); + border-radius: 10px; +} + +.recommendations-list::-webkit-scrollbar-thumb { + background: #4A90E2; + border-radius: 10px; +} + +.recommendation-item { + display: flex; + align-items: center; + padding: 15px; + background: rgba(255, 255, 255, 0.05); + border-radius: 12px; + border: 1px solid rgba(255, 255, 255, 0.1); + transition: all 0.3s ease; + cursor: pointer; +} + +.recommendation-item:hover { + background: rgba(255, 255, 255, 0.1); + transform: translateY(-2px); + box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2); +} + +.song-cover { + width: 60px; + height: 60px; + border-radius: 8px; + margin-right: 15px; + object-fit: cover; +} + +.song-info { + flex: 1; } .song-info h4 { - font-size: 1rem; - font-weight: 600; - color: #333; - margin: 0 0 4px 0; + font-size: 16px; + margin-bottom: 5px; + color: white; } -.song-info p { - font-size: 0.9rem; - color: #666; - margin: 0; +.artist { + font-size: 14px; + color: #4A90E2; + margin-bottom: 3px; } -.song-duration { - font-size: 0.9rem; - color: #888; - font-weight: 500; +.album { + font-size: 12px; + color: #aaa; } -/* Modal Styles */ -.modal-backdrop { - position: fixed; +.duration { + font-size: 14px; + color: #ccc; + font-weight: bold; +} + +/* Progress Container */ +.progress-container { + padding: 20px 40px; + background: rgba(0, 0, 0, 0.3); + backdrop-filter: blur(10px); + position: relative; + z-index: 10; +} + +.progress-bar { + width: 100%; + height: 8px; + background: rgba(255, 255, 255, 0.2); + border-radius: 4px; + overflow: hidden; + position: relative; +} + +.progress-fill { + height: 100%; + background: linear-gradient(90deg, #4A90E2, #6BB6FF); + border-radius: 4px; + transition: width 0.3s ease; + box-shadow: 0 0 10px rgba(74, 144, 226, 0.5); +} + +/* Home Page Styles */ +.home-container { + min-height: 100vh; + position: relative; + display: flex; + flex-direction: column; + background: #1a1a1a; +} + +.home-main { + display: flex; + flex: 1; + padding: 40px; + gap: 60px; + max-width: 1400px; + margin: 0 auto; + width: 100%; + height: 100vh; + align-items: center; +} + +/* Home Left Section */ +.home-left-section { + flex: 1; + display: flex; + align-items: center; + justify-content: center; +} + +.home-vinyl-container { + position: relative; +} + +.home-vinyl-record { + width: 250px; + height: 250px; + background: radial-gradient(circle, #1a1a1a 30%, #333 31%, #1a1a1a 32%, #333 33%, #1a1a1a 34%); + border-radius: 50%; + position: relative; + box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5); + animation: spin 8s linear infinite; +} + +.home-music-notes { + position: absolute; top: 0; left: 0; width: 100%; height: 100%; - background: rgba(0, 0, 0, 0.5); + pointer-events: none; +} + +.home-music-notes .music-note { + position: absolute; + font-size: 20px; + color: #4A90E2; + animation: float 4s ease-in-out infinite; +} + +.home-music-notes .note-1 { + top: 20%; + right: -30px; + animation-delay: 0s; +} + +.home-music-notes .note-2 { + top: 50%; + right: -50px; + animation-delay: 1.5s; +} + +.home-music-notes .note-3 { + top: 80%; + right: -30px; + animation-delay: 3s; +} + +/* Home Right Section */ +.home-right-section { + flex: 1; + display: flex; + align-items: center; + justify-content: center; +} + +.home-content { + text-align: center; + max-width: 500px; + background: linear-gradient(135deg, #2a2a2a 0%, #1a1a1a 50%, #0a0a0a 100%); + backdrop-filter: blur(10px); + border-radius: 20px; + padding: 50px 40px; + border: 1px solid rgba(255, 255, 255, 0.1); +} + +.home-title { + font-size: 48px; + font-weight: bold; + color: #4A90E2; + margin-bottom: 20px; + text-shadow: 0 2px 10px rgba(74, 144, 226, 0.3); +} + +.home-subtitle { + font-size: 18px; + color: #ccc; + margin-bottom: 40px; + line-height: 1.6; +} + +.home-button-container { + display: flex; + flex-direction: column; + gap: 20px; +} + +.home-action-button { + display: flex; + align-items: center; + justify-content: center; + gap: 12px; + padding: 18px 30px; + font-size: 16px; + font-weight: bold; + border: none; + border-radius: 12px; + cursor: pointer; + transition: all 0.3s ease; + text-transform: uppercase; + letter-spacing: 1px; + min-height: 60px; +} + +.home-action-button.primary { + background: linear-gradient(135deg, #4A90E2, #6BB6FF); + color: white; + box-shadow: 0 10px 20px rgba(74, 144, 226, 0.3); +} + +.home-action-button.primary:hover { + transform: translateY(-3px); + box-shadow: 0 15px 30px rgba(74, 144, 226, 0.4); +} + +.home-action-button.secondary { + background: transparent; + color: #4A90E2; + border: 2px solid #4A90E2; + box-shadow: 0 5px 15px rgba(74, 144, 226, 0.2); +} + +.home-action-button.secondary:hover { + background: rgba(74, 144, 226, 0.1); + transform: translateY(-3px); + box-shadow: 0 10px 25px rgba(74, 144, 226, 0.3); +} + +/* Create Station Styles */ +.create-station-container { + min-height: 100vh; + position: relative; + display: flex; + flex-direction: column; + background: #1a1a1a; +} + +.create-station-main { + display: flex; + flex: 1; + padding: 40px; + gap: 60px; + max-width: 1400px; + margin: 0 auto; + width: 100%; + height: 100vh; + align-items: center; +} + +/* Create Station Left Section */ +.create-station-left-section { + flex: 1; + display: flex; + align-items: center; + justify-content: center; +} + +.create-station-vinyl-container { + position: relative; +} + +.create-station-vinyl-record { + width: 280px; + height: 280px; + background: radial-gradient(circle, #1a1a1a 30%, #333 31%, #1a1a1a 32%, #333 33%, #1a1a1a 34%); + border-radius: 50%; + position: relative; + box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5); + animation: spin 6s linear infinite; +} + +.create-station-music-notes { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + pointer-events: none; +} + +.create-station-music-notes .music-note { + position: absolute; + font-size: 24px; + color: #4A90E2; + animation: float 3s ease-in-out infinite; +} + +.create-station-music-notes .note-1 { + top: 20%; + right: -40px; + animation-delay: 0s; +} + +.create-station-music-notes .note-2 { + top: 50%; + right: -60px; + animation-delay: 1s; +} + +.create-station-music-notes .note-3 { + top: 80%; + right: -40px; + animation-delay: 2s; +} + +/* Create Station Right Section */ +.create-station-right-section { + flex: 1; + display: flex; + align-items: center; + justify-content: center; +} + +.create-station-content { + width: 100%; + max-width: 500px; + background: linear-gradient(135deg, #2a2a2a 0%, #1a1a1a 50%, #0a0a0a 100%); + backdrop-filter: blur(10px); + border-radius: 20px; + padding: 40px; + border: 1px solid rgba(255, 255, 255, 0.1); + box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3); +} + +.create-station-header { + text-align: center; + margin-bottom: 40px; +} + +.create-station-header h1 { + font-size: 32px; + font-weight: bold; + color: #4A90E2; + margin-bottom: 10px; + text-shadow: 0 2px 10px rgba(74, 144, 226, 0.3); +} + +.create-station-form { + display: flex; + flex-direction: column; + gap: 30px; +} + +.join-method-section h2 { + font-size: 18px; + color: #fff; + margin-bottom: 20px; + font-weight: 600; +} + +.radio-option { + margin-bottom: 20px; +} + +.radio-option label { + display: flex; + align-items: center; + gap: 12px; + cursor: pointer; + padding: 15px 20px; + background: rgba(255, 255, 255, 0.05); + border: 2px solid rgba(255, 255, 255, 0.1); + border-radius: 12px; + transition: all 0.3s ease; + font-size: 16px; + font-weight: 500; + color: #fff; +} + +.radio-option label:hover { + background: rgba(255, 255, 255, 0.1); + border-color: rgba(74, 144, 226, 0.5); +} + +.radio-option input[type="radio"] { + display: none; +} + +.radio-custom { + width: 20px; + height: 20px; + border: 2px solid #4A90E2; + border-radius: 50%; + position: relative; + transition: all 0.3s ease; +} + +.radio-option input[type="radio"]:checked + .radio-custom { + background: #4A90E2; + box-shadow: 0 0 10px rgba(74, 144, 226, 0.5); +} + +.radio-option input[type="radio"]:checked + .radio-custom::after { + content: ''; + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + width: 8px; + height: 8px; + background: white; + border-radius: 50%; +} + +.password-input-section { + display: flex; + flex-direction: column; + gap: 10px; + margin-top: 20px; + padding: 20px; + background: rgba(255, 255, 255, 0.03); + border-radius: 12px; + border: 1px solid rgba(255, 255, 255, 0.1); +} + +.password-input-section label { + font-size: 14px; + font-weight: 600; + color: #4A90E2; + text-transform: uppercase; + letter-spacing: 1px; +} + +.password-input-section input { + padding: 15px 20px; + background: rgba(255, 255, 255, 0.05); + border: 2px solid rgba(255, 255, 255, 0.1); + border-radius: 10px; + color: #fff; + font-size: 16px; + transition: all 0.3s ease; +} + +.password-input-section input:focus { + outline: none; + border-color: #4A90E2; + background: rgba(255, 255, 255, 0.1); + box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1); +} + +.password-input-section input::placeholder { + color: #aaa; +} + +.create-station-final-btn { + display: flex; + align-items: center; + justify-content: center; + gap: 12px; + padding: 18px 30px; + font-size: 16px; + font-weight: bold; + border: none; + border-radius: 12px; + cursor: pointer; + transition: all 0.3s ease; + text-transform: uppercase; + letter-spacing: 1px; + min-height: 60px; + background: linear-gradient(135deg, #4A90E2, #6BB6FF); + color: white; + box-shadow: 0 10px 20px rgba(74, 144, 226, 0.3); + margin-top: 20px; +} + +.create-station-final-btn:hover:not(:disabled) { + transform: translateY(-3px); + box-shadow: 0 15px 30px rgba(74, 144, 226, 0.4); +} + +.create-station-final-btn:disabled { + background: rgba(255, 255, 255, 0.1); + color: #666; + cursor: not-allowed; + box-shadow: none; + transform: none; +} + +/* Add Song Modal Styles */ +.add-song-modal-backdrop { + position: fixed; + top: 0; + left: 0; + right: 0; + bottom: 0; + background: rgba(0, 0, 0, 0.8); + backdrop-filter: blur(8px); display: flex; align-items: center; justify-content: center; @@ -596,312 +800,371 @@ body { padding: 20px; } -.modal-content { - background: white; +.add-song-modal-content { + background: linear-gradient(135deg, #2a2a2a 0%, #1a1a1a 50%, #0a0a0a 100%); border-radius: 20px; width: 100%; - max-width: 500px; + max-width: 600px; max-height: 80vh; - overflow-y: auto; - box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2); + border: 1px solid rgba(255, 255, 255, 0.1); + box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5); + display: flex; + flex-direction: column; + overflow: hidden; } -.modal-header { +.add-song-modal-header { display: flex; justify-content: space-between; align-items: center; - padding: 25px 30px 20px; - border-bottom: 1px solid #eee; + padding: 25px 30px; + border-bottom: 2px solid rgba(74, 144, 226, 0.3); + background: rgba(255, 255, 255, 0.02); } -.modal-header h2 { - font-size: 1.4rem; - font-weight: 600; - color: #333; +.add-song-modal-header h2 { + font-size: 24px; + color: #4A90E2; + font-weight: bold; margin: 0; } -.close-btn { - background: none; +.add-song-close-btn { + width: 40px; + height: 40px; border: none; - cursor: pointer; - padding: 5px; border-radius: 50%; - color: #666; + background: rgba(255, 255, 255, 0.1); + color: #fff; + cursor: pointer; + display: flex; + align-items: center; + justify-content: center; transition: all 0.3s ease; } -.close-btn:hover { - background: #f5f5f5; - color: #333; +.add-song-close-btn:hover { + background: rgba(255, 255, 255, 0.2); + transform: scale(1.1); } -.modal-body { +.add-song-modal-body { padding: 30px; + flex: 1; + display: flex; + flex-direction: column; + min-height: 0; } -.modal-body p { +.add-song-search-container { + margin-bottom: 25px; +} + +.add-song-search-box { + position: relative; + display: flex; + align-items: center; +} + +.add-song-search-box .search-icon { + position: absolute; + left: 15px; + color: #4A90E2; + z-index: 1; +} + +.add-song-search-box input { + width: 100%; + padding: 15px 20px 15px 50px; + background: rgba(255, 255, 255, 0.05); + border: 2px solid rgba(255, 255, 255, 0.1); + border-radius: 12px; + color: #fff; + font-size: 16px; + transition: all 0.3s ease; +} + +.add-song-search-box input:focus { + outline: none; + border-color: #4A90E2; + background: rgba(255, 255, 255, 0.1); + box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1); +} + +.add-song-search-box input::placeholder { + color: #aaa; +} + +.search-loading { + position: absolute; + right: 15px; + display: flex; + align-items: center; +} + +.loading-spinner { + width: 20px; + height: 20px; + border: 2px solid rgba(74, 144, 226, 0.3); + border-top: 2px solid #4A90E2; + border-radius: 50%; + animation: spin 1s linear infinite; +} + +.add-song-results-container { + flex: 1; + display: flex; + flex-direction: column; + min-height: 300px; + overflow: hidden; +} + +.add-song-placeholder { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + flex: 1; text-align: center; - color: #666; - font-size: 1rem; + color: #aaa; + gap: 15px; +} + +.add-song-placeholder svg { + color: #4A90E2; + opacity: 0.6; +} + +.add-song-placeholder p { margin: 0; + font-size: 16px; } -/* Empty State Styles */ -.empty-songs-state { - text-align: center; - padding: 40px 20px; - color: #666; +.placeholder-subtitle { + font-size: 14px !important; + color: #666 !important; } -.empty-songs-state p { - font-size: 1.1rem; +.add-song-results-list { + display: flex; + flex-direction: column; + gap: 12px; + flex: 1; + overflow-y: auto; + padding-right: 10px; +} + +.add-song-results-list::-webkit-scrollbar { + width: 6px; +} + +.add-song-results-list::-webkit-scrollbar-track { + background: rgba(255, 255, 255, 0.1); + border-radius: 10px; +} + +.add-song-results-list::-webkit-scrollbar-thumb { + background: #4A90E2; + border-radius: 10px; +} + +.add-song-result-item { + display: flex; + align-items: center; + padding: 15px; + background: rgba(255, 255, 255, 0.03); + border-radius: 12px; + border: 1px solid rgba(255, 255, 255, 0.1); + transition: all 0.3s ease; + gap: 15px; +} + +.add-song-result-item:hover { + background: rgba(255, 255, 255, 0.08); + transform: translateY(-1px); + box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2); +} + +.result-song-cover { + width: 50px; + height: 50px; + border-radius: 8px; + object-fit: cover; + flex-shrink: 0; +} + +.result-song-info { + flex: 1; + min-width: 0; +} + +.result-song-info h4 { + font-size: 16px; + margin: 0 0 5px 0; + color: white; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.result-artist { + font-size: 14px; + color: #4A90E2; + margin: 0 0 3px 0; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.result-album { + font-size: 12px; + color: #aaa; margin: 0; - font-style: italic; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; } -/* Mobile Responsive Design */ +.add-song-btn { + display: flex; + align-items: center; + gap: 8px; + padding: 10px 16px; + background: linear-gradient(135deg, #4A90E2, #6BB6FF); + color: white; + border: none; + border-radius: 8px; + font-size: 14px; + font-weight: 600; + cursor: pointer; + transition: all 0.3s ease; + flex-shrink: 0; +} + +.add-song-btn:hover { + transform: scale(1.05); + box-shadow: 0 5px 15px rgba(74, 144, 226, 0.4); +} + +/* Responsive Design */ @media (max-width: 768px) { - .content { + .desktop-main { + flex-direction: column; + padding: 20px 20px 0 20px; + gap: 30px; + height: auto; + } + + .left-section { + flex: none; + max-width: none; + } + + .recommendations-container { + height: auto; + min-height: 400px; + } + + .vinyl-record-desktop { + width: 200px; + height: 200px; + } + + .progress-container { + padding: 15px 20px; + } + + .home-main { + flex-direction: column; + padding: 20px; + gap: 40px; + height: auto; + min-height: 100vh; + } + + .home-vinyl-record { + width: 180px; + height: 180px; + } + + .home-content { padding: 30px 20px; - margin: 10px; - border-radius: 20px; } - .title { - font-size: 2rem; + .home-title { + font-size: 36px; } - .subtitle { - font-size: 1rem; - margin-bottom: 30px; + .home-subtitle { + font-size: 16px; } - .create-station-header { - padding-top: 20px; - margin-bottom: 30px; + .home-action-button { + padding: 15px 25px; + font-size: 14px; } - .create-station-header h1 { - font-size: 1.8rem; + .create-station-main { + flex-direction: column; + padding: 20px; + gap: 40px; + height: auto; + min-height: 100vh; + } + + .create-station-vinyl-record { + width: 200px; + height: 200px; } .create-station-content { padding: 30px 20px; - border-radius: 20px; - margin: 10px; + } + + .create-station-header h1 { + font-size: 28px; } .join-method-section h2 { - font-size: 1.2rem; - } - - .radio-option label { - padding: 14px 16px; - font-size: 1rem; - } - - .password-input-section input { - padding: 14px 16px; + font-size: 16px; } .create-station-final-btn { - padding: 16px 24px; - font-size: 1rem; + padding: 15px 25px; + font-size: 14px; } - .join-station-header { - padding-top: 20px; - margin-bottom: 30px; - } - - .join-station-header h1 { - font-size: 1.8rem; - } - - .join-station-content { - padding: 30px 20px; - border-radius: 20px; - margin: 10px; - } - - .verify-method-section h2 { - font-size: 1.2rem; - } - - .join-station-final-btn { - padding: 16px 24px; - font-size: 1rem; - } - - .station-content { - padding: 15px; - } - - .station-header { - padding-top: 20px; - margin-bottom: 30px; - } - - .station-header h1 { - font-size: 2rem; - } - - .station-subtitle { - font-size: 1rem; - } - - .media-controls-section { - padding: 25px 20px; - } - - .songs-section { - padding: 25px 20px; - } - - .section-header { - flex-direction: column; - align-items: stretch; - gap: 15px; - } - - .add-song-btn { - align-self: center; - min-width: 120px; - } - - .song-item { - padding: 12px 15px; - } - - .songs-list { - max-height: 300px; - } - - .modal-header { - padding: 20px 25px 15px; - } - - .modal-body { - padding: 25px; + .add-song-modal-content { + max-width: 100%; + max-height: 90vh; } } @media (max-width: 480px) { - .home-container { - padding: 15px; + .home-title { + font-size: 28px; } - .content { - padding: 25px 15px; + .home-subtitle { + font-size: 14px; } - .title { - font-size: 1.8rem; - } - - .create-station { - padding: 15px; - } - - .create-station-content { - padding: 25px 15px; - } - - .join-station { - padding: 15px; - } - - .join-station-content { - padding: 25px 15px; - } - - .station-content { - padding: 10px; - } - - .station-header h1 { - font-size: 1.8rem; - } - - .media-controls-section { - padding: 20px 15px; - } - - .songs-section { - padding: 20px 15px; - } - - .control-btn { - width: 45px; - height: 45px; - } - - .control-btn.play-pause { - width: 55px; - height: 55px; - } - - .modal-backdrop { - padding: 15px; - } - - .modal-header { - padding: 15px 20px 10px; - } - - .modal-body { - padding: 20px; - } -} - -/* Larger screens */ -@media (min-width: 1024px) { - .title { - font-size: 3rem; - } - - .subtitle { - font-size: 1.2rem; + .home-vinyl-record { + width: 150px; + height: 150px; } .create-station-header h1 { - font-size: 2.5rem; + font-size: 24px; } - .button-container { - flex-direction: row; - justify-content: center; - gap: 20px; + .create-station-vinyl-record { + width: 150px; + height: 150px; } - .action-button { - min-width: 200px; + .password-input-section input { + padding:12px 15px; + font-size: 14px; } - - .join-station-header h1 { - font-size: 2.5rem; - } - - .station-header h1 { - font-size: 3rem; - } - - .station-subtitle { - font-size: 1.2rem; - } - - .media-controls { - gap: 30px; - } - - .control-btn { - width: 55px; - height: 55px; - } - - .control-btn.play-pause { - width: 70px; - height: 70px; - } -} +} \ No newline at end of file diff --git a/frontend/src/screens/AddSongModal.jsx b/frontend/src/screens/AddSongModal.jsx index b4d50bc..a6b024f 100644 --- a/frontend/src/screens/AddSongModal.jsx +++ b/frontend/src/screens/AddSongModal.jsx @@ -1,26 +1,146 @@ -import React from 'react'; +import React, { useState } from 'react'; +import { searchSpotifyTracks, isLoggedIn } from '../utils/spotifyAuth.js'; function AddSongModal({ onClose }) { + const [searchQuery, setSearchQuery] = useState(''); + const [searchResults, setSearchResults] = useState([]); + const [isLoading, setIsLoading] = useState(false); + const [error, setError] = useState(''); + const handleBackdropClick = (e) => { if (e.target === e.currentTarget) { onClose(); } }; + const handleSearch = async (e) => { + const query = e.target.value; + setSearchQuery(query); + setError(''); + + if (query.length > 2) { + if (!isLoggedIn()) { + setError('Please login to Spotify to search for songs'); + return; + } + + setIsLoading(true); + try { + const results = await searchSpotifyTracks(query); + setSearchResults(results); + } catch (err) { + setError(err.message === 'Token expired' ? 'Session expired. Please login again.' : 'Search failed. Please try again.'); + setSearchResults([]); + if (err.message === 'Token expired') { + setTimeout(() => window.location.reload(), 2000); + } + } finally { + setIsLoading(false); + } + } else { + setSearchResults([]); + } + }; + + const handleKeyPress = async (e) => { + if (e.key === 'Enter' && searchQuery.trim() && searchQuery.length > 2) { + if (!isLoggedIn()) { + setError('Please login to Spotify to search for songs'); + return; + } + + setIsLoading(true); + try { + const results = await searchSpotifyTracks(searchQuery); + setSearchResults(results); + setError(''); + } catch (err) { + setError(err.message === 'Token expired' ? 'Session expired. Please login again.' : 'Search failed. Please try again.'); + setSearchResults([]); + } finally { + setIsLoading(false); + } + } + }; + return ( -
-
-
-

Add Song

-
-
-

Song addition functionality coming soon...

+
+
+
+ + + + + {isLoading && ( +
+
+
+ )} +
+
+ +
+ {error && ( +
+

{error}

+
+ )} + {searchQuery.length === 0 ? ( +
+ + + +

Search for music to add to your station

+

Enter song title, artist, or album name

+
+ ) : searchQuery.length <= 2 ? ( +
+

Type at least 3 characters to search

+
+ ) : searchResults.length === 0 && !isLoading && !error ? ( +
+

No results found for "{searchQuery}"

+

Try different keywords

+
+ ) : ( +
+ {searchResults.map(song => ( +
+ {`${song.title} +
+

{song.title}

+

{song.artist}

+

{song.album}

+
+ +
+ ))} +
+ )} +
diff --git a/frontend/src/screens/CreateStation.jsx b/frontend/src/screens/CreateStation.jsx index 16c8688..8fb2603 100644 --- a/frontend/src/screens/CreateStation.jsx +++ b/frontend/src/screens/CreateStation.jsx @@ -9,50 +9,78 @@ function CreateStation() { }; return ( -
-
-

Create a Station on Serena

-
- -
-
-

How should people be able to join your station?

- -
- -
- - {joinMethod === 'password' && ( -
- - setPassword(e.target.value)} - placeholder="Enter station password" - /> +
+
+ {/* Left Section - Vinyl Animation */} +
+
+
+
+
- )} + + {/* Animated Music Notes */} +
+
+
+
+
+
- -
+ {/* Right Section - Create Station Form */} +
+
+
+

Create a Station on Serena

+
+ +
+
+

How should people be able to join your station?

+ +
+ +
+ + {joinMethod === 'password' && ( +
+ + setPassword(e.target.value)} + placeholder="Enter station password" + /> +
+ )} +
+ + +
+
+
+
); } diff --git a/frontend/src/screens/Home.jsx b/frontend/src/screens/Home.jsx index 414e9d9..5863cac 100644 --- a/frontend/src/screens/Home.jsx +++ b/frontend/src/screens/Home.jsx @@ -14,24 +14,52 @@ function Home() { return (
-
-

Radio Station Hub

-

Create or join a radio station to share music with friends

- -
- - - +
+ {/* Left Section - Logo/Animation */} +
+
+
+
+
+
+ + {/* Animated Music Notes */} +
+
+
+
+
+
+
+ + {/* Right Section - Content */} +
+
+

Serena Hub

+

Create or join a radio station to share music with friends

+ +
+ + + +
+
diff --git a/frontend/src/screens/JoinStation.jsx b/frontend/src/screens/JoinStation.jsx index 3bb3302..0dcd834 100644 --- a/frontend/src/screens/JoinStation.jsx +++ b/frontend/src/screens/JoinStation.jsx @@ -13,50 +13,78 @@ function JoinStation() { }; return ( -
-
-

Join a Station on Serena

-
- -
-
-

How would you like to verify access?

- -
- -
- - {verifyMethod === 'password' && ( -
- - setPassword(e.target.value)} - placeholder="Enter station password" - /> +
+
+ {/* Left Section - Vinyl Animation */} +
+
+
+
+
- )} + + {/* Animated Music Notes */} +
+
+
+
+
+
- -
+ {/* Right Section - Join Station Form */} +
+
+
+

Join a Station on Serena

+
+ +
+
+

How would you like to verify access?

+ +
+ +
+ + {verifyMethod === 'password' && ( +
+ + setPassword(e.target.value)} + placeholder="Enter station password" + /> +
+ )} +
+ + +
+
+
+
); } diff --git a/frontend/src/screens/StationPage.jsx b/frontend/src/screens/StationPage.jsx index 77d5058..08a4287 100644 --- a/frontend/src/screens/StationPage.jsx +++ b/frontend/src/screens/StationPage.jsx @@ -1,30 +1,27 @@ import React, { useState } from 'react'; import AddSongModal from './AddSongModal'; -import LoginButton from '../components/LoginButton'; function StationPage() { const [isModalOpen, setIsModalOpen] = useState(false); const [currentSong, setCurrentSong] = useState({ title: "No song playing", artist: "Add songs to get started", - isPlaying: false + isPlaying: false, + progress: 0, + duration: 180 // 3 minutes in seconds + }); + + const [nextSong] = useState({ + title: "No song queued", + artist: "No Artist Queued" }); - // Empty song list - no songs initially const recommendedSongs = []; const handlePlayPause = () => { setCurrentSong(prev => ({ ...prev, isPlaying: !prev.isPlaying })); }; - const handleNext = () => { - console.log('Next song'); - }; - - const handlePrevious = () => { - console.log('Previous song'); - }; - const openModal = () => { setIsModalOpen(true); }; @@ -34,34 +31,38 @@ function StationPage() { }; return ( -
-
- {[...Array(20)].map((_, i) => ( -
- ))} -
- -
-
-

Serena Station

-

Collaborative Music Experience

- -
- -
-
-

{currentSong.title}

-

{currentSong.artist}

-
- -
- +
+ {/* Main Layout */} +
+ {/* Left Section */} +
+ {/* Vinyl Record */} +
+
+
+
+
-
+ + {/* Next Song Info */} +
+

Next song:

+

{nextSong.title}

+

{nextSong.artist}

+
+ + {/* Bottom Play Icon */} +
+ - -
-
-
-

Song Queue

- -
- -
- {recommendedSongs.length === 0 ? ( -
-

No songs in queue yet. Add some songs to get started!

-
- ) : ( - recommendedSongs.map(song => ( -
-
-

{song.title}

-

{song.artist}

-
- {song.duration} + {/* Right Section - Recommendations */} +
+
+
+

Song Suggestions

+ +
+ +
+ {recommendedSongs.length === 0 ? ( +
+

No songs suggested yet

+

Add songs to get started!

- )) - )} + ) : ( + recommendedSongs.map(song => ( +
+ {`${song.title} +
+

{song.title}

+

{song.artist}

+

{song.album}

+
+ {song.duration} +
+ )) + )} +
+ {/* Progress Bar */} +
+
+
+
+
+ {isModalOpen && }
); diff --git a/frontend/src/utils/spotifyAuth.js b/frontend/src/utils/spotifyAuth.js index 67fc94a..342897c 100644 --- a/frontend/src/utils/spotifyAuth.js +++ b/frontend/src/utils/spotifyAuth.js @@ -38,3 +38,39 @@ export const removeAccessToken = () => { export const isLoggedIn = () => { return !!getAccessToken(); }; + +export const searchSpotifyTracks = async (query) => { + const token = getAccessToken(); + if (!token) { + throw new Error('No access token available'); + } + + const response = await fetch( + `https://api.spotify.com/v1/search?q=${encodeURIComponent(query)}&type=track&limit=20`, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + + if (!response.ok) { + if (response.status === 401) { + removeAccessToken(); + throw new Error('Token expired'); + } + throw new Error('Search failed'); + } + + const data = await response.json(); + return data.tracks.items.map((track) => ({ + id: track.id, + title: track.name, + artist: track.artists.map((artist) => artist.name).join(', '), + album: track.album.name, + coverUrl: track.album.images[0]?.url || '', + duration: track.duration_ms, + previewUrl: track.preview_url, + spotifyUrl: track.external_urls.spotify, + })); +}; From 7e9b155fa1a7cc1cf4786b16a3c1d01910447d14 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 2 Aug 2025 02:07:47 +0200 Subject: [PATCH 02/13] fix --- frontend/src/screens/CreateStation.jsx | 3 +++ frontend/src/screens/JoinStation.jsx | 3 +++ 2 files changed, 6 insertions(+) diff --git a/frontend/src/screens/CreateStation.jsx b/frontend/src/screens/CreateStation.jsx index 5a75fa4..c7c56f6 100644 --- a/frontend/src/screens/CreateStation.jsx +++ b/frontend/src/screens/CreateStation.jsx @@ -51,6 +51,9 @@ function CreateStation() {
+
+
+
); } diff --git a/frontend/src/screens/JoinStation.jsx b/frontend/src/screens/JoinStation.jsx index 3444137..2961198 100644 --- a/frontend/src/screens/JoinStation.jsx +++ b/frontend/src/screens/JoinStation.jsx @@ -53,6 +53,9 @@ function JoinStation() { ); })} +
+
+
); } From 98baaed4846a7d6feb888e36f97eec49a5ca3c6d Mon Sep 17 00:00:00 2001 From: Lukas Weger Date: Sat, 2 Aug 2025 03:30:48 +0200 Subject: [PATCH 03/13] Implement song queue management for clients, including adding songs to preferred queue and retrieving the queue for a radio station --- backend/API_DOCUMENTATION.md | 172 ++++++++++++++++++ .../backend/controller/SongController.java | 36 +++- .../serena/backend/dto/AddSongRequest.java | 3 +- .../dto/AddSongToClientQueueRequest.java | 41 +++++ .../java/com/serena/backend/model/Client.java | 20 ++ .../serena/backend/model/RadioStation.java | 6 +- .../backend/service/RadioStationService.java | 34 +++- 7 files changed, 289 insertions(+), 23 deletions(-) create mode 100644 backend/src/main/java/com/serena/backend/dto/AddSongToClientQueueRequest.java diff --git a/backend/API_DOCUMENTATION.md b/backend/API_DOCUMENTATION.md index 7f5482d..690ee97 100644 --- a/backend/API_DOCUMENTATION.md +++ b/backend/API_DOCUMENTATION.md @@ -23,6 +23,26 @@ Authorization: Bearer #### Create Radio Station +#### Get All Radio Stations + +#### Get Radio Station by ID + +#### Delete Radio Station + +### Client Management + +#### Connect Client to Station + +### Song Queue Management + +#### Add Song to Client's Preferred Queue + +#### Get Radio Station Queue + +## Radio Station Management + +#### Create Radio Station + Creates a new radio station and returns an owner token. **Endpoint:** `POST /radio-stations` @@ -170,6 +190,90 @@ Connects a client to a radio station using a join code. No authentication requir } ``` +### Song Queue Management + +#### Add Song to Client's Preferred Queue + +Adds a song to a specific client's preferred queue. The frontend can merge track and audio features objects using `const merged = { ...trackObj, ...audioFeaturesObj };` + +**Endpoint:** `POST /api/songs/queue` + +**Request Body:** + +```json +{ + "song": { + "id": "4iV5W9uYEdYUVa79Axb7Rh", + "popularity": 85, + "tempo": 120.5, + "danceability": 0.8, + "energy": 0.7, + "valence": 0.6, + "acousticness": 0.1, + "instrumentalness": 0.0, + "liveness": 0.1, + "speechiness": 0.04 + }, + "clientId": "client-uuid", + "radioStationId": "station-uuid" +} +``` + +**Response:** + +```json +{ + "success": true, + "message": "Song added to client's preferred queue successfully", + "data": null +} +``` + +#### Get Radio Station Queue + +Retrieves the main song queue for a radio station. Returns a list of song objects. + +**Endpoint:** `GET /api/songs/queue?radioStationId={radioStationId}` + +**Query Parameters:** + +- `radioStationId` (required): The ID of the radio station + +**Response:** + +```json +{ + "success": true, + "message": "Queue retrieved successfully", + "data": [ + { + "id": "4iV5W9uYEdYUVa79Axb7Rh", + "popularity": 85, + "tempo": 120.5, + "danceability": 0.8, + "energy": 0.7, + "valence": 0.6, + "acousticness": 0.1, + "instrumentalness": 0.0, + "liveness": 0.1, + "speechiness": 0.04 + }, + { + "id": "7ouMYWpwJ422jRcDASZB7P", + "popularity": 78, + "tempo": 95.0, + "danceability": 0.6, + "energy": 0.5, + "valence": 0.8, + "acousticness": 0.3, + "instrumentalness": 0.0, + "liveness": 0.2, + "speechiness": 0.06 + } + ] +} +``` + ## Error Responses All error responses follow this format: @@ -213,3 +317,71 @@ curl -X GET "http://localhost:8080/api/radio-stations" \ curl -X DELETE http://localhost:8080/api/radio-stations/{stationId} \ -H "Authorization: Bearer {ownerToken}" ``` + +### Adding a Song to Client's Preferred Queue + +```bash +curl -X POST http://localhost:8080/api/songs/queue \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer {clientToken}" \ + -d '{ + "song": { + "id": "4iV5W9uYEdYUVa79Axb7Rh", + "popularity": 85, + "tempo": 120.5, + "danceability": 0.8, + "energy": 0.7, + "valence": 0.6, + "acousticness": 0.1, + "instrumentalness": 0.0, + "liveness": 0.1, + "speechiness": 0.04 + }, + "clientId": "client-uuid", + "radioStationId": "station-uuid" + }' +``` + +### Getting Radio Station Queue + +```bash +curl -X GET "http://localhost:8080/api/songs/queue?radioStationId=station-uuid" \ + -H "Authorization: Bearer {token}" +``` + +## Frontend Integration Notes + +### Merging Track and Audio Features + +The frontend can easily merge track information with audio features using JavaScript object spread: + +```javascript +// Track object from Spotify API +const trackObj = { + id: "4iV5W9uYEdYUVa79Axb7Rh", + popularity: 85, + tempo: 120.5, +}; + +// Audio features object from Spotify API +const audioFeaturesObj = { + danceability: 0.8, + energy: 0.7, + valence: 0.6, + acousticness: 0.1, + instrumentalness: 0.0, + liveness: 0.1, + speechiness: 0.04, +}; + +// Merge objects for API request +const merged = { ...trackObj, ...audioFeaturesObj }; +``` + +### Queue Data Structure + +The queue endpoints return/accept arrays of song objects. Each song object contains: + +- Basic track info (id, popularity, tempo) +- Audio features (danceability, energy, valence, etc.) +- All properties are at the root level (flattened structure) diff --git a/backend/src/main/java/com/serena/backend/controller/SongController.java b/backend/src/main/java/com/serena/backend/controller/SongController.java index 1694a5c..403784b 100644 --- a/backend/src/main/java/com/serena/backend/controller/SongController.java +++ b/backend/src/main/java/com/serena/backend/controller/SongController.java @@ -1,8 +1,8 @@ package com.serena.backend.controller; import com.serena.backend.dto.ApiResponse; -import com.serena.backend.dto.ConnectClientRequest; -import com.serena.backend.dto.AddSongRequest; +import com.serena.backend.dto.AddSongToClientQueueRequest; +import com.serena.backend.model.Song; import com.serena.backend.service.RadioStationService; import com.serena.backend.service.JwtService; import org.springframework.beans.factory.annotation.Autowired; @@ -10,8 +10,11 @@ import org.springframework.http.ResponseEntity; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; +import java.util.Optional; +import java.util.Queue; + @RestController -@RequestMapping("/api/songs/") +@RequestMapping("/api/songs") @CrossOrigin(origins = "*") public class SongController { @@ -21,20 +24,33 @@ public class SongController { @Autowired private JwtService jwtService; - @PostMapping - public ResponseEntity> addSong(@RequestBody AddSongRequest request) { - if (request.getSong() == null || request.getRadioStationId() == null) { + @PostMapping("/queue") + public ResponseEntity> addSongToClientQueue(@RequestBody AddSongToClientQueueRequest request) { + if (request.getSong() == null || request.getClientId() == null) { return ResponseEntity.badRequest() - .body(new ApiResponse<>(false, "Song data and radio station ID are required", null)); + .body(new ApiResponse<>(false, "Song data and client ID are required", null)); } - boolean success = radioStationService.addSongToQueue(request.getRadioStationId(), request.getSong()); + boolean success = radioStationService.addSongToClientQueue(request.getClientId(), request.getSong()); if (success) { - return ResponseEntity.ok(new ApiResponse<>(true, "Song added to queue successfully", null)); + return ResponseEntity.ok(new ApiResponse<>(true, "Song added to client's preferred queue successfully", null)); } else { return ResponseEntity.status(HttpStatus.NOT_FOUND) - .body(new ApiResponse<>(false, "Radio station not found or inactive", null)); + .body(new ApiResponse<>(false, "Client not found", null)); + } + } + + @GetMapping("/queue") + public ResponseEntity>> getRadioStationQueue(@RequestParam String radioStationId) { + Optional station = radioStationService.getRadioStation(radioStationId); + + if (station.isPresent()) { + Queue queue = station.get().getSongQueue(); + return ResponseEntity.ok(new ApiResponse<>(true, "Queue retrieved successfully", queue)); + } else { + return ResponseEntity.status(HttpStatus.NOT_FOUND) + .body(new ApiResponse<>(false, "Radio station not found", null)); } } } diff --git a/backend/src/main/java/com/serena/backend/dto/AddSongRequest.java b/backend/src/main/java/com/serena/backend/dto/AddSongRequest.java index be69f9f..ce6ed44 100644 --- a/backend/src/main/java/com/serena/backend/dto/AddSongRequest.java +++ b/backend/src/main/java/com/serena/backend/dto/AddSongRequest.java @@ -6,7 +6,8 @@ public class AddSongRequest { private Song song; private String radioStationId; - public AddSongRequest() {} + public AddSongRequest() { + } public AddSongRequest(Song song, String radioStationId) { this.song = song; diff --git a/backend/src/main/java/com/serena/backend/dto/AddSongToClientQueueRequest.java b/backend/src/main/java/com/serena/backend/dto/AddSongToClientQueueRequest.java new file mode 100644 index 0000000..05626db --- /dev/null +++ b/backend/src/main/java/com/serena/backend/dto/AddSongToClientQueueRequest.java @@ -0,0 +1,41 @@ +package com.serena.backend.dto; + +import com.serena.backend.model.Song; + +public class AddSongToClientQueueRequest { + private Song song; + private String clientId; + private String radioStationId; + + public AddSongToClientQueueRequest() {} + + public AddSongToClientQueueRequest(Song song, String clientId, String radioStationId) { + this.song = song; + this.clientId = clientId; + this.radioStationId = radioStationId; + } + + public Song getSong() { + return song; + } + + public void setSong(Song song) { + this.song = song; + } + + public String getClientId() { + return clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getRadioStationId() { + return radioStationId; + } + + public void setRadioStationId(String radioStationId) { + this.radioStationId = radioStationId; + } +} diff --git a/backend/src/main/java/com/serena/backend/model/Client.java b/backend/src/main/java/com/serena/backend/model/Client.java index 4b5e2dd..b734aeb 100644 --- a/backend/src/main/java/com/serena/backend/model/Client.java +++ b/backend/src/main/java/com/serena/backend/model/Client.java @@ -2,16 +2,20 @@ package com.serena.backend.model; import java.time.LocalDateTime; import java.util.UUID; +import java.util.LinkedList; +import java.util.Queue; public class Client { private String id; private String username; private String radioStationId; private LocalDateTime connectedAt; + private Queue preferredQueue; public Client() { this.id = UUID.randomUUID().toString(); this.connectedAt = LocalDateTime.now(); + this.preferredQueue = new LinkedList<>(); } public Client(String username, String radioStationId) { @@ -53,4 +57,20 @@ public class Client { this.connectedAt = connectedAt; } + public Queue getPreferredQueue() { + return preferredQueue; + } + + public void setPreferredQueue(Queue preferredQueue) { + this.preferredQueue = preferredQueue; + } + + public void addSongToPreferredQueue(Song song) { + this.preferredQueue.offer(song); + } + + public Song getNextPreferredSong() { + return this.preferredQueue.poll(); + } + } diff --git a/backend/src/main/java/com/serena/backend/model/RadioStation.java b/backend/src/main/java/com/serena/backend/model/RadioStation.java index 693f480..27fb3bc 100644 --- a/backend/src/main/java/com/serena/backend/model/RadioStation.java +++ b/backend/src/main/java/com/serena/backend/model/RadioStation.java @@ -15,7 +15,7 @@ public class RadioStation { private String ownerId; private String joinCode; private LocalDateTime createdAt; - private List connectedClients; + private List connectedClients; private Queue songQueue; public RadioStation() { @@ -93,11 +93,11 @@ public class RadioStation { this.createdAt = createdAt; } - public List getConnectedClients() { + public List getConnectedClients() { return connectedClients; } - public void setConnectedClients(List connectedClients) { + public void setConnectedClients(List connectedClients) { this.connectedClients = connectedClients; } diff --git a/backend/src/main/java/com/serena/backend/service/RadioStationService.java b/backend/src/main/java/com/serena/backend/service/RadioStationService.java index 9ab557b..8af4122 100644 --- a/backend/src/main/java/com/serena/backend/service/RadioStationService.java +++ b/backend/src/main/java/com/serena/backend/service/RadioStationService.java @@ -54,9 +54,10 @@ public class RadioStationService { RadioStation station = radioStations.get(stationId); if (station != null) { // Disconnect all clients + for (Client client : station.getConnectedClients()) { + clients.remove(client.getId()); + } station.getConnectedClients().clear(); - // Remove from clients map - clients.entrySet().removeIf(entry -> stationId.equals(entry.getValue().getRadioStationId())); radioStations.remove(stationId); return true; } @@ -69,7 +70,7 @@ public class RadioStationService { if (station != null && station.getJoinCode().equals(joinCode)) { Client client = new Client(username, radioStationId); clients.put(client.getId(), client); - station.getConnectedClients().add(client.getId()); + station.getConnectedClients().add(client); return Optional.of(client); } return Optional.empty(); @@ -81,7 +82,7 @@ public class RadioStationService { RadioStation station = stationOpt.get(); Client client = new Client(username, station.getId()); clients.put(client.getId(), client); - station.getConnectedClients().add(client.getId()); + station.getConnectedClients().add(client); return Optional.of(client); } return Optional.empty(); @@ -92,7 +93,7 @@ public class RadioStationService { if (client != null) { RadioStation station = radioStations.get(client.getRadioStationId()); if (station != null) { - station.getConnectedClients().remove(clientId); + station.getConnectedClients().removeIf(c -> c.getId().equals(clientId)); } clients.remove(clientId); return true; @@ -107,10 +108,7 @@ public class RadioStationService { public List getConnectedClients(String radioStationId) { RadioStation station = radioStations.get(radioStationId); if (station != null) { - return station.getConnectedClients().stream() - .map(clients::get) - .filter(client -> client != null) - .toList(); + return new ArrayList<>(station.getConnectedClients()); } return new ArrayList<>(); } @@ -132,4 +130,22 @@ public class RadioStationService { return Optional.empty(); } + // Client Queue Management + public boolean addSongToClientQueue(String clientId, Song song) { + Client client = clients.get(clientId); + if (client != null) { + client.addSongToPreferredQueue(song); + return true; + } + return false; + } + + public Optional getNextClientSong(String clientId) { + Client client = clients.get(clientId); + if (client != null) { + return Optional.ofNullable(client.getNextPreferredSong()); + } + return Optional.empty(); + } + } From f99ae52c4ad1d6aded719e9fdd8068a20c4d9f3d Mon Sep 17 00:00:00 2001 From: Lukas Weger Date: Sat, 2 Aug 2025 03:54:44 +0200 Subject: [PATCH 04/13] Add recommended queue endpoint and audio feature methods for song model --- backend/API_DOCUMENTATION.md | 35 ++++ .../backend/controller/SongController.java | 41 ++++ .../java/com/serena/backend/model/Song.java | 24 +++ .../serena/backend/service/QueueService.java | 182 ++++++++++++++++++ 4 files changed, 282 insertions(+) create mode 100644 backend/src/main/java/com/serena/backend/service/QueueService.java diff --git a/backend/API_DOCUMENTATION.md b/backend/API_DOCUMENTATION.md index 690ee97..64c3875 100644 --- a/backend/API_DOCUMENTATION.md +++ b/backend/API_DOCUMENTATION.md @@ -39,6 +39,8 @@ Authorization: Bearer #### Get Radio Station Queue +#### Get Recommended Queue + ## Radio Station Management #### Create Radio Station @@ -274,6 +276,39 @@ Retrieves the main song queue for a radio station. Returns a list of song object } ``` +#### Get Recommended Queue + +**Endpoint:** `GET /api/songs/queue/recommended?radioStationId={radioStationId}¤tSongId={currentSongId}` + +**Query Parameters:** + +- `radioStationId` (required): The ID of the radio station +- `currentSongId` (optional): The ID of the currently playing song for similarity analysis + +**Response:** + +```json +{ + "success": true, + "message": "Recommended queue retrieved successfully", + "data": [ + { + "id": "4iV5W9uYEdYUVa79Axb7Rh", + "popularity": 85, + "tempo": 120.5, + "audioFeatures": { + "danceability": 0.8, + "energy": 0.7, + "valence": 0.6, + "acousticness": 0.1, + "instrumentalness": 0.0, + "speechiness": 0.04 + } + } + ] +} +``` + ## Error Responses All error responses follow this format: diff --git a/backend/src/main/java/com/serena/backend/controller/SongController.java b/backend/src/main/java/com/serena/backend/controller/SongController.java index 403784b..3fd5c65 100644 --- a/backend/src/main/java/com/serena/backend/controller/SongController.java +++ b/backend/src/main/java/com/serena/backend/controller/SongController.java @@ -4,14 +4,17 @@ import com.serena.backend.dto.ApiResponse; import com.serena.backend.dto.AddSongToClientQueueRequest; import com.serena.backend.model.Song; import com.serena.backend.service.RadioStationService; +import com.serena.backend.service.QueueService; import com.serena.backend.service.JwtService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; +import java.util.List; import java.util.Optional; import java.util.Queue; +import java.util.ArrayList; @RestController @RequestMapping("/api/songs") @@ -21,6 +24,9 @@ public class SongController { @Autowired private RadioStationService radioStationService; + @Autowired + private QueueService queueService; + @Autowired private JwtService jwtService; @@ -53,4 +59,39 @@ public class SongController { .body(new ApiResponse<>(false, "Radio station not found", null)); } } + + @GetMapping("/queue/recommended") + public ResponseEntity>> getRecommendedQueue( + @RequestParam String radioStationId, + @RequestParam(required = false) String currentSongId) { + + Optional stationOpt = radioStationService.getRadioStation(radioStationId); + + if (stationOpt.isEmpty()) { + return ResponseEntity.status(HttpStatus.NOT_FOUND) + .body(new ApiResponse<>(false, "Radio station not found", null)); + } + + com.serena.backend.model.RadioStation station = stationOpt.get(); + + List queueList = new ArrayList<>(station.getSongQueue()); + + if (queueList.isEmpty()) { + return ResponseEntity.ok(new ApiResponse<>(true, "Empty queue", queueList)); + } + + Song currentSong = null; + if (currentSongId != null && !currentSongId.isEmpty()) { + currentSong = queueList.stream() + .filter(song -> song.getId().equals(currentSongId)) + .findFirst() + .orElse(null); + } + + List clients = radioStationService.getConnectedClients(radioStationId); + + List sortedQueue = queueService.sortQueue(currentSong, queueList, clients); + + return ResponseEntity.ok(new ApiResponse<>(true, "Recommended queue retrieved successfully", sortedQueue)); + } } diff --git a/backend/src/main/java/com/serena/backend/model/Song.java b/backend/src/main/java/com/serena/backend/model/Song.java index 0e92555..88d378e 100644 --- a/backend/src/main/java/com/serena/backend/model/Song.java +++ b/backend/src/main/java/com/serena/backend/model/Song.java @@ -57,4 +57,28 @@ public class Song { public void setAudioFeatures(Map audioFeatures) { this.audioFeatures = audioFeatures; } + + public double getAcousticness() { + return audioFeatures.getOrDefault("acousticness", 0.0); + } + + public double getDanceability() { + return audioFeatures.getOrDefault("danceability", 0.0); + } + + public double getEnergy() { + return audioFeatures.getOrDefault("energy", 0.0); + } + + public double getInstrumentalness() { + return audioFeatures.getOrDefault("instrumentalness", 0.0); + } + + public double getSpeechiness() { + return audioFeatures.getOrDefault("speechiness", 0.0); + } + + public double getValence() { + return audioFeatures.getOrDefault("valence", 0.0); + } } diff --git a/backend/src/main/java/com/serena/backend/service/QueueService.java b/backend/src/main/java/com/serena/backend/service/QueueService.java new file mode 100644 index 0000000..de50171 --- /dev/null +++ b/backend/src/main/java/com/serena/backend/service/QueueService.java @@ -0,0 +1,182 @@ +package com.serena.backend.service; + +import com.serena.backend.model.Song; +import com.serena.backend.model.Client; +import org.springframework.stereotype.Service; + +import java.util.*; +import java.util.stream.Collectors; + +@Service +public class QueueService { + + private static final double W1_PREFERRED_QUEUE = 0.3; // preferred queue position + private static final double W2_POPULARITY = 0.2; // popularity + private static final double W3_TEMPO_SIMILARITY = 0.2; // tempo similarity + private static final double W4_AUDIO_FEATURES = 0.3; // audio feature distance + + public List sortQueue(Song currentSong, List queue, List clients) { + if (queue == null || queue.isEmpty()) { + return new ArrayList<>(); + } + + if (currentSong == null) { + return queue.stream() + .sorted((s1, s2) -> Integer.compare(s2.getPopularity(), s1.getPopularity())) + .collect(Collectors.toList()); + } + + Map songScores = new HashMap<>(); + + for (Song song : queue) { + double totalScore = calculateRecommendationScore(currentSong, song, clients, queue); + songScores.put(song, totalScore); + } + + return queue.stream() + .sorted((s1, s2) -> Double.compare(songScores.get(s2), songScores.get(s1))) + .collect(Collectors.toList()); + } + + private double calculateRecommendationScore(Song currentSong, Song song, List clients, List queue) { + double p1 = calculatePreferredQueueScore(song, clients); + double p2 = calculatePopularityScore(song); + double p3 = calculateTempoSimilarityScore(currentSong, song, queue); + double p4 = calculateAudioFeatureScore(currentSong, song); + + return W1_PREFERRED_QUEUE * p1 + W2_POPULARITY * p2 + W3_TEMPO_SIMILARITY * p3 + W4_AUDIO_FEATURES * p4; + } + + /** + * P1: Preferred Queue Position Score + * For each client, find the song's rank in their preferred queue and normalize. + */ + private double calculatePreferredQueueScore(Song song, List clients) { + if (clients == null || clients.isEmpty()) { + return 0.0; + } + + List clientScores = new ArrayList<>(); + + for (Client client : clients) { + Queue preferredQueue = client.getPreferredQueue(); + if (preferredQueue == null || preferredQueue.isEmpty()) { + continue; + } + + List preferredList = new ArrayList<>(preferredQueue); + int position = -1; + + for (int i = 0; i < preferredList.size(); i++) { + if (preferredList.get(i).getId().equals(song.getId())) { + position = i + 1; // 1-based position + break; + } + } + + if (position > 0) { + // Normalize: 1 = most preferred (position 1), approaches 0 for later positions + double normalizedScore = 1.0 - ((double) (position - 1) / preferredList.size()); + clientScores.add(normalizedScore); + } + } + + return clientScores.isEmpty() ? 0.0 : clientScores.stream().mapToDouble(Double::doubleValue).average().orElse(0.0); + } + + /** + * P2: Popularity Score + * Normalize popularity from 0-100 to 0.0-1.0 + */ + private double calculatePopularityScore(Song song) { + return song.getPopularity() / 100.0; + } + + /** + * P3: Tempo Similarity Score + * Calculate similarity based on tempo difference, normalized by max tempo. + */ + private double calculateTempoSimilarityScore(Song currentSong, Song song, List queue) { + double currentTempo = currentSong.getTempo(); + double songTempo = song.getTempo(); + + // Find max tempo among current song and queue + double maxTempo = Math.max(currentTempo, + queue.stream().mapToDouble(Song::getTempo).max().orElse(currentTempo)); + + if (maxTempo == 0) { + return 1.0; + } + + double tempoDistance = Math.abs(currentTempo - songTempo); + return 1.0 - (tempoDistance / maxTempo); + } + + /** + * P4: Audio Feature Distance Score + * Calculate Euclidean distance between audio features and invert for similarity + * score. + */ + private double calculateAudioFeatureScore(Song currentSong, Song song) { + double distanceSquared = 0.0; + int featureCount = 0; + + // Calculate Euclidean distance for each audio feature + double currentAcousticness = currentSong.getAcousticness(); + double songAcousticness = song.getAcousticness(); + distanceSquared += Math.pow(currentAcousticness - songAcousticness, 2); + featureCount++; + + double currentDanceability = currentSong.getDanceability(); + double songDanceability = song.getDanceability(); + distanceSquared += Math.pow(currentDanceability - songDanceability, 2); + featureCount++; + + double currentEnergy = currentSong.getEnergy(); + double songEnergy = song.getEnergy(); + distanceSquared += Math.pow(currentEnergy - songEnergy, 2); + featureCount++; + + double currentInstrumentalness = currentSong.getInstrumentalness(); + double songInstrumentalness = song.getInstrumentalness(); + distanceSquared += Math.pow(currentInstrumentalness - songInstrumentalness, 2); + featureCount++; + + double currentSpeechiness = currentSong.getSpeechiness(); + double songSpeechiness = song.getSpeechiness(); + distanceSquared += Math.pow(currentSpeechiness - songSpeechiness, 2); + featureCount++; + + double currentValence = currentSong.getValence(); + double songValence = song.getValence(); + distanceSquared += Math.pow(currentValence - songValence, 2); + featureCount++; + + if (featureCount == 0) { + return 0.0; + } + + double distance = Math.sqrt(distanceSquared); + + double maxDistance = Math.sqrt(featureCount); + double normalizedDistance = distance / maxDistance; + + return 1.0 - normalizedDistance; + } + + public static double getW1PreferredQueue() { + return W1_PREFERRED_QUEUE; + } + + public static double getW2Popularity() { + return W2_POPULARITY; + } + + public static double getW3TempoSimilarity() { + return W3_TEMPO_SIMILARITY; + } + + public static double getW4AudioFeatures() { + return W4_AUDIO_FEATURES; + } +} From db8ab4e166a9782a9431e2891e38924cb83f8117 Mon Sep 17 00:00:00 2001 From: Noah Date: Sat, 2 Aug 2025 04:23:49 +0200 Subject: [PATCH 05/13] Fixed Join Screen and added Station Page navigation --- frontend/src/App.jsx | 16 +++---- frontend/src/screens/JoinStation.jsx | 18 +++++--- frontend/src/screens/StationPage.jsx | 62 +++------------------------- frontend/src/utils/GetStations.js | 31 ++++++++------ frontend/src/utils/StationsCreate.js | 4 +- 5 files changed, 46 insertions(+), 85 deletions(-) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 7b0b635..465c9cb 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -1,10 +1,10 @@ -import React from 'react'; -import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'; -import Home from './screens/Home'; -import CreateStation from './screens/CreateStation'; -import JoinStation from './screens/JoinStation'; -import StationPage from './screens/StationPage'; -import './App.css'; +import React from "react"; +import { BrowserRouter as Router, Routes, Route } from "react-router-dom"; +import Home from "./screens/Home"; +import CreateStation from "./screens/CreateStation"; +import JoinStation from "./screens/JoinStation"; +import StationPage from "./screens/StationPage"; +import "./App.css"; function App() { return ( @@ -14,7 +14,7 @@ function App() { } /> } /> } /> - } /> + } /> diff --git a/frontend/src/screens/JoinStation.jsx b/frontend/src/screens/JoinStation.jsx index 2f3e758..ed2fff4 100644 --- a/frontend/src/screens/JoinStation.jsx +++ b/frontend/src/screens/JoinStation.jsx @@ -8,13 +8,15 @@ function JoinStation() { const handleJoinStation = (stationID) => { console.log("Joining station with ID:" + stationID); - navigate("/station"); + navigate(`/station/${stationID}`); }; useEffect(() => { - console.log("Test"); - - getStations(getStations()); + async function fetchStations() { + const result = await getStations(); // assuming getStations is async + setStations(result); + } + fetchStations(); }, []); return ( @@ -26,8 +28,12 @@ function JoinStation() {
{stations.map((station, index) => { return ( -
- station +
+

Station Name: {station.name}

+

Station Description: {station.description}

+
); })} diff --git a/frontend/src/screens/StationPage.jsx b/frontend/src/screens/StationPage.jsx index 77d5058..c4830eb 100644 --- a/frontend/src/screens/StationPage.jsx +++ b/frontend/src/screens/StationPage.jsx @@ -1,30 +1,13 @@ -import React, { useState } from 'react'; -import AddSongModal from './AddSongModal'; -import LoginButton from '../components/LoginButton'; +import React, { useState, useParams } from "react"; +import AddSongModal from "./AddSongModal"; +import LoginButton from "../components/LoginButton"; function StationPage() { + const { id } = useParams(); const [isModalOpen, setIsModalOpen] = useState(false); - const [currentSong, setCurrentSong] = useState({ - title: "No song playing", - artist: "Add songs to get started", - isPlaying: false - }); - // Empty song list - no songs initially const recommendedSongs = []; - const handlePlayPause = () => { - setCurrentSong(prev => ({ ...prev, isPlaying: !prev.isPlaying })); - }; - - const handleNext = () => { - console.log('Next song'); - }; - - const handlePrevious = () => { - console.log('Previous song'); - }; - const openModal = () => { setIsModalOpen(true); }; @@ -48,39 +31,6 @@ function StationPage() { -
-
-

{currentSong.title}

-

{currentSong.artist}

-
- -
- - - - - -
-
-

Song Queue

@@ -88,14 +38,14 @@ function StationPage() { Add Song
- +
{recommendedSongs.length === 0 ? (

No songs in queue yet. Add some songs to get started!

) : ( - recommendedSongs.map(song => ( + recommendedSongs.map((song) => (

{song.title}

diff --git a/frontend/src/utils/GetStations.js b/frontend/src/utils/GetStations.js index 21d954e..886f5c0 100644 --- a/frontend/src/utils/GetStations.js +++ b/frontend/src/utils/GetStations.js @@ -4,17 +4,22 @@ import { } from "../constants/ApiConstants"; export async function getStations() { - fetch(RADIOSTATION_URL + LIST_RADIOSTATIONS_ENDPOINT, { - method: "GET", - headers: { - "Content-Type": "application/json", - }, - }) - .then((response) => response.json()) - .then((data) => { - console.log("Station:", data); - }) - .catch((error) => { - console.error("Error creating station:", error); - }); + try { + const response = await fetch( + RADIOSTATION_URL + LIST_RADIOSTATIONS_ENDPOINT, + { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + } + ); + + const data = await response.json(); + console.log("Station:", data.data); + return data.data; + } catch (error) { + console.error("Error fetching stations:", error); + return []; + } } diff --git a/frontend/src/utils/StationsCreate.js b/frontend/src/utils/StationsCreate.js index 34ac305..7d5d31f 100644 --- a/frontend/src/utils/StationsCreate.js +++ b/frontend/src/utils/StationsCreate.js @@ -7,8 +7,8 @@ import { export async function createStation(name, description) { const body = { - name: "My Awesome Station", - description: "The best music station ever", + name: name, + description: description, }; fetch(RADIOSTATION_URL + CREATE_RADIOSTATION_ENDPOINT, { From fb355414ab09bfb33716b2f17a4bc1534dd7ee86 Mon Sep 17 00:00:00 2001 From: Noah Date: Sat, 2 Aug 2025 05:08:21 +0200 Subject: [PATCH 06/13] Added first steps towards user auth to the app --- frontend/src/App.jsx | 2 +- frontend/src/constants/ApiConstants.js | 1 + frontend/src/screens/JoinStation.jsx | 8 ++++-- frontend/src/screens/StationPage.jsx | 27 +++++++++++++++++-- frontend/src/utils/AddClientToStation.js | 33 ++++++++++++++++++++++++ 5 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 frontend/src/utils/AddClientToStation.js diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 465c9cb..df00a96 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -14,7 +14,7 @@ function App() { } /> } /> } /> - } /> + } />
diff --git a/frontend/src/constants/ApiConstants.js b/frontend/src/constants/ApiConstants.js index c7fd4b7..7cdec44 100644 --- a/frontend/src/constants/ApiConstants.js +++ b/frontend/src/constants/ApiConstants.js @@ -2,3 +2,4 @@ export const RADIOSTATION_URL = "http://localhost:8080/api"; export const CREATE_RADIOSTATION_ENDPOINT = "/radio-stations"; export const LIST_RADIOSTATIONS_ENDPOINT = "/radio-stations"; +export const ADD_CLIENT_ENDPOINT = "/clients/connect"; diff --git a/frontend/src/screens/JoinStation.jsx b/frontend/src/screens/JoinStation.jsx index ed2fff4..b1f4cc1 100644 --- a/frontend/src/screens/JoinStation.jsx +++ b/frontend/src/screens/JoinStation.jsx @@ -5,10 +5,13 @@ import { getStations } from "../utils/GetStations"; function JoinStation() { const navigate = useNavigate(); const [stations, setStations] = useState([]); + const [displayName, setDisplayName] = useState(""); const handleJoinStation = (stationID) => { - console.log("Joining station with ID:" + stationID); - navigate(`/station/${stationID}`); + // console.log("Joining station with ID:" + stationID); + if (!displayName) return; // USER HAS TO HAVE DISPLAY NAME + + navigate(`/station/${stationID}/${displayName}`); }; useEffect(() => { @@ -26,6 +29,7 @@ function JoinStation() {
+