From 4a8ce6fd9ff9ee18dfd7e5e3dcfe4996135e5af1 Mon Sep 17 00:00:00 2001 From: ellawaal Date: Wed, 9 Sep 2026 12:54:12 +0200 Subject: [PATCH] Implementert filtreringslogikk for album --- src/App.tsx | 18 +++++++++++++----- src/components/FilterSortBar.tsx | 24 +++++++++++++++--------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 84122e5..b8fba69 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -9,10 +9,18 @@ import { useState } from "react"; function App() { const [currentSongIndex, setCurrentSongIndex] = useState(0) - const currentSong = songs[currentSongIndex] + const [selectedAlbum, setSelectedAlbum] = useState('all') + const filteredSongs = songs.filter(song => selectedAlbum === 'all' || song.album === selectedAlbum) + const currentSong = filteredSongs[currentSongIndex] + + const handleAlbumChange = (newAlbum: string) => { + setSelectedAlbum(newAlbum) + setCurrentSongIndex(0) + } + const handleSelectSong = (song: (typeof songs)[number]) => { - const songIndex = songs.findIndex((item) => item.id === song.id) + const songIndex = filteredSongs.findIndex((item) => item.id === song.id) if (songIndex !== -1) { setCurrentSongIndex(songIndex) } @@ -26,8 +34,8 @@ function App() {
@@ -37,7 +45,7 @@ function App() { setCurrentSongIndex(currentSongIndex - 1)} onNext={() => setCurrentSongIndex(currentSongIndex + 1)} /> diff --git a/src/components/FilterSortBar.tsx b/src/components/FilterSortBar.tsx index 6db5a26..1a1b8dd 100644 --- a/src/components/FilterSortBar.tsx +++ b/src/components/FilterSortBar.tsx @@ -1,4 +1,10 @@ -export function FilterSortBar() { + +type FilterSortBarProps = { + selectedAlbum: string + onAlbumChange: (newAlbum: string) => void +} + +export function FilterSortBar({selectedAlbum, onAlbumChange}: FilterSortBarProps) { return (

Filtrer og sorter

@@ -12,21 +18,21 @@ export function FilterSortBar() {
- onAlbumChange(e.target.value)}> - - - - + - - - + + +