Skip to content

Commit 79d57c9

Browse files
committed
Refactor stream lookup error handling and remove redundant locked state
1 parent 5801ad8 commit 79d57c9

10 files changed

Lines changed: 12 additions & 37 deletions

File tree

packages/app/app/actions/queue.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('Queue actions tests', () => {
3939
});
4040

4141
const dispatchOperation = jest.fn();
42-
const findStreamsForTrackOperation = QueueOperations.findStreamsForTrack(trackIndex);
42+
const findStreamsForTrackOperation = QueueOperations.findStreamsForTrack(trackIndex, 'stream lookup error');
4343
findStreamsForTrackOperation(dispatchOperation, stateResolver)
4444
.then(() => {
4545
// The track without streams should have been removed from the queue.

packages/app/app/actions/queue.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ const resolveStreams = async (
233233
return resolveSourceUrlForTheFirstStream(streamData, selectedStreamProvider);
234234
};
235235

236-
export const findStreamsForTrack = (index: number) => async (dispatch, getState) => {
236+
export const findStreamsForTrack = (index: number, streamLookupErrorMessage: string) => async (dispatch, getState) => {
237237
const getLatestTrack = () => queueSelector(getState()).queueItems[index];
238238
let track = getLatestTrack();
239239

@@ -284,7 +284,7 @@ export const findStreamsForTrack = (index: number) => async (dispatch, getState)
284284
...track,
285285
loading: false,
286286
error: {
287-
message: 'Stream lookup error.',
287+
message: streamLookupErrorMessage,
288288
details: e.message
289289
}
290290
}));

packages/app/app/components/PlayQueue/QueueItemClone/index.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ export const QueueItemClone: (props: QueueItemCloneProps) => DraggableChildrenFn
3737
onRemove={onRemoveTrack(rubric.source.index)}
3838
onReload={onReloadTrack(rubric.source.index)}
3939
duration={formatTrackDuration(queue.queueItems[rubric.source.index])}
40-
strings={{
41-
locked: t('locked')
42-
}}
4340
/>
4441
</div>;
4542
};

packages/app/app/components/PlayQueue/index.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,6 @@ const PlayQueue: React.FC<PlayQueueProps> = ({
180180
onSelect={onSelectTrack(index)}
181181
onRemove={onRemoveTrack(index)}
182182
onReload={onReloadTrack(index)}
183-
strings={{
184-
locked: t('locked')
185-
}}
186183
/>
187184
}
188185
isQueueItemCompact={data.settings.compactQueueBar as boolean}

packages/app/app/containers/PlayQueueContainer/__snapshots__/PlayQueueContainer.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ exports[`Play Queue container should display tracks in the queue 1`] = `
578578
data-testid="queue-popup-trigger-uuid1"
579579
>
580580
<div
581-
class="nuclear queue_item current_song"
581+
class="nuclear queue_item current_track"
582582
>
583583
<div
584584
class="thumbnail"

packages/app/app/containers/PlayerBarContainer/hooks.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ export const useVolumeControlsProps = () => {
252252
export const useStreamLookup = () => {
253253
const dispatch = useDispatch();
254254
const queue = useSelector(queueSelector);
255+
const { t } = useTranslation('queue');
255256

256257
useEffect(() => {
257258
if (!shouldSearchForStreams(queue)) {
@@ -269,7 +270,7 @@ export const useStreamLookup = () => {
269270
!currentTrack.loading &&
270271
queueActions.trackHasNoFirstStream(currentTrack)
271272
) {
272-
dispatch(queueActions.findStreamsForTrack(queue.currentTrack));
273+
dispatch(queueActions.findStreamsForTrack(queue.currentTrack, t('stream-lookup-error')));
273274
return;
274275
}
275276

@@ -282,7 +283,7 @@ export const useStreamLookup = () => {
282283
);
283284

284285
if (nextTrackWithNoStream !== -1) {
285-
dispatch(queueActions.findStreamsForTrack(nextTrackWithNoStream));
286+
dispatch(queueActions.findStreamsForTrack(nextTrackWithNoStream, t('stream-lookup-error')));
286287
}
287288
}
288289
}, [queue.currentTrack, queue.queueItems]);
@@ -291,6 +292,8 @@ export const useStreamLookup = () => {
291292
export const shouldSearchForStreams = (queue: QueueStore): boolean => {
292293
return queue.queueItems.length > 0 && !queue.queueItems.every(item =>
293294
item.local ||
295+
item.loading ||
296+
item.error ||
294297
(item.streams?.[0]?.stream)
295298
);
296299
};

packages/i18n/src/locales/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@
258258
},
259259
"create-playlist-dialog-title": "Input playlist name:",
260260
"play-now": "Play now",
261-
"locked": "Stream lookup failed. Click to start over."
261+
"stream-lookup-error": "Stream lookup error. Click to retry."
262262
},
263263
"search": {
264264
"album": "Album",

packages/ui/lib/components/QueueItem/index.tsx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ import { getThumbnail, getTrackArtist, getTrackTitle } from '../../utils';
1212
import { Track } from '../../types';
1313
import Img from 'react-image';
1414

15-
type QueueItemStrings = {
16-
locked: string
17-
}
18-
1915
export type QueueItemProps = {
2016
isCurrent: boolean;
2117
isCompact: boolean;
@@ -24,7 +20,6 @@ export type QueueItemProps = {
2420
onSelect: () => void;
2521
onRemove: () => void;
2622
onReload: () => void;
27-
strings: QueueItemStrings;
2823
};
2924

3025
const isErrorWithMessage = (error: Track['error']): error is { message: string; details: string } => {
@@ -38,8 +33,7 @@ export const QueueItem: React.FC<QueueItemProps> = ({
3833
duration,
3934
onRemove,
4035
onSelect,
41-
onReload,
42-
strings
36+
onReload
4337
}) => {
4438
return (
4539
<div
@@ -51,6 +45,7 @@ export const QueueItem: React.FC<QueueItemProps> = ({
5145
{ [`${styles.compact}`]: isCompact }
5246
)}
5347
onDoubleClick={onSelect}
48+
onClick={track. error && onReload}
5449
>
5550
<div className={styles.thumbnail}>
5651
{
@@ -108,15 +103,6 @@ export const QueueItem: React.FC<QueueItemProps> = ({
108103
<div className={styles.error_message}>{track.error && track.error.message}</div>
109104
</div>
110105
}
111-
112-
{
113-
!isCompact &&
114-
<div className={styles.error_overlay}>
115-
<div className={styles.error_message}>
116-
{strings.locked}
117-
</div>
118-
</div>
119-
}
120106
</div>
121107
);
122108
};

packages/ui/lib/components/QueueItem/styles.scss

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,6 @@
7979
background: rgba(common.$red, 0.8);
8080
}
8181

82-
&.locked {
83-
cursor: pointer;
84-
background: rgba(common.$white, 0.3);
85-
}
86-
8782
&.compact {
8883
width: auto;
8984
height: auto;

packages/ui/stories/components/queueItem.stories.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ const commonProps = {
2626
},
2727
onReload: () => {
2828
alert('Item reloaded');
29-
},
30-
strings: {
31-
locked: 'Stream lookup failed. Click to start over.'
3229
}
3330
};
3431

0 commit comments

Comments
 (0)