feat(components/plexloginbutton): added PlexLoginButton
This commit is contained in:
44
src/components/PlexLoginButton/index.tsx
Normal file
44
src/components/PlexLoginButton/index.tsx
Normal file
@@ -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<PlexLoginButtonProps> = ({
|
||||
onAuthToken,
|
||||
onError,
|
||||
}) => {
|
||||
const [loading, setLoading] = useState<boolean>(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 (
|
||||
<span className="inline-flex rounded-md shadow-sm">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => getPlexLogin()}
|
||||
disabled={loading}
|
||||
className="plex-button"
|
||||
>
|
||||
{loading ? 'Loading...' : 'Login with Plex'}
|
||||
</button>
|
||||
</span>
|
||||
);
|
||||
};
|
||||
|
||||
export default PlexLoginButton;
|
||||
Reference in New Issue
Block a user