From 05814a100a277e5acc156d7ef881cc8ebe4b5543 Mon Sep 17 00:00:00 2001 From: bivashy Date: Mon, 24 Nov 2025 01:03:46 +0500 Subject: [PATCH] Implement reordering with optimistic updates --- app/components/internal/PlaylistSelect.vue | 13 +- app/composeables/api/models/index.ts | 3 + .../api/models/trackBulkReorderRequest.ts | 10 + .../api/models/trackReorderAfterRequest.ts | 11 ++ .../api/track-controller/track-controller.ts | 61 ++++++ app/pages/edit.vue | 186 +++++++++++++----- app/plugins/vue-dnd-kit.client.ts | 1 - app/stores/use-current-playlist-store.ts | 24 +++ bun.lock | 16 ++ nuxt.config.ts | 7 +- package.json | 2 + 11 files changed, 271 insertions(+), 63 deletions(-) create mode 100644 app/composeables/api/models/trackBulkReorderRequest.ts create mode 100644 app/composeables/api/models/trackReorderAfterRequest.ts create mode 100644 app/stores/use-current-playlist-store.ts diff --git a/app/components/internal/PlaylistSelect.vue b/app/components/internal/PlaylistSelect.vue index 8fed3fa..f911b81 100644 --- a/app/components/internal/PlaylistSelect.vue +++ b/app/components/internal/PlaylistSelect.vue @@ -14,6 +14,7 @@ import { usePlaylists } from '@/composeables/api/playlist-controller/playlist-co import { ChevronsUpDown, Music4, Plus } from 'lucide-vue-next'; import Button from '../ui/button/Button.vue'; import PlaylistCreateDialog from './playlists/select/PlaylistCreateDialog.vue'; +import { useCurrentPlaylistStore } from '~/stores/use-current-playlist-store'; const { open: sidebarOpen, @@ -21,18 +22,18 @@ const { const { isLoading, isError, error, data } = usePlaylists(); -const selectedPlaylist = ref(-1); +const currentPlaylistStore = useCurrentPlaylistStore(); watch(data, (value) => { - const newValue = value?.data[0]?.id || -1; - if (selectedPlaylist.value === -1) { - selectedPlaylist.value = newValue; + const newValue = value?.data[0]; + if (currentPlaylistStore.id === -1 && newValue) { + currentPlaylistStore.load(newValue); } });