Skip to content

Commit

Permalink
add context menu to top result
Browse files Browse the repository at this point in the history
  • Loading branch information
vixalien committed Oct 26, 2023
1 parent 2d809ee commit e6ec4de
Showing 1 changed file with 105 additions and 0 deletions.
105 changes: 105 additions & 0 deletions src/components/search/topresultcard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { DynamicActionState, DynamicImage } from "../dynamic-image";
import { pretty_subtitles } from "src/util/text.js";
import { get_player } from "src/application.js";
import { SignalListeners } from "src/util/signal-listener.js";
import { MenuHelper } from "src/util/menu.js";

GObject.type_ensure(DynamicImage.$gtype);

Expand Down Expand Up @@ -201,6 +202,8 @@ export class TopResultCard extends Adw.Bin {
this._image_stack.visible_child = show ? this._avatar : this.dynamic_image;
}

private menu_helper = MenuHelper.new(this);

private set_song_or_video(track: TopResultSong | TopResultVideo) {
this.result = track;

Expand All @@ -222,13 +225,45 @@ export class TopResultCard extends Adw.Bin {

this.dynamic_image.cover_thumbnails = song.thumbnails;
this.set_subtitle("Song", song.artists, [song.duration]);

this.menu_helper.props = [
[_("Start radio"), `queue.play-song("${song.videoId}?radio=true")`],
[_("Play next"), `queue.add-song("${song.videoId}?next=true")`],
[_("Add to queue"), `queue.add-song("${song.videoId}")`],
[_("Save to playlist"), `win.add-to-playlist("${song.videoId}")`],
song.album
? [
_("Go to album"),
`navigator.visit("muzika:album:${song.album.id}")`,
]
: null,
song.artists.length > 1
? [
_("Go to artist"),
`navigator.visit("muzika:artist:${song.artists[0].id}")`,
]
: null,
];
}

show_video(video: TopResultVideo) {
this.set_song_or_video(video);

this.dynamic_image.cover_thumbnails = video.thumbnails;
this.set_subtitle("Video", video.artists, [video.duration]);

this.menu_helper.props = [
[_("Start radio"), `queue.play-song("${video.videoId}?radio=true")`],
[_("Play next"), `queue.add-song("${video.videoId}?next=true")`],
[_("Add to queue"), `queue.add-song("${video.videoId}")`],
[_("Save to playlist"), `win.add-to-playlist("${video.videoId}")`],
video.artists && video.artists.length > 1
? [
_("Go to artist"),
`navigator.visit("muzika:artist:${video.artists[0].id}")`,
]
: null,
];
}

show_album(album: TopResultAlbum) {
Expand All @@ -243,6 +278,37 @@ export class TopResultCard extends Adw.Bin {

this._primary.sensitive = false;
this._secondary.sensitive = false;

this.menu_helper.props = [
album.shuffleId
? [
_("Shuffle play"),
`queue.play-playlist("${album.shuffleId}?next=true")`,
]
: null,
album.radioId
? [
_("Start radio"),
`queue.play-playlist("${album.radioId}?next=true")`,
]
: null,
// TODO: get album audioPlaylistId
// [
// _("Play next"),
// `queue.add-playlist("${album.audioPlaylistId}?next=true")`,
// ],
// [_("Add to queue"), `queue.add-playlist("${album.audioPlaylistId}")`],
// [
// _("Save to playlist"),
// `win.add-playlist-to-playlist("${album.audioPlaylistId}")`,
// ],
album.artists.length > 1
? [
_("Go to artist"),
`navigator.visit("muzika:artist:${album.artists[0].id}")`,
]
: null,
];
}

show_artist(artist: TopResultArtist) {
Expand Down Expand Up @@ -276,6 +342,21 @@ export class TopResultCard extends Adw.Bin {
} else {
this._secondary.sensitive = false;
}

this.menu_helper.props = [
artist.shuffleId
? [
_("Shuffle play"),
`queue.play-playlist("${artist.shuffleId}?next=true")`,
]
: null,
artist.radioId
? [
_("Start radio"),
`queue.play-playlist("${artist.radioId}?next=true")`,
]
: null,
];
}

show_playlist(playlist: TopResultPlaylist) {
Expand Down Expand Up @@ -307,6 +388,30 @@ export class TopResultCard extends Adw.Bin {
} else {
this._secondary.sensitive = false;
}

this.menu_helper.props = [
playlist.shuffleId
? [
_("Shuffle play"),
`queue.play-playlist("${playlist.shuffleId}?next=true")`,
]
: null,
playlist.radioId
? [
_("Start radio"),
`queue.play-playlist("${playlist.radioId}?next=true")`,
]
: null,
[
_("Play next"),
`queue.add-playlist("${playlist.browseId}?next=true")`,
],
[_("Add to queue"), `queue.add-playlist("${playlist.browseId}")`],
[
_("Save to playlist"),
`win.add-playlist-to-playlist("${playlist.browseId}")`,
],
];
}

show_top_result(top_result: TopResult) {
Expand Down

0 comments on commit e6ec4de

Please sign in to comment.