Skip to content

Commit 6e33c41

Browse files
committed
add sonner, create audio error toast
1 parent 76196d0 commit 6e33c41

File tree

5 files changed

+24
-20
lines changed

5 files changed

+24
-20
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"react-timeago": "^8.3.0",
4343
"react-use-cookie": "^1.6.1",
4444
"redux": "^4.2.1",
45+
"sonner": "^2.0.7",
4546
"tailwind-merge": "^3.3.1",
4647
"thenby": "^1.3.4",
4748
"ua-parser-js": "^1.0.37",

pnpm-lock.yaml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/(browse)/layout.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import NavBar from '@/components/NavBar';
33
import cn from '@/lib/cn';
44
import { getIsInIframe } from '@/lib/isInIframe';
55
import { ReactNode } from 'react';
6+
import { Toaster } from 'sonner';
67

78
export default async function BrowseLayout({
89
children,
@@ -23,6 +24,7 @@ export default async function BrowseLayout({
2324

2425
return (
2526
<Flex column className="h-screen">
27+
<Toaster id="audio-error" position="top-center" richColors closeButton />
2628
<NavBar />
2729
<div
2830
className={cn(

src/components/Player.tsx

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import Head from 'next/head';
44
import Link from 'next/link';
5-
import React, { useRef, useState, useEffect } from 'react';
5+
import React, { useRef, useState } from 'react';
66

77
import { useSelector } from 'react-redux';
88
import player from '../lib/player';
@@ -18,6 +18,7 @@ import {
1818
RewindIcon,
1919
Volume2Icon,
2020
} from 'lucide-react';
21+
import { Toaster } from 'sonner';
2122

2223
interface Props {
2324
artistSlugsToName: Record<string, string | undefined>;
@@ -30,7 +31,6 @@ const Player = ({ artistSlugsToName }: Props) => {
3031
const [volume, setVolume] = useState(
3132
(typeof localStorage !== 'undefined' && localStorage.volume) || 1
3233
);
33-
// const [hasAudioError, setHasAudioError] = useState(false);
3434

3535
const { year, month, day } = splitShowDate(playback.showDate);
3636
const { artistSlug, source } = playback;
@@ -73,17 +73,6 @@ const Player = ({ artistSlugsToName }: Props) => {
7373
localStorage.volume = Math.max(0, Math.min(1, nextVolume));
7474
};
7575

76-
// useEffect(() => {
77-
// const handleAudioError = () => {
78-
// setHasAudioError(true);
79-
// };
80-
81-
// window.addEventListener('gapless-audio-error', handleAudioError);
82-
// return () => {
83-
// window.removeEventListener('gapless-audio-error', handleAudioError);
84-
// };
85-
// }, []);
86-
8776
return (
8877
<Flex className="content relative h-[50px] flex-1 px-2">
8978
{false && activeTrack && (
@@ -201,12 +190,6 @@ const Player = ({ artistSlugsToName }: Props) => {
201190
</div>
202191
</Link>
203192
)}
204-
{/* {hasAudioError && (
205-
<Flex className="items-center">
206-
<AlertCircle color="red" />
207-
<p className="m-2">Error loading audio</p>
208-
</Flex>
209-
)} */}
210193
</Flex>
211194
);
212195
};

src/lib/player.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { splitShowDate } from './utils';
55
import { scrobblePlay } from '../redux/modules/live';
66
import { updatePlayback } from '../redux/modules/playback';
77
import { ActiveTrack, GaplessMetadata } from '../types';
8+
import { toast } from 'sonner';
89

910
declare global {
1011
interface Window {
@@ -157,7 +158,10 @@ const player = new Gapless.Queue({
157158
}
158159
},
159160
onError: () => {
160-
console.log('Leithen errors');
161+
toast.error('There was an error loading your audio', {
162+
toasterId: 'audio-error',
163+
duration: Infinity,
164+
});
161165
},
162166
});
163167

0 commit comments

Comments
 (0)