From ddefa53b61f6580d6935214dce3373ec1e57964c Mon Sep 17 00:00:00 2001 From: ellawaal Date: Wed, 9 Sep 2026 14:22:29 +0200 Subject: [PATCH] =?UTF-8?q?Sl=C3=A5tt=20sammen=20filtrerings-=20og=20sorte?= =?UTF-8?q?ringslogikk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Løser konflikt fra stash pop av filtreringsendringer inn i sorteringsbranchen. --- src/App.tsx | 25 +++++++++++++++++++------ src/components/FilterSortBar.tsx | 28 ++++++++++++++++++---------- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 84122e5..107b02e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -9,10 +9,23 @@ import { useState } from "react"; function App() { const [currentSongIndex, setCurrentSongIndex] = useState(0) - const currentSong = songs[currentSongIndex] - + const [selectedAlbum, setSelectedAlbum] = useState('all') + const [sortBy, setSortBy] = useState('alphabetical') + const filteredSongs = songs.filter(song => selectedAlbum === 'all' || song.album === selectedAlbum) + const sortedSongs = [...filteredSongs].sort((a, b) => a.title.localeCompare(b.title)) + const currentSong = sortedSongs[currentSongIndex] + + const handleAlbumChange = (newAlbum: string) => { + setSelectedAlbum(newAlbum) + setCurrentSongIndex(0) + } + + const handleSortByChange = (newSort: string) => { + setSortBy(newSort) + } + const handleSelectSong = (song: (typeof songs)[number]) => { - const songIndex = songs.findIndex((item) => item.id === song.id) + const songIndex = sortedSongs.findIndex((item) => item.id === song.id) if (songIndex !== -1) { setCurrentSongIndex(songIndex) } @@ -26,8 +39,8 @@ function App() {
@@ -37,7 +50,7 @@ function App() { setCurrentSongIndex(currentSongIndex - 1)} onNext={() => setCurrentSongIndex(currentSongIndex + 1)} /> diff --git a/src/components/FilterSortBar.tsx b/src/components/FilterSortBar.tsx index 6db5a26..7e29af8 100644 --- a/src/components/FilterSortBar.tsx +++ b/src/components/FilterSortBar.tsx @@ -1,32 +1,40 @@ -export function FilterSortBar() { + +type FilterSortBarProps = { + selectedAlbum: string + onAlbumChange: (newAlbum: string) => void + sortBy: string + onSortByChange: (newSort: string) => void +} + +export function FilterSortBar({selectedAlbum, onAlbumChange, sortBy, onSortByChange}: FilterSortBarProps) { return (

Filtrer og sorter

- onSortByChange(e.target.value)}>
- onAlbumChange(e.target.value)}> - - - - + - - - + + +