feat: playlist loading

This commit is contained in:
2026-09-07 16:15:31 +02:00
parent a5910df441
commit 867374fa47
19 changed files with 411 additions and 47 deletions
+53 -1
View File
@@ -1,10 +1,62 @@
import {
editingPlaylists,
playlistIdx,
playlists
} from './state';
import {
queue,
rawQueue,
shuffle
} from '../player/state';
import {
addPlaylist
} from '.';
import request from '../request';
import {
useNotification
} from '@kyvg/vue3-notification';
const savePlaylist = () => {
export const savePlaylist = async () => {
rawQueue.value = queue.value;
shuffle.value = false;
if ( playlistIdx.value ) {
let name: null | string = '';
while ( !name || name.length === 0 ) {
name = prompt( 'You are trying to save a playlist that has not previously been created. Please enter a name for it' );
}
addPlaylist( name );
playlistIdx.value = playlists.value.length - 1;
}
playlists.value[ playlistIdx.value ]!.songs = rawQueue.value;
savePlaylists();
};
export const getPlaylists = async () => {
playlists.value = await ( await request.get( '/user/playlists' ) ).json();
editingPlaylists.value = playlists.value.map( () => false );
};
export const savePlaylists = async () => {
const notifications = useNotification();
try {
await request.post( '/user/playlists', JSON.stringify( playlists.value ) );
notifications.notify( {
'text': 'Playlists saved successfully',
'type': 'success',
'title': 'Playlists'
} );
} catch ( e ) {
console.error( e );
notifications.notify( {
'text': 'Failed to save playlists',
'type': 'error',
'title': 'Playlists'
} );
}
};