diff --git a/src/components/PlexLoginButton/index.tsx b/src/components/PlexLoginButton/index.tsx new file mode 100644 index 00000000..816533ee --- /dev/null +++ b/src/components/PlexLoginButton/index.tsx @@ -0,0 +1,44 @@ +import React, { useState } from 'react'; +import PlexOAuth from '../../utils/plex'; + +const plexOAuth = new PlexOAuth(); + +interface PlexLoginButtonProps { + onAuthToken: (authToken: string) => void; + onError?: (message: string) => void; +} + +const PlexLoginButton: React.FC = ({ + onAuthToken, + onError, +}) => { + const [loading, setLoading] = useState(false); + + const getPlexLogin = async () => { + setLoading(true); + try { + const authToken = await plexOAuth.login(); + onAuthToken(authToken); + setLoading(false); + } catch (e) { + if (onError) { + onError(e.message); + } + setLoading(false); + } + }; + return ( + + + + ); +}; + +export default PlexLoginButton; diff --git a/src/pages/plextest.tsx b/src/pages/plextest.tsx index c710e0dd..2612b71d 100644 --- a/src/pages/plextest.tsx +++ b/src/pages/plextest.tsx @@ -1,36 +1,12 @@ import React, { useState } from 'react'; import { NextPage } from 'next'; -import PlexOAuth from '../utils/plex'; - -const plexOAuth = new PlexOAuth(); +import PlexLoginButton from '../components/PlexLoginButton'; const PlexText: NextPage = () => { - const [loading, setLoading] = useState(false); const [authToken, setAuthToken] = useState(''); - - const getPlexLogin = async () => { - setLoading(true); - try { - const authToken = await plexOAuth.login(); - setAuthToken(authToken); - setLoading(false); - } catch (e) { - console.log(e.message); - setLoading(false); - } - }; return (
- - - + setAuthToken(authToken)} />
Auth Token: {authToken}
); diff --git a/src/styles/globals.css b/src/styles/globals.css index b5c61c95..1fe682de 100644 --- a/src/styles/globals.css +++ b/src/styles/globals.css @@ -1,3 +1,8 @@ @tailwind base; @tailwind components; @tailwind utilities; + +.plex-button { + @apply inline-flex items-center px-4 py-2 border border-transparent text-sm leading-5 font-medium rounded-md text-white bg-indigo-600 transition ease-in-out duration-150; + background-color: #cc7b19; +}