Skip to content

Commit

Permalink
Update all explore #27
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhonatanjacome07 committed Dec 5, 2024
1 parent 518a3f6 commit d0adcb5
Show file tree
Hide file tree
Showing 26 changed files with 565 additions and 67 deletions.
Binary file added frontend/public/songs/1.mp3
Binary file not shown.
Binary file added frontend/public/songs/10.mp3
Binary file not shown.
Binary file added frontend/public/songs/11.mp3
Binary file not shown.
Binary file added frontend/public/songs/12.mp3
Binary file not shown.
Binary file added frontend/public/songs/13.mp3
Binary file not shown.
Binary file added frontend/public/songs/14.mp3
Binary file not shown.
Binary file added frontend/public/songs/15.mp3
Binary file not shown.
Binary file added frontend/public/songs/16.mp3
Binary file not shown.
Binary file added frontend/public/songs/17.mp3
Binary file not shown.
Binary file added frontend/public/songs/18.mp3
Binary file not shown.
Binary file added frontend/public/songs/2.mp3
Binary file not shown.
Binary file added frontend/public/songs/3.mp3
Binary file not shown.
Binary file added frontend/public/songs/4.mp3
Binary file not shown.
Binary file added frontend/public/songs/5.mp3
Binary file not shown.
Binary file added frontend/public/songs/6.mp3
Binary file not shown.
Binary file added frontend/public/songs/7.mp3
Binary file not shown.
Binary file added frontend/public/songs/8.mp3
Binary file not shown.
Binary file added frontend/public/songs/9.mp3
Binary file not shown.
8 changes: 7 additions & 1 deletion frontend/src/app/(page)/explore/components/SongItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ import Image from "next/image";
import { Heart } from "lucide-react";

interface SongItemProps {
id: string;
title: string;
title_short: string;
duration: string;
preview: string;
md5_image: string;
artist: string;
genre: string;
duration: string;

isSelected: boolean;
isFavorite: boolean;

onFavoriteToggle: () => void;
onPlay: () => void;
}
Expand Down
95 changes: 71 additions & 24 deletions frontend/src/app/(page)/explore/components/SongList.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SongList.tsx
import React, { useState } from "react";
import React, { useState, useCallback } from "react";
import SongItem from "./SongItem";
import Player from "@/components/ui/Player";
import { useFilterSongs } from "@/hooks/useFilterSongs";
import { mockSongs } from "@/data/mockSongs";
import { Song } from "@/types/ui/Song";
import { formatDuration } from "@/app/utils/formatDuration";

interface SongListProps {
searchTerm?: string;
Expand All @@ -18,42 +18,89 @@ export default function SongList({
const [selectedSong, setSelectedSong] = useState<Song | null>(null);
const [isPlaying, setIsPlaying] = useState(false);
const [songs, setSongs] = useState<Song[]>(mockSongs);

const filteredSongs = useFilterSongs(songs, searchTerm, selectedGenre);

const handlePlay = (song: Song) => {
setSelectedSong(song);
setIsPlaying(true);
};
const handlePlay = useCallback(
(song: Song) => {
if (selectedSong?.id === song.id) {
setIsPlaying(!isPlaying);
} else {
setSelectedSong(song);
setIsPlaying(true);
}
},
[selectedSong, isPlaying]
);

const handlePlayPause = useCallback(() => {
setIsPlaying(!isPlaying);
}, [isPlaying]);

const handleNext = useCallback(() => {
if (!selectedSong) return;
const currentIndex = filteredSongs.findIndex(
(song) => song.id === selectedSong.id
);
if (currentIndex < filteredSongs.length - 1) {
setSelectedSong(filteredSongs[currentIndex + 1]);
setIsPlaying(true);
}
}, [selectedSong, filteredSongs]);

const handlePrevious = useCallback(() => {
if (!selectedSong) return;
const currentIndex = filteredSongs.findIndex(
(song) => song.id === selectedSong.id
);
if (currentIndex > 0) {
setSelectedSong(filteredSongs[currentIndex - 1]);
setIsPlaying(true);
}
}, [selectedSong, filteredSongs]);

const toggleFavorite = (songId: string) => {
const toggleFavorite = useCallback((songId: string) => {
setSongs((prevSongs) =>
prevSongs.map((song) =>
song.id === songId ? { ...song, isFavorite: !song.isFavorite } : song
)
);
};
}, []);

return (
<div className="w-full">
{filteredSongs.map((song) => (
<SongItem
key={song.id}
title={song.title}
artist={song.artist}
genre={song.genre}
duration={song.duration}
isFavorite={song.isFavorite}
isSelected={selectedSong?.id === song.id}
onPlay={() => handlePlay(song)}
onFavoriteToggle={() => toggleFavorite(song.id)}
/>
))}
<div className="mb-24">
{filteredSongs.map((song) => (
<SongItem
key={song.id}
id={song.id}
title={song.title}
title_short={song.title_short}
genre={song.genre}
duration={formatDuration(song.duration)}
md5_image={song.md5_image}
preview={song.preview}
artist={song.artist.name}
isFavorite={song.isFavorite}
isSelected={selectedSong?.id === song.id}
onPlay={() => handlePlay(song)}
onFavoriteToggle={() => toggleFavorite(song.id)}
/>
))}
</div>
{selectedSong && (
<Player
currentSong={selectedSong}
currentSong={{
...selectedSong,
artist: selectedSong.artist.name, // Asegúrate de usar el nombre
}}
isFavorite={selectedSong.isFavorite}
isPlaying={isPlaying}
onPlayPause={() => setIsPlaying(!isPlaying)}
onPlayPause={handlePlayPause}
onNext={handleNext}
onPrevious={handlePrevious}
onFavoriteToggle={() =>
selectedSong && toggleFavorite(selectedSong.id)
}
/>
)}
</div>
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/app/utils/formatDuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function formatDuration(durationInSeconds: string): string {
const totalSeconds = parseInt(durationInSeconds, 10);
const minutes = Math.floor(totalSeconds / 60);
const seconds = totalSeconds % 60;
return `${minutes}:${seconds.toString().padStart(2, "0")}`;
}
2 changes: 1 addition & 1 deletion frontend/src/components/ui/GenroButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface GenreButtonsProps {

const genres = [
"Todos",
"Electronica",
"Electrónica",
"Pop",
"Rock",
"Rap",
Expand Down
Loading

0 comments on commit d0adcb5

Please sign in to comment.