feat: add music library page with search, edit and delete

Add a Library page reachable from the navigation. It lists all songs
from the SQLite database, filters them by title or artist, edits title,
artist, license and attribution in a dialog, and deletes a song after a
confirmation prompt. File path, duration and source stay read-only.

LibraryController wraps SongRepository so the view only forwards user
actions. Changes are written to the database immediately, and the list
reloads every time the page is shown.

Refs #3

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
fraujulianandClaude Opus 5.5 committed 2026-11-23 10:24:12 +01:00
1 parent 89b7959404
commit faa1dc19cc
7 files changed
+357

No files matched your search

@@ -0,0 +1,63 @@
using System.Windows;
using System.Windows.Controls;
using Radiosender.Controllers;
using Radiosender.Models;
using Wpf.Ui.Controls;
using MessageBox = Wpf.Ui.Controls.MessageBox;
namespace Radiosender.Views.Pages;
public partial class LibraryPage : Page
{
private readonly LibraryController _controller = new(App.Songs);
public LibraryPage() => InitializeComponent();
private Song? Selected => SongList.SelectedItem as Song;
// Loaded fires on every navigation to the page, so the list is reloaded from the database each time.
private void OnLoaded(object sender, RoutedEventArgs e) => Refresh();
private void OnSearchChanged(object sender, TextChangedEventArgs e) => Refresh();
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e) =>
EditButton.IsEnabled = DeleteButton.IsEnabled = Selected is not null;
private void Refresh()
{
var songs = _controller.Search(SearchBox.Text);
SongList.ItemsSource = songs;
EmptyText.Visibility = songs.Count == 0 ? Visibility.Visible : Visibility.Collapsed;
}
private void OnEdit(object sender, RoutedEventArgs e)
{
if (Selected is not { } song)
return;
var dialog = new SongEditWindow(song) { Owner = Window.GetWindow(this) };
if (dialog.ShowDialog() == true)
_controller.Update(song.Id, dialog.SongTitle, dialog.Artist, dialog.License, dialog.Attribution);
Refresh();
}
private async void OnDelete(object sender, RoutedEventArgs e)
{
if (Selected is not { } song)
return;
var result = await new MessageBox
{
Title = "Delete song",
Content = $"Delete \"{song.Title}\" by {song.Artist} from the library?",
PrimaryButtonText = "Delete",
CloseButtonText = "Cancel",
}.ShowDialogAsync();
if (result != Wpf.Ui.Controls.MessageBoxResult.Primary)
return;
_controller.Delete(song.Id);
Refresh();
}
}