Changeset d1ee039 for frontend/src/components/playlist
- Timestamp:
- 02/15/26 23:28:14 (5 months ago)
- Branches:
- main
- Children:
- 615dcee, c807e22
- Parents:
- c8baad1
- Location:
- frontend/src/components/playlist
- Files:
-
- 2 edited
-
CreatePlaylistModal.tsx (modified) (2 diffs)
-
PlaylistDropdown.tsx (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
frontend/src/components/playlist/CreatePlaylistModal.tsx
rc8baad1 rd1ee039 8 8 onClose, 9 9 onSuccess, 10 songId, 10 11 }: CreatePlaylistModalProps) => { 11 12 const [playlistName, setPlaylistName] = useState(""); … … 39 40 setIsSubmitting(true); 40 41 try { 41 await axiosInstance.post( 42 `/playlists?playlistName=${encodeURIComponent(playlistName.trim())}`, 43 ); 42 await axiosInstance.post("/playlists", null, { 43 params: { 44 playlistName: playlistName.trim(), 45 ...(songId != null && { songId }), 46 }, 47 }); 48 44 49 toast.success("Playlist created successfully!"); 45 onSuccess();50 await onSuccess(); 46 51 handleClose(); 47 52 } catch (err: any) { -
frontend/src/components/playlist/PlaylistDropdown.tsx
rc8baad1 rd1ee039 3 3 import axiosInstance from "../../api/axiosInstance"; 4 4 import { useCreatedPlaylists } from "../../context/playlistContext"; 5 import CreatePlaylistModal from "./CreatePlaylistModal"; 5 6 6 7 interface PlaylistDropdownProps { … … 13 14 14 15 direction?: "above" | "below"; 15 16 onCreateNewPlaylist?: () => void;17 16 } 18 17 … … 24 23 usePortal = false, 25 24 direction = "above", 26 onCreateNewPlaylist,27 25 }: PlaylistDropdownProps) => { 28 26 const { createdPlaylists, refreshPlaylists } = useCreatedPlaylists(); … … 31 29 ); 32 30 const [loading, setLoading] = useState(false); 33 const [processingPlaylistId, setProcessingPlaylistId] = useState< 34 number | null 35 >(null); 31 const [processingIds, setProcessingIds] = useState<Set<number>>(new Set()); 32 const [isModalOpen, setIsModalOpen] = useState(false); 36 33 const dropdownRef = useRef<HTMLDivElement>(null); 37 34 … … 75 72 76 73 const handleTogglePlaylist = async (playlistId: number, songId: number) => { 77 if (processing PlaylistId !== null) return;78 79 setProcessing PlaylistId(playlistId);74 if (processingIds.has(playlistId)) return; 75 76 setProcessingIds((prev) => new Set(prev).add(playlistId)); 80 77 81 78 try { … … 104 101 refreshPlaylists(true); 105 102 setTimeout(() => { 106 setProcessingPlaylistId(null); 103 setProcessingIds((prev) => { 104 const next = new Set(prev); 105 next.delete(playlistId); 106 return next; 107 }); 107 108 }, 500); 108 109 } … … 110 111 111 112 const handleCreateNew = () => { 112 onCreateNewPlaylist?.();113 113 onClose(); 114 setIsModalOpen(true); 114 115 }; 115 116 116 if (!isOpen) return null; 117 const handleModalSuccess = async () => { 118 await refreshPlaylists(false); 119 }; 117 120 118 121 const inlinePositionClass = … … 121 124 : "absolute right-0 bottom-full mb-2"; 122 125 123 const dropdownContent = (126 const dropdownContent = !isOpen ? null : ( 124 127 <div 125 128 ref={dropdownRef} 126 className={`${usePortal ? "fixed" : inlinePositionClass} w-56 bg-[#282828] rounded-lg shadow-2xl py-2 z- [9999]border border-white/10 max-h-60 overflow-y-auto custom-scrollbar`}129 className={`${usePortal ? "fixed" : inlinePositionClass} w-56 bg-[#282828] rounded-lg shadow-2xl py-2 z-9999 border border-white/10 max-h-60 overflow-y-auto custom-scrollbar`} 127 130 style={ 128 131 usePortal && position … … 147 150 ) : createdPlaylists && createdPlaylists.length > 0 ? ( 148 151 createdPlaylists.map((playlist) => { 149 const isProcessing = processing PlaylistId === playlist.id;152 const isProcessing = processingIds.has(playlist.id); 150 153 const isChecked = containingPlaylistIds.includes(playlist.id); 151 154 … … 153 156 <label 154 157 key={playlist.id} 155 className={`flex items-center px-4 py-2 hover:bg-white/10 transition-colors group/item ${158 className={`flex items-center gap-1.5 px-4 py-2 hover:bg-white/10 transition-colors group/item ${ 156 159 isProcessing ? "pointer-events-none" : "cursor-pointer" 157 160 }`} 158 161 onClick={(e) => e.stopPropagation()} 159 162 > 160 <div className="relative flex items-center justify-center ">163 <div className="relative flex items-center justify-center shrink-0"> 161 164 <input 162 165 type="checkbox" 163 166 className="peer sr-only" 164 167 checked={isChecked} 165 disabled={ processingPlaylistId !== null}168 disabled={isProcessing} 166 169 onChange={() => handleTogglePlaylist(playlist.id, songId)} 167 170 /> … … 172 175 : isChecked 173 176 ? "bg-[#1db954] border-[#1db954]" 174 : "border-gray-500 "177 : "border-gray-500 text=wjot" 175 178 }`} 176 179 > … … 182 185 </div> 183 186 <svg 184 className={`absolute w-3 h-3 transition-opacity ${187 className={`absolute w-3 h-3 transition-opacity ${ 185 188 isChecked && !isProcessing ? "opacity-100" : "opacity-0" 186 189 }`} 187 190 fill="none" 188 stroke=" currentColor"191 stroke="white" 189 192 strokeWidth="3" 190 193 viewBox="0 0 24 24" … … 198 201 </div> 199 202 <span 200 className={` ml-3text-sm truncate transition-all ${203 className={`text-sm truncate transition-all ${ 201 204 isProcessing 202 205 ? "text-[#1db954] animate-pulse" … … 206 209 {playlist.name} 207 210 </span> 208 {isProcessing && (209 <span className="ml-auto text-xs text-[#1db954] animate-pulse">210 •••211 </span>212 )}213 211 </label> 214 212 ); … … 245 243 ); 246 244 247 return usePortal 248 ? createPortal(dropdownContent, document.body) 249 : dropdownContent; 245 const dropdown = dropdownContent 246 ? usePortal 247 ? createPortal(dropdownContent, document.body) 248 : dropdownContent 249 : null; 250 251 return ( 252 <> 253 {dropdown} 254 {createPortal( 255 <CreatePlaylistModal 256 isOpen={isModalOpen} 257 onClose={() => setIsModalOpen(false)} 258 onSuccess={handleModalSuccess} 259 songId={songId} 260 />, 261 document.body, 262 )} 263 </> 264 ); 250 265 }; 251 266
Note:
See TracChangeset
for help on using the changeset viewer.
