Skip to content

Commit

Permalink
fix: "Add () to Playlist" option not showing in favorited playlists #904
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Nov 27, 2023
1 parent 96e0e86 commit 96021e1
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 34 deletions.
8 changes: 6 additions & 2 deletions lib/components/shared/dialogs/playlist_add_track_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import 'package:spotube/services/queries/queries.dart';
import 'package:spotube/utils/type_conversion_utils.dart';

class PlaylistAddTrackDialog extends HookConsumerWidget {
/// The id of the playlist this dialog was opened from
final String? openFromPlaylist;
final List<Track> tracks;
const PlaylistAddTrackDialog({
required this.tracks,
required this.openFromPlaylist,
Key? key,
}) : super(key: key);

Expand All @@ -30,11 +33,12 @@ class PlaylistAddTrackDialog extends HookConsumerWidget {
?.where(
(playlist) =>
playlist.owner?.id != null &&
playlist.owner!.id == me.data?.id,
playlist.owner!.id == me.data?.id &&
playlist.id != openFromPlaylist,
)
.toList() ??
[],
[userPlaylists.data, me.data?.id],
[userPlaylists.data, me.data?.id, openFromPlaylist],
);

final playlistsCheck = useState(<String, bool>{});
Expand Down
6 changes: 5 additions & 1 deletion lib/components/shared/track_tile/track_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,15 @@ class TrackOptions extends HookConsumerWidget {
});
}

void actionAddToPlaylist(BuildContext context, Track track) {
void actionAddToPlaylist(
BuildContext context,
Track track,
) {
showDialog(
context: context,
builder: (context) => PlaylistAddTrackDialog(
tracks: [track],
openFromPlaylist: playlistId,
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class TrackViewBodySection extends HookConsumerWidget {
final playlist = ref.watch(ProxyPlaylistNotifier.provider);
final playlistNotifier = ref.watch(ProxyPlaylistNotifier.notifier);
final props = InheritedTrackView.of(context);
final trackViewState = ref.watch(trackViewProvider(props.tracks));

final searchController = useTextEditingController();
final searchFocus = useFocusNode();
Expand All @@ -38,8 +39,6 @@ class TrackViewBodySection extends HookConsumerWidget {
return props.tracks.where((e) => trackIds.remove(e.id)).toList();
}, [props.tracks]);

final trackViewState = ref.watch(trackViewProvider(uniqTracks));

final tracks = useMemoized(() {
List<Track> filteredTracks;
if (searchQuery.isEmpty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,16 @@ class TrackViewBodyHeaders extends HookConsumerWidget {
),
);
},
child: trackViewState.isSelecting
? Checkbox(
value: trackViewState.hasSelectedAll,
onChanged: (checked) {
if (checked == true) {
trackViewState.selectAll();
} else {
trackViewState.deselectAll();
}
},
)
: constrains.mdAndUp
? const SizedBox(width: 32)
: const SizedBox(width: 16),
child: Checkbox(
value: trackViewState.hasSelectedAll,
onChanged: (checked) {
if (checked == true) {
trackViewState.selectAll();
} else {
trackViewState.deselectAll();
}
},
),
),
Expanded(
flex: 7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import 'package:spotube/provider/download_manager_provider.dart';
import 'package:spotube/provider/proxy_playlist/proxy_playlist_provider.dart';
import 'package:spotube/provider/user_preferences/user_preferences_provider.dart';
import 'package:spotube/provider/user_preferences/user_preferences_state.dart';
import 'package:spotube/services/queries/queries.dart';

class TrackViewBodyOptions extends HookConsumerWidget {
const TrackViewBodyOptions({Key? key}) : super(key: key);
Expand All @@ -30,11 +29,6 @@ class TrackViewBodyOptions extends HookConsumerWidget {
final trackViewState = ref.watch(trackViewProvider(props.tracks));
final selectedTracks = trackViewState.selectedTracks;

final userPlaylists = useQueries.playlist.ofMineAll(ref);

final isUserPlaylist =
userPlaylists.data?.any((e) => e.id == props.collectionId) ?? false;

return AdaptivePopSheetList(
tooltip: context.l10n.more_actions,
headings: [
Expand Down Expand Up @@ -66,6 +60,7 @@ class TrackViewBodyOptions extends HookConsumerWidget {
context: context,
builder: (context) {
return PlaylistAddTrackDialog(
openFromPlaylist: props.collectionId,
tracks: selectedTracks.toList(),
);
},
Expand Down Expand Up @@ -100,15 +95,14 @@ class TrackViewBodyOptions extends HookConsumerWidget {
context.l10n.download_count(selectedTracks.length),
),
),
if (!isUserPlaylist)
PopSheetEntry(
value: "add-to-playlist",
leading: const Icon(SpotubeIcons.playlistAdd),
enabled: selectedTracks.isNotEmpty,
title: Text(
context.l10n.add_count_to_playlist(selectedTracks.length),
),
PopSheetEntry(
value: "add-to-playlist",
leading: const Icon(SpotubeIcons.playlistAdd),
enabled: selectedTracks.isNotEmpty,
title: Text(
context.l10n.add_count_to_playlist(selectedTracks.length),
),
),
PopSheetEntry(
enabled: selectedTracks.isNotEmpty,
value: "add-to-queue",
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class SpotubeState extends ConsumerState<Spotube> {
Brightness.dark,
isAmoledTheme,
),
[paletteColor, accentMaterialColor, isAmoledTheme],

);

return MaterialApp.router(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class PlaylistGenerateResultPage extends HookConsumerWidget {
context: context,
builder: (context) =>
PlaylistAddTrackDialog(
openFromPlaylist: null,
tracks: selectedTracks.value
.map(
(e) => generatedPlaylist.data!
Expand Down
3 changes: 3 additions & 0 deletions lib/themes/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,8 @@ ThemeData theme(Color seed, Brightness brightness, bool isAmoled) {
scrollbarTheme: const ScrollbarThemeData(
thickness: MaterialStatePropertyAll(14),
),
checkboxTheme: CheckboxThemeData(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
),
);
}

0 comments on commit 96021e1

Please sign in to comment.