From 8fa9c0b76245085552bda6d4e91c1bdd555c10ed Mon Sep 17 00:00:00 2001 From: h7x4 Date: Mon, 23 Dec 2024 13:08:17 +0100 Subject: [PATCH] Allow load/remove commands to take multiple entries at once --- lib/api/commands.dart | 8 ++++---- lib/player_ui/body.dart | 10 ++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/api/commands.dart b/lib/api/commands.dart index 671c195..ca5c8ec 100644 --- a/lib/api/commands.dart +++ b/lib/api/commands.dart @@ -52,11 +52,11 @@ class Command extends PlayerConnectionEvent { // ); // } - factory Command.load(String url) { + factory Command.load(List urls) { return Command( type: 'load', value: { - 'url': url, + 'urls': urls, }, ); } @@ -116,11 +116,11 @@ class Command extends PlayerConnectionEvent { ); } - factory Command.playlistRemove(int position) { + factory Command.playlistRemove(List positions) { return Command( type: 'playlist_remove', value: { - 'position': position, + 'positions': positions, }, ); } diff --git a/lib/player_ui/body.dart b/lib/player_ui/body.dart index 268bf04..aebd9b6 100644 --- a/lib/player_ui/body.dart +++ b/lib/player_ui/body.dart @@ -107,7 +107,7 @@ class PlayerUIBody extends StatelessWidget { color: Colors.redAccent, onPressed: () { BlocProvider.of(context) - .add(Command.playlistRemove(i)); + .add(Command.playlistRemove([i])); }, ), ], @@ -133,7 +133,7 @@ class PlayerUIBody extends StatelessWidget { ), onSubmitted: (value) { BlocProvider.of(context) - .add(Command.load(value)); + .add(Command.load([value])); _textController.clear(); }, ), @@ -144,7 +144,7 @@ class PlayerUIBody extends StatelessWidget { tooltip: 'Add link to playlist', onPressed: () { BlocProvider.of(context) - .add(Command.load(_textController.text)); + .add(Command.load([_textController.text])); _textController.clear(); }, ), @@ -159,9 +159,7 @@ class PlayerUIBody extends StatelessWidget { return; } - for (final link in links.split('\n')) { - blocProvider.add(Command.load(link)); - } + blocProvider.add(Command.load(links.split('\n'))); }, ), ],