Skip to content

Commit 1b30d34

Browse files
committed
feat(auth): add button and improve text
1 parent d40c649 commit 1b30d34

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

src/pages/auth/apple-music.tsx

+27-18
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1+
'use client';
2+
13
import type { NextPage } from 'next';
24
import { useApi, useToaster } from '@/hooks';
35
import { Container } from '@/components/Container';
46
import { useRouter } from 'next/router';
57
import type { SSRProps } from '@/utils/ssrUtils';
68
import Script from 'next/script';
9+
import { useEffect, useState } from 'react';
10+
import { AppleMusicIcon } from '@/components/Icons';
11+
import { Button } from '@/components/Button';
712

813
const Login: NextPage<SSRProps> = () => {
914
const router = useRouter();
1015
const toaster = useToaster();
1116
const api = useApi();
1217
// const [musicKitLoaded, setMusicKitLoaded] = useState(false);
13-
let inProgress = false;
18+
const [inProgress, setInProgress] = useState(false);
19+
const [showButton, setShowButton] = useState(false);
1420

1521
const redirectToLogin = () => {
1622
toaster.error('Sign in with Apple first');
@@ -30,15 +36,12 @@ const Login: NextPage<SSRProps> = () => {
3036
}
3137

3238
if (inProgress) return;
33-
inProgress = true;
39+
setInProgress(true);
3440

3541
try {
3642
const music = MusicKit.getInstance();
3743
const MUT = await music.authorize();
3844

39-
// // eslint-disable-next-line no-promise-executor-return
40-
// await new Promise((resolve) => setTimeout(resolve, 500));
41-
4245
window.location.replace(
4346
api.http.resolveUrl(
4447
'/auth/APPLEMUSIC/callback/music',
@@ -51,7 +54,7 @@ const Login: NextPage<SSRProps> = () => {
5154
console.error(e);
5255
toaster.error('Something went wrong trying to login. Please try again.');
5356
}
54-
inProgress = false;
57+
setInProgress(false);
5558
};
5659

5760
const initializeMusicKit = () => {
@@ -71,9 +74,13 @@ const Login: NextPage<SSRProps> = () => {
7174
})();
7275
};
7376

74-
// useEffect(() => {
75-
// initializeMusicKit();
76-
// }, [router.isReady, musicKitLoaded, router.query]);
77+
useEffect(() => {
78+
// 3 second timeout to show the button
79+
const timeout = setTimeout(() => {
80+
setShowButton(true);
81+
}, 3000);
82+
return () => clearTimeout(timeout);
83+
}, []);
7784

7885
return (
7986
<>
@@ -89,16 +96,18 @@ const Login: NextPage<SSRProps> = () => {
8996
</h1>
9097
<div className="mt-8 flex flex-col gap-4">
9198
<p className="text-center">
92-
An Apple Music popup should appear soon...
99+
An Apple Music popup should appear soon... If it doesn&apos;t,
100+
please check if you have browser popups blocked.
93101
</p>
94-
{/* TODO: show the button below after 3 seconds or so in case the automatic popup didnt open @stijnvdkolk */}
95-
{/* <Button
96-
onClick={appleMusicKitHandle}
97-
className="w-full bg-applemusic/80 text-white hover:bg-applemusic/60 active:bg-applemusic/50"
98-
>
99-
<AppleMusicIcon className="mr-2 !fill-white" hover={false} />
100-
Authorize
101-
</Button> */}
102+
{showButton && (
103+
<Button
104+
onClick={appleMusicKitHandle}
105+
className="w-full bg-applemusic/80 text-white hover:bg-applemusic/60 active:bg-applemusic/50"
106+
>
107+
<AppleMusicIcon className="mr-2 !fill-white" hover={false} />
108+
Authorize
109+
</Button>
110+
)}{' '}
102111
</div>
103112
</div>
104113
</Container>

0 commit comments

Comments
 (0)