[client] minor refactors

This commit is contained in:
geoffrey45
2022-03-27 18:22:35 +03:00
parent 9ada6c9058
commit e4640d9985
10 changed files with 128 additions and 57 deletions
+8 -10
View File
@@ -1,7 +1,7 @@
import { Playlist, Track } from "../interfaces";
import Router from "../router";
import { Option } from "../interfaces";
import { getAllPlaylists } from "../composables/playlists";
import { getAllPlaylists, addTrackToPlaylist } from "../composables/playlists";
/**
* Returns a list of context menu items for a track.
@@ -11,17 +11,20 @@ import { getAllPlaylists } from "../composables/playlists";
*/
export default async (track: Track, modalStore: any): Promise<Option[]> => {
const separator: Option = {
type: "separator",
};
const single_artist = track.artists.length === 1;
let playlists = <Option[]>[];
const p = await getAllPlaylists();
playlists = p.map((playlist: Playlist) => {
return <Option>{
label: playlist.name,
action: () => {
console.log(playlist.name);
addTrackToPlaylist(playlist, track);
},
};
});
@@ -43,12 +46,11 @@ export default async (track: Track, modalStore: any): Promise<Option[]> => {
const new_playlist = <Option>{
label: "New playlist",
action: () => {
modalStore.showModal(modalStore.options.newPlaylist);
modalStore.showNewPlaylistModal(track);
},
};
console.log([new_playlist, ...playlists]);
return [new_playlist, ...playlists];
return [new_playlist, separator, ...playlists];
}
const add_to_playlist: Option = {
@@ -115,10 +117,6 @@ export default async (track: Track, modalStore: any): Promise<Option[]> => {
icon: "heart",
};
const separator: Option = {
type: "separator",
};
const options: Option[] = [
add_to_playlist,
add_to_q,