From e4640d998522f4aec28e50709b58cb7a3dfa968f Mon Sep 17 00:00:00 2001 From: geoffrey45 Date: Sun, 27 Mar 2022 18:22:35 +0300 Subject: [PATCH] [client] minor refactors --- src/assets/css/_variables.scss | 2 +- src/components/Notification.vue | 47 +++++++++++++++++++-------- src/components/contextMenu.vue | 9 ++--- src/components/modals/NewPlaylist.vue | 17 +++++++++- src/components/shared/SongItem.vue | 2 -- src/composables/playlists.ts | 43 ++++++++++++++++++++---- src/contexts/track_context.ts | 18 +++++----- src/interfaces.ts | 9 ++++- src/stores/enums.ts | 5 +++ src/stores/notification.ts | 33 ++++++++----------- 10 files changed, 128 insertions(+), 57 deletions(-) create mode 100644 src/stores/enums.ts diff --git a/src/assets/css/_variables.scss b/src/assets/css/_variables.scss index b6aae3f..8e9cd21 100644 --- a/src/assets/css/_variables.scss +++ b/src/assets/css/_variables.scss @@ -41,7 +41,7 @@ $accent: $indigo; $cta: $blue; $danger: $red; $track-hover: $gray4; -$context: $gray4; +$context: $gray5; // media query mixins @mixin phone-only { diff --git a/src/components/Notification.vue b/src/components/Notification.vue index cbaca4b..44d4675 100644 --- a/src/components/Notification.vue +++ b/src/components/Notification.vue @@ -1,30 +1,47 @@ diff --git a/src/components/contextMenu.vue b/src/components/contextMenu.vue index 8ed1d68..9d43f42 100644 --- a/src/components/contextMenu.vue +++ b/src/components/contextMenu.vue @@ -32,6 +32,7 @@ class="context-item" v-for="child in option.children" :key="child" + :class="[{ critical: child.critical }, child.type]" @click="child.action()" >
@@ -56,11 +57,11 @@ const context = useContextStore(); left: 0; width: 12rem; height: min-content; - z-index: 100000 !important; + z-index: 10; transform: scale(0); padding: $small; - background: $gray3; + background: $context; transform-origin: top left; font-size: 0.875rem; @@ -74,6 +75,7 @@ const context = useContextStore(); border-radius: $small; color: rgb(255, 255, 255); position: relative; + text-transform: capitalize; .more { height: 1.5rem; @@ -90,7 +92,7 @@ const context = useContextStore(); max-height: 21.25rem; padding: $small !important; - background: $gray3; + background-color: $context; transform: scale(0); transform-origin: left; } @@ -173,7 +175,6 @@ const context = useContextStore(); .context-normalizedY { .context-item > .children { - bottom: -0.5rem; transform-origin: bottom right; } } diff --git a/src/components/modals/NewPlaylist.vue b/src/components/modals/NewPlaylist.vue index 20c13f5..187a3ca 100644 --- a/src/components/modals/NewPlaylist.vue +++ b/src/components/modals/NewPlaylist.vue @@ -16,6 +16,12 @@ diff --git a/src/components/shared/SongItem.vue b/src/components/shared/SongItem.vue index 134d6a9..2dc974b 100644 --- a/src/components/shared/SongItem.vue +++ b/src/components/shared/SongItem.vue @@ -65,7 +65,6 @@ import perks from "../../composables/perks.js"; import state from "../../composables/state"; import useContextStore from "../../stores/context"; import useModalStore from "../../stores/modal"; -import usePlaylistStore from "../../stores/playlists"; import { ref } from "vue"; import trackContext from "../../contexts/track_context"; @@ -73,7 +72,6 @@ import { Track } from "../../interfaces.js"; const contextStore = useContextStore(); const modalStore = useModalStore(); -const playlistStore = usePlaylistStore(); const context_on = ref(false); diff --git a/src/composables/playlists.ts b/src/composables/playlists.ts index 2f6c9e4..7b1852d 100644 --- a/src/composables/playlists.ts +++ b/src/composables/playlists.ts @@ -1,25 +1,40 @@ import axios from "axios"; -import { Playlist } from "../interfaces"; -import { Notification, NotificationType } from "../stores/notification"; +import { Playlist, Track } from "../interfaces"; +import { Notification, NotifType } from "../stores/notification"; import state from "./state"; /** * Creates a new playlist on the server. * @param playlist_name The name of the playlist to create. */ -async function createNewPlaylist(playlist_name: string) { +async function createNewPlaylist(playlist_name: string, track?: Track) { + let status = false; + await axios .post(state.settings.uri + "/playlist/new", { name: playlist_name, }) - .then(() => { + .then((res) => { new Notification("✅ Playlist created successfullly!"); + + if (track) { + setTimeout(() => { + addTrackToPlaylist(res.data.playlist, track); + }, 1000); + } + + status = true; }) .catch((err) => { if (err.response.status == 409) { - new Notification("❌ Playlist already exists!", NotificationType.Error); + new Notification( + "That playlist already exists ... you might want to try another name!", + NotifType.Error + ); } }); + + return status; } /** @@ -43,4 +58,20 @@ async function getAllPlaylists(): Promise { return playlists; } -export { createNewPlaylist, getAllPlaylists }; +async function addTrackToPlaylist(playlist: Playlist, track: Track) { + const uri = `${state.settings.uri}/playlist/${playlist.playlistid}/add`; + console.log(track.trackid, playlist.playlistid); + + await axios + .post(uri, { track: track.trackid }) + .then(() => { + new Notification(track.title + " added to " + playlist.name); + }) + .catch((error) => { + if (error.response.status == 409) { + new Notification("Track already exists in playlist", NotifType.Info); + } + }); +} + +export { createNewPlaylist, getAllPlaylists, addTrackToPlaylist }; diff --git a/src/contexts/track_context.ts b/src/contexts/track_context.ts index 19bc6b9..556209e 100644 --- a/src/contexts/track_context.ts +++ b/src/contexts/track_context.ts @@ -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 => { + const separator: Option = { + type: "separator", + }; + const single_artist = track.artists.length === 1; let playlists = []; - const p = await getAllPlaylists(); playlists = p.map((playlist: Playlist) => { return