11<script >
2- // @ts-nocheck
3-
4- import { isPlaying , currentSong ,
5- playPercentage , setCurrentTime ,
6- nextSong , previousSong ,
7- isShuffledEnabled , isLoopingEnabled ,
8- toggleShuffle , playOrPauseSong ,
9- toggleLoop , isLoading } from " ../scripts/playbackService" ;
10- import { getImageUrl } from " ../scripts/api" ;
2+ // @ts-nocheck
3+
4+ import { isPlaying , currentSong , playPercentage , setCurrentTime , nextSong , previousSong , isShuffledEnabled , isLoopingEnabled , toggleShuffle , playOrPauseSong , toggleLoop , isLoading } from " ../scripts/playbackService" ;
5+ import { getImageUrl , createPlaylist } from " ../scripts/api" ;
116 import { get } from " svelte/store" ;
127 import { isTimerEnabled , timeLeft , toggleSleepTimer } from " ../scripts/sleeptimerService" ;
138
1813 $: $isLoopingEnabled;
1914 $: $isTimerEnabled;
2015 $: $timeLeft;
21- $: $isLoading
22-
16+ $: $isLoading;
17+
2318 function togglePlay () {
2419 playOrPauseSong (get (currentSong).id );
2520 }
3530 setCurrentTime (newTime);
3631 }
3732 }
33+
34+ async function handleCreatePlaylistSubmit (e ) {
35+ event .preventDefault ();
36+ const formData = new FormData (event .target );
37+ var response = await createPlaylist (formData);
38+
39+ if (response .success ){
40+ alert (` Playlist has been created successfully.` );
41+
42+ // Close modal
43+ const modalElement = document .getElementById (' createPlaylistModal' );
44+ const modalInstance = bootstrap .Modal .getInstance (modalElement);
45+ modalInstance .hide ();
46+
47+ // clear form
48+ event .target .reset ();
49+
50+ } else {
51+ alert (` Failed to create playlist: ${ response .data } ` );
52+ }
53+ }
3854 </script >
3955
40- <!-- Modal -->
41- {#if $currentSong && $currentSong .id !== - 999 } <!-- Ensure currentSong is valid -->
56+ <!-- Play Modal -->
57+ {#if $currentSong && $currentSong .id !== - 999 }
58+ <!-- Ensure currentSong is valid -->
4259 <div class =" modal fade" id =" songControlModal" tabindex =" -1" aria-labelledby =" songControlModalLabel" aria-hidden =" false" >
4360 <div class =" modal-dialog modal-fullscreen-sm-down" >
4461 <div class =" modal-content" >
4764 <div class =" row" >
4865 <div class =" col-12" >
4966 <div class =" container-fluid" style =" height: 7rem;" >
50- <p class ="text-white" id ="songControlModalLabel" >{$currentSong .name }</p >
67+ <p class ="text-white" id ="songControlModalLabel" >{$currentSong .name }</p >
5168 </div >
5269 </div >
5370 <div class =" col-12 text-center" >
88105 <div class =" row mt-5" >
89106 <div class =" col-4" >
90107 <button on:click ={toggleSleepTimer } aria-label =" sleep timer" type =" button" class =" btn w-100" >
91- <i class ="fa-solid fa-stopwatch-20" style =" {$isTimerEnabled ? " color: #1CC558;" : " color:#ACACAC;" }" >
108+ <i class ="fa-solid fa-stopwatch-20" style ={$isTimerEnabled ? " color: #1CC558;" : " color:#ACACAC;" }>
92109 <span style =" font-size: 0.8rem;" >
93- {$isTimerEnabled ? $timeLeft : " " }
94- </span >
95- </i >
110+ {$isTimerEnabled ? $timeLeft : " " }
111+ </span >
112+ </i >
96113 </button >
97114 </div >
98115
99116 <div class =" col-4" >
100117 <button on:click ={toggleShuffle } aria-label =" shuffle playlist" type =" button" class =" btn w-100" >
101- <i class ="fa-solid fa-shuffle" style =" {$isShuffledEnabled ? " color: #1CC558;" : " color:#ACACAC;" }" ></i >
118+ <i class ="fa-solid fa-shuffle" style ={$isShuffledEnabled ? " color: #1CC558;" : " color:#ACACAC;" }></i >
102119 </button >
103120 </div >
104121 <div class =" col-4" >
105122 <button on:click ={toggleLoop } aria-label =" repeat song" type =" button" class =" btn w-100" >
106- <i class ="fa-solid fa-repeat" style =" {$isLoopingEnabled ? " color: #1CC558;" : " color:#ACACAC;" }" ></i >
123+ <i class ="fa-solid fa-repeat" style ={$isLoopingEnabled ? " color: #1CC558;" : " color:#ACACAC;" }></i >
107124 </button >
108125 </div >
109126 </div >
119136 </div >
120137{/if }
121138
139+ <!-- Create Playlist Modal -->
140+ <div class =" modal fade" id =" createPlaylistModal" tabindex =" -1" aria-labelledby =" createPlaylistModalLabel" aria-hidden =" false" >
141+ <div class =" modal-dialog modal-fullscreen-sm-down" >
142+ <div class =" modal-content" >
143+ <div class =" modal-body" >
144+ <form on:submit |preventDefault ={handleCreatePlaylistSubmit } class =" p-2 rounded rounded-2 tile-bg" >
145+ <div class =" mb-3" >
146+ <label for =" playlistName" class =" form-label" >Playlist Name</label >
147+ <input type =" text" required class =" form-control form-control-sm" id =" playlistName" name =" playlistName" placeholder =" Name of newly created playlist" />
148+ </div >
149+ <div class =" mt-3 mb-3 p-2 rounded rounded-2 tile-bg" >
150+ <label for =" backgroundImage" class =" form-label" >Playlist Image (leave blank for default)</label >
151+ <input type =" file" id =" backgroundImage" name =" backgroundImage" class =" form-file-input form-control-sm" />
152+ </div >
153+ <div class =" mt-3 mb-3 p-2 rounded rounded-2 tile-bg" >
154+ <label for =" publicPlaylist" class =" form-label" >Public</label >
155+ <input type =" checkbox" checked id =" publicPlaylist" name =" publicPlaylist" class =" form-check-input" />
156+ </div >
157+ <div class =" mt-3 mb-3 p-2 rounded rounded-2 tile-bg" >
158+ <label for =" playlistDescription" class =" form-label" >Description</label >
159+ <textarea id =" playlistDescription" name =" playlistDescription" rows =" 3" class =" form-control form-control-sm" > </textarea >
160+ </div >
161+ <button type =" submit" class =" btn btn-primary" >Create Playlist</button >
162+ </form >
163+ </div >
164+ <div class =" modal-footer" >
165+ <button type =" button" class =" btn btn-dark w-100 text-white" data-bs-dismiss =" modal" >Close</button >
166+ </div >
167+ </div >
168+ </div >
169+ </div >
170+
122171<style >
172+ .tile-bg {
173+ background-color : #2c2c2c ;
174+ }
123175 img {
124176 height : 10rem ;
125177 object-fit : contain ;
126178 box-shadow : 0 6px 18px rgba (0 , 0 , 0 , 0.55 );
127179 border : 1px solid rgba (0 , 0 , 0 , 0.35 );
128180 }
129181
130- p {
182+ p {
131183 font-size : 1rem !important ;
132184 font-weight : bolder ;
133185 color : white ;
134186 text-align : center ;
135187 }
136188
137- i {
189+ i {
138190 font-size : 1.2rem ;
139- color : #ACACAC ;
191+ color : #acacac ;
140192 font-weight : bolder ;
141193 }
142194
143- .modal-footer {
195+ .modal-footer {
144196 border : none !important ;
145197 }
146198
147199 .modal-footer button {
148200 background-color : #2c2c2c !important ;
149201 }
150202
203+ input [type = " range" ]::-webkit-slider-thumb {
204+ background-color : #1db954 ;
205+ }
151206
152- input [type = " range" ]::-webkit-slider-thumb {
153- background-color : #1DB954 ;
154- }
155-
156- input [type = " range" ]::-webkit-slider-runnable-track {
157- background-color : #ACACAC ;
158- }
207+ input [type = " range" ]::-webkit-slider-runnable-track {
208+ background-color : #acacac ;
209+ }
159210
160- .modal-content {
211+ .modal-content {
161212 background-color : #1e1e1e !important ;
162213 color : white ;
163214 }
@@ -167,6 +218,6 @@ input[type="range"]::-webkit-slider-runnable-track {
167218 }
168219
169220 .form-range {
170- color : #1DB954 ;
221+ color : #1db954 ;
171222 }
172223 </style >
0 commit comments