From ceedc228433dc1ecad9be91f169cd9ba1ac3952c Mon Sep 17 00:00:00 2001 From: geoffrey45 Date: Fri, 13 Jan 2023 15:53:36 +0300 Subject: [PATCH] add functionality to adjust image position --- src/components/PlaylistView/Header.vue | 6 ++- src/components/modals/updatePlaylist.vue | 59 +++++++++++++++++++---- src/components/shared/TrackItem.vue | 3 +- src/composables/fetch/playlists.ts | 45 ++++++++++++------ src/interfaces.ts | 2 + src/stores/pages/playlist.ts | 11 +++++ src/views/PlaylistList.vue | 7 +-- src/views/PlaylistView/index.vue | 18 +++++-- yarn.lock | 60 ++++++++++++------------ 9 files changed, 146 insertions(+), 65 deletions(-) diff --git a/src/components/PlaylistView/Header.vue b/src/components/PlaylistView/Header.vue index ab0af21..59138c2 100644 --- a/src/components/PlaylistView/Header.vue +++ b/src/components/PlaylistView/Header.vue @@ -5,6 +5,7 @@ :style="[ { backgroundImage: info.image ? `url(${imguri + info.image})` : undefined, + backgroundPosition: `center ${bannerPos}%`, }, ]" :class="{ border: !info.image }" @@ -28,7 +29,7 @@ Last updated {{ info.last_updated }}  |   - Edit  | +
Edit  |
@@ -56,7 +57,7 @@ const playlist = usePStore(); const imguri = paths.images.playlist; const playlistheader = ref(null); -const { info } = storeToRefs(playlist); +const { info, bannerPos } = storeToRefs(playlist); useVisibility(playlistheader, nav.toggleShowPlay); @@ -76,6 +77,7 @@ function deletePlaylist() { height: $banner-height; position: relative; background-color: $gray5; + background-position: center 50%; .gradient { position: absolute; diff --git a/src/components/modals/updatePlaylist.vue b/src/components/modals/updatePlaylist.vue index 7219008..5b0241c 100644 --- a/src/components/modals/updatePlaylist.vue +++ b/src/components/modals/updatePlaylist.vue @@ -23,7 +23,7 @@ @change="handleUpload" ref="dropZoneRef" /> -
+
Click to upload cover image
+ + @@ -45,12 +57,14 @@ import { onMounted, ref } from "vue"; // import { useDropZone } from "@vueuse/core"; -import { updatePlaylist } from "@/composables/fetch/playlists"; import { paths } from "@/config"; import { Playlist } from "@/interfaces"; import usePStore from "@/stores/pages/playlist"; +import { updatePlaylist } from "@/composables/fetch/playlists"; +import ExpandSvg from "@/assets/icons/expand.svg"; const pStore = usePStore(); +const bannerPos = ref(0); const props = defineProps<{ playlist: Playlist; @@ -140,15 +154,18 @@ function update_playlist(e: Event) { diff --git a/src/components/shared/TrackItem.vue b/src/components/shared/TrackItem.vue index f1ba4d4..5892a9e 100644 --- a/src/components/shared/TrackItem.vue +++ b/src/components/shared/TrackItem.vue @@ -32,7 +32,7 @@ />
-
+
} A promise that resolves to an array of playlists. */ -async function getAllPlaylists(): Promise { +export async function getAllPlaylists(): Promise { const { data, error } = await useAxios({ url: allPlaylistsUrl, get: true, @@ -64,7 +70,7 @@ async function getAllPlaylists(): Promise { return []; } -async function addTrackToPlaylist(playlist: Playlist, track: Track) { +export async function addTrackToPlaylist(playlist: Playlist, track: Track) { const uri = `${basePlaylistUrl}/${playlist.id}/add`; const { status } = await useAxios({ @@ -85,7 +91,7 @@ async function addTrackToPlaylist(playlist: Playlist, track: Track) { ); } -async function getPlaylist(pid: string) { +export async function getPlaylist(pid: string) { const uri = `${basePlaylistUrl}/${pid}`; interface PlaylistData { @@ -109,7 +115,11 @@ async function getPlaylist(pid: string) { return null; } -async function updatePlaylist(pid: string, playlist: FormData, pStore: any) { +export async function updatePlaylist( + pid: string, + playlist: FormData, + pStore: any +) { const uri = `${basePlaylistUrl}/${pid}/update`; const { data, status } = await useAxios({ @@ -157,7 +167,6 @@ export async function getPlaylistArtists(pid: string): Promise { } export async function deletePlaylist(pid: string) { - console.log(pid); const { status } = await useAxios({ url: paths.api.playlist.base + "/delete", props: { @@ -170,10 +179,18 @@ export async function deletePlaylist(pid: string) { } } -export { - createNewPlaylist, - getAllPlaylists, - addTrackToPlaylist, - getPlaylist, - updatePlaylist, -}; +export async function updateBannerPos(pid: number, pos: number) { + const { status } = await useAxios({ + url: paths.api.playlist.base + `/${pid}/set-image-pos`, + props: { + pos, + }, + }); + + if (status === 200) { + new Notification("Image position saved", NotifType.Info); + return; + } + + new Notification("Unable to save image position", NotifType.Error); +} diff --git a/src/interfaces.ts b/src/interfaces.ts index c5a3ba4..9ed99de 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -87,6 +87,8 @@ export interface Playlist { last_updated: string; thumb: string; duration: number; + has_gif: boolean; + banner_pos: number; } export interface Notif { diff --git a/src/stores/pages/playlist.ts b/src/stores/pages/playlist.ts index dc1e6b3..511e6eb 100644 --- a/src/stores/pages/playlist.ts +++ b/src/stores/pages/playlist.ts @@ -11,6 +11,7 @@ export default defineStore("playlist-tracks", { state: () => ({ info: {}, query: "", + bannerPos: 0, allTracks: [], artists: [], }), @@ -23,6 +24,7 @@ export default defineStore("playlist-tracks", { const playlist = await getPlaylist(id); this.info = playlist?.info || ({} as Playlist); + this.bannerPos = this.info.banner_pos; this.allTracks = playlist?.tracks || []; }, @@ -42,6 +44,12 @@ export default defineStore("playlist-tracks", { this.info = { ...this.info, duration, count }; }, + plusBannerPos() { + this.bannerPos !== 100 ? (this.bannerPos += 10) : null; + }, + minusBannerPos() { + this.bannerPos !== 0 ? (this.bannerPos -= 10) : null; + }, resetArtists() { this.artists = []; }, @@ -66,5 +74,8 @@ export default defineStore("playlist-tracks", { return tracks; }, + bannerPosUpdated(): boolean { + return this.info.banner_pos - this.bannerPos !== 0; + }, }, }); diff --git a/src/views/PlaylistList.vue b/src/views/PlaylistList.vue index 3173c2f..d8fd9c9 100644 --- a/src/views/PlaylistList.vue +++ b/src/views/PlaylistList.vue @@ -1,11 +1,7 @@ @@ -24,6 +20,7 @@ const pStore = usePStore(); padding-bottom: $content-padding-bottom; height: 100%; overflow: auto; + padding-right: 1rem; .grid { grid-template-columns: repeat(auto-fill, minmax(9.25rem, 1fr)); diff --git a/src/views/PlaylistView/index.vue b/src/views/PlaylistView/index.vue index c5d8ace..f3c61e0 100644 --- a/src/views/PlaylistView/index.vue +++ b/src/views/PlaylistView/index.vue @@ -23,7 +23,7 @@ diff --git a/yarn.lock b/yarn.lock index 73397f7..094bcf7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2804,36 +2804,6 @@ __metadata: languageName: node linkType: hard -"musicx-v@workspace:.": - version: 0.0.0-use.local - resolution: "musicx-v@workspace:." - dependencies: - "@formkit/auto-animate": ^1.0.0-beta.3 - "@popperjs/core": ^2.11.6 - "@vitejs/plugin-vue": ^3.2.0 - "@vueuse/components": ^9.2.0 - "@vueuse/core": ^8.5.0 - "@vueuse/integrations": ^9.2.0 - axios: ^0.26.1 - eslint: ^8.7.0 - eslint-plugin-vue: ^8.3.0 - fuse.js: ^6.6.2 - pinia: ^2.0.17 - pinia-plugin-persistedstate: ^2.1.1 - sass: ^1.56.1 - sass-loader: ^13.2.0 - vite: ^3.0.4 - vite-svg-loader: ^3.4.0 - vue: ^3.2.37 - vue-debounce: ^3.0.2 - vue-router: ^4.1.3 - vue-svg-loader: ^0.16.0 - vue-template-compiler: ^2.0.0 - vue-virtual-scroller: ^2.0.0-alpha.1 - webpack: ^5.74.0 - languageName: unknown - linkType: soft - "nanoid@npm:^3.2.0": version: 3.2.0 resolution: "nanoid@npm:3.2.0" @@ -3639,6 +3609,36 @@ __metadata: languageName: node linkType: hard +"swing_music_client@workspace:.": + version: 0.0.0-use.local + resolution: "swing_music_client@workspace:." + dependencies: + "@formkit/auto-animate": ^1.0.0-beta.3 + "@popperjs/core": ^2.11.6 + "@vitejs/plugin-vue": ^3.2.0 + "@vueuse/components": ^9.2.0 + "@vueuse/core": ^8.5.0 + "@vueuse/integrations": ^9.2.0 + axios: ^0.26.1 + eslint: ^8.7.0 + eslint-plugin-vue: ^8.3.0 + fuse.js: ^6.6.2 + pinia: ^2.0.17 + pinia-plugin-persistedstate: ^2.1.1 + sass: ^1.56.1 + sass-loader: ^13.2.0 + vite: ^3.0.4 + vite-svg-loader: ^3.4.0 + vue: ^3.2.37 + vue-debounce: ^3.0.2 + vue-router: ^4.1.3 + vue-svg-loader: ^0.16.0 + vue-template-compiler: ^2.0.0 + vue-virtual-scroller: ^2.0.0-alpha.1 + webpack: ^5.74.0 + languageName: unknown + linkType: soft + "tapable@npm:^2.1.1, tapable@npm:^2.2.0": version: 2.2.1 resolution: "tapable@npm:2.2.1"