fix(playlists): update player state after pressing play
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
import type { SubmitFunction } from '../../../routes/playlists/[id]/$types';
|
import type { SubmitFunction } from '../../../routes/playlists/[id]/$types';
|
||||||
import { getCoverUrl } from '$lib/covers';
|
import { getCoverUrl } from '$lib/covers';
|
||||||
import { getLibraryState } from '$lib/library.svelte';
|
import { getLibraryState } from '$lib/library.svelte';
|
||||||
|
import { getPlayerState } from '$lib/player.svelte';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -21,6 +22,7 @@
|
|||||||
);
|
);
|
||||||
|
|
||||||
const library = getLibraryState();
|
const library = getLibraryState();
|
||||||
|
const player = getPlayerState();
|
||||||
|
|
||||||
let coverImages = $derived.by(() => {
|
let coverImages = $derived.by(() => {
|
||||||
if (tracks.length === 0) {
|
if (tracks.length === 0) {
|
||||||
@@ -53,11 +55,15 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
const playPlaylist: SubmitFunction = async () => {
|
const playPlaylist: SubmitFunction = async () => {
|
||||||
return async ({ update }) => {
|
return async ({ update, result }) => {
|
||||||
await update({
|
await update({
|
||||||
invalidateAll: false,
|
invalidateAll: false,
|
||||||
reset: false
|
reset: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (result.type === 'success' && result.data) {
|
||||||
|
player.applyStatus(result.data);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,14 +2,18 @@ import type { Actions } from './$types';
|
|||||||
import { protoTransport } from '../../../hooks.server';
|
import { protoTransport } from '../../../hooks.server';
|
||||||
import { PlayerClient } from '$lib/proto/player.client';
|
import { PlayerClient } from '$lib/proto/player.client';
|
||||||
import { LibraryClient } from '$lib/proto/library.client';
|
import { LibraryClient } from '$lib/proto/library.client';
|
||||||
|
import { serializable } from '$lib/proto';
|
||||||
|
import type { PlayerStatus } from '$lib/proto/player';
|
||||||
|
|
||||||
export const actions = {
|
export const actions = {
|
||||||
play: async ({ params }) => {
|
play: async ({ params }) => {
|
||||||
const client = new PlayerClient(protoTransport);
|
const client = new PlayerClient(protoTransport);
|
||||||
|
|
||||||
const _response = await client.playPlaylist({
|
const response = await client.playPlaylist({
|
||||||
id: parseInt(params.id)
|
id: parseInt(params.id)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return serializable<PlayerStatus>(response.response);
|
||||||
},
|
},
|
||||||
delete: async ({ params }) => {
|
delete: async ({ params }) => {
|
||||||
const client = new LibraryClient(protoTransport);
|
const client = new LibraryClient(protoTransport);
|
||||||
|
|||||||
Reference in New Issue
Block a user