Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 3 additions & 21 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"effect": "3.21.0",
"ink": "7.0.0",
"ink-link": "5.0.0",
"ink-scroll-view": "0.3.6",
"ink-scroll-view": "0.3.7",
"ink-spinner": "5.0.0",
"react": "19.2.0",
"sanitize-filename": "1.6.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/ui/DoneScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function DoneScreen(props: DoneScreenProps) {

<Panel title="Tracks" borderColor="green" titleColor="green">
{props.workerSlots.map((slot) => (
<WorkerRow key={slot.trackId} slot={slot} />
<WorkerRow key={slot.trackIndex} slot={slot} />
))}
</Panel>

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/ui/SyncScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function SyncScreen(props: SyncScreenProps) {
borderColor="magenta"
minRows={20}
items={visibleSlots}
renderItem={(slot) => <WorkerRow key={slot.trackId} slot={slot} />}
renderItem={(slot) => <WorkerRow key={slot.trackIndex} slot={slot} />}
/>
</Box>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/ui/components/ListPanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('ListPanel', () => {
<ListPanel
items={createSlots(18)}
minRows={4}
renderItem={(slot) => <WorkerRow key={slot.trackId} slot={slot} />}
renderItem={(slot) => <WorkerRow key={slot.trackIndex} slot={slot} />}
title="Tracks"
viewportHeight={4}
/>
Expand Down
63 changes: 63 additions & 0 deletions packages/cli/src/ui/utils/workerSlots.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { describe, expect, test } from 'bun:test';
import type { PlaylistMetadata, SyncProgress } from '../../lib/types';
import { createWorkerSlots, updateWorkerSlots } from './workerSlots';

describe('updateWorkerSlots', () => {
test('updates the indexed duplicate track instead of the first matching track ID', () => {
const playlist: PlaylistMetadata = {
id: 'playlist-1',
provider: 'spotify',
sourceUrl: 'https://open.spotify.com/playlist/playlist-1',
title: 'Duplicate tracks',
tracks: [
{ artists: ['Artist'], id: 'duplicate-track', title: 'First copy' },
{ artists: ['Artist'], id: 'duplicate-track', title: 'Second copy' },
],
};
const progress: SyncProgress = {
completed: 1,
current: 2,
downloaded: 1,
failed: 0,
message: 'Finished',
playlistDir: '/music/Duplicate tracks',
skipped: 0,
stage: 'completed',
total: 2,
track: playlist.tracks[1],
trackIndex: 2,
};

const slots = updateWorkerSlots(createWorkerSlots(playlist, 1), playlist, progress);

expect(slots.map((slot) => slot.stage)).toEqual(['queued', 'completed']);
expect(slots.map((slot) => slot.message)).toEqual(['Queued', 'Finished']);
});

test('ignores progress with an unknown track index', () => {
const playlist: PlaylistMetadata = {
id: 'playlist-1',
provider: 'spotify',
sourceUrl: 'https://open.spotify.com/playlist/playlist-1',
title: 'One track',
tracks: [{ artists: ['Artist'], id: 'track-1', title: 'Track' }],
};
const progress: SyncProgress = {
completed: 0,
current: 2,
downloaded: 0,
failed: 0,
message: 'Preparing track',
playlistDir: '/music/One track',
skipped: 0,
stage: 'initializing',
total: 1,
track: playlist.tracks[0],
trackIndex: 2,
};

expect(updateWorkerSlots(createWorkerSlots(playlist, 1), playlist, progress)).toEqual(
createWorkerSlots(playlist, 1)
);
});
});
5 changes: 4 additions & 1 deletion packages/cli/src/ui/utils/workerSlots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ export function updateWorkerSlots(
return slots;
}

const slotIndex = slots.findIndex((slot) => slot.trackId === trackId);
const slotIndex =
progress.trackIndex === undefined
? slots.findIndex((slot) => slot.trackId === trackId)
: slots.findIndex((slot) => slot.trackIndex === progress.trackIndex);
if (slotIndex < 0) {
return slots;
}
Expand Down