fix(ui): improve StackIcon reactivity and add debugging

- Replace onMount/onDestroy with $effect rune for better reactivity
- Add console logging to trace context changes
- Log when setPlaybackContext/clearPlaybackContext are called
- Log when StackIcon receives context updates

This will help debug why stack icon might not appear immediately.

To test:
1. Open browser console
2. Click a track in an album
3. Check logs for '[PlaybackContext]' and '[StackIcon]'
4. Verify context is being set and icon is receiving updates

cp
This commit is contained in:
vicrodh committed 2026-01-18 01:26:18 -06:00
1 parent b6001b0203
commit 3851fecd92
2 files changed
+19 -10

No files matched your search

+14 -10
View File
@@ -1,7 +1,6 @@
<script lang="ts">
import { Layers } from 'lucide-svelte';
import { subscribe, getCurrentContext, getContextDisplayInfo } from '$lib/stores/playbackContextStore';
import { onMount, onDestroy } from 'svelte';
interface Props {
size?: number;
@@ -13,17 +12,19 @@
let context = $state(getCurrentContext());
let displayInfo = $state(context ? getContextDisplayInfo() : null);
let unsubscribe: (() => void) | null = null;
onMount(() => {
unsubscribe = subscribe(() => {
context = getCurrentContext();
displayInfo = context ? getContextDisplayInfo() : null;
// Subscribe to context changes with $effect
$effect(() => {
const unsubscribe = subscribe(() => {
const newContext = getCurrentContext();
const newDisplayInfo = newContext ? getContextDisplayInfo() : null;
console.log('[StackIcon] Context changed:', { newContext, newDisplayInfo });
context = newContext;
displayInfo = newDisplayInfo;
});
});
onDestroy(() => {
unsubscribe?.();
return () => {
unsubscribe();
};
});
</script>
@@ -31,6 +32,9 @@
<div class="stack-icon-wrapper {className}" title="Playing from: {displayInfo}">
<Layers size={size} strokeWidth={2} />
</div>
{:else}
<!-- Debug: Icon should be hidden -->
<!-- <span style="font-size: 10px; color: red;">No context</span> -->
{/if}
<style>
+5
View File
@@ -45,6 +45,8 @@ export async function setPlaybackContext(
trackIds: number[],
startPosition: number
): Promise<void> {
console.log('[PlaybackContext] Setting context:', { contextType, id, label, trackIds: trackIds.length, startPosition });
await invoke('set_playback_context', {
contextType,
id,
@@ -64,6 +66,7 @@ export async function setPlaybackContext(
current_position: startPosition
};
console.log('[PlaybackContext] Context set, notifying listeners. Current context:', currentContext);
notifyListeners();
}
@@ -71,8 +74,10 @@ export async function setPlaybackContext(
* Clear the playback context (e.g., when playing single track)
*/
export async function clearPlaybackContext(): Promise<void> {
console.log('[PlaybackContext] Clearing context');
await invoke('clear_playback_context');
currentContext = null;
console.log('[PlaybackContext] Context cleared, notifying listeners');
notifyListeners();
}