mirror of
https://github.com/BrenBroZAYT/gameyfin.git
synced 2026-06-16 16:20:04 +00:00
Switch to Hilla for UI
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
import {useAuth} from "Frontend/util/auth";
|
||||
import {useState} from "react";
|
||||
import {useNavigate} from "react-router-dom";
|
||||
import {Button, Card, Input, Typography} from "@material-tailwind/react";
|
||||
|
||||
export default function LoginView() {
|
||||
const {state, login} = useAuth();
|
||||
const [hasError, setError] = useState<boolean>();
|
||||
const [username, setUsername] = useState<string>();
|
||||
const [password, setPassword] = useState<string>();
|
||||
const [url, setUrl] = useState<string>();
|
||||
const navigate = useNavigate();
|
||||
|
||||
if (state.user && url) {
|
||||
const path = new URL(url, document.baseURI).pathname;
|
||||
navigate(path, {replace: true});
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex h-screen">
|
||||
<div className="fixed h-full w-full bg-gradient-to-br from-gf-primary to-gf-secondary"></div>
|
||||
<Card className="m-auto p-12" shadow={true}>
|
||||
<img
|
||||
className="h-28 w-full content-center"
|
||||
src="/images/Logo.svg"
|
||||
/>
|
||||
<div className="mt-8 mb-2 w-80 max-w-screen-lg sm:w-96">
|
||||
<form
|
||||
className="mb-1 flex flex-col gap-6"
|
||||
onSubmit={async e => {
|
||||
e.preventDefault();
|
||||
if (typeof username === "string" && password != null) {
|
||||
const {defaultUrl, error, redirectUrl} = await login(username, password);
|
||||
if (error) {
|
||||
setError(true);
|
||||
alert("Wrong username and/or password!");
|
||||
} else {
|
||||
setUrl(redirectUrl ?? defaultUrl ?? '/');
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Typography variant="h6" color="blue-gray" className="-mb-3">
|
||||
Username
|
||||
</Typography>
|
||||
<Input
|
||||
onChange={(event) => {
|
||||
setUsername(event.target.value);
|
||||
}}
|
||||
size="lg"
|
||||
className=" !border-t-blue-gray-200 focus:!border-t-gray-900"
|
||||
labelProps={{
|
||||
className: "before:content-none after:content-none",
|
||||
}}
|
||||
crossOrigin="" //TODO: see https://github.com/creativetimofficial/material-tailwind/issues/427
|
||||
/>
|
||||
<Typography variant="h6" color="blue-gray" className="-mb-3">
|
||||
Password
|
||||
</Typography>
|
||||
<Input
|
||||
onChange={(event) => {
|
||||
setPassword(event.target.value);
|
||||
}}
|
||||
type="password"
|
||||
size="lg"
|
||||
className=" !border-t-blue-gray-200 focus:!border-t-gray-900"
|
||||
labelProps={{
|
||||
className: "before:content-none after:content-none",
|
||||
}}
|
||||
crossOrigin="" //TODO: see https://github.com/creativetimofficial/material-tailwind/issues/427
|
||||
/>
|
||||
<Button
|
||||
type="submit"
|
||||
size="lg"
|
||||
fullWidth>
|
||||
Log in
|
||||
</Button>
|
||||
</form>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import {AppLayout} from '@hilla/react-components/AppLayout.js';
|
||||
import {Avatar} from '@hilla/react-components/Avatar.js';
|
||||
import {Button} from '@hilla/react-components/Button.js';
|
||||
import {DrawerToggle} from '@hilla/react-components/DrawerToggle.js';
|
||||
import {useAuth} from 'Frontend/util/auth.js';
|
||||
import {useRouteMetadata} from 'Frontend/util/routing.js';
|
||||
import {useEffect} from 'react';
|
||||
import {Outlet} from 'react-router-dom';
|
||||
|
||||
const navLinkClasses = ({isActive}: any) => {
|
||||
return `block rounded-m p-s ${isActive ? 'bg-primary-10 text-primary' : 'text-body'}`;
|
||||
};
|
||||
|
||||
export default function MainLayout() {
|
||||
const currentTitle = useRouteMetadata()?.title ?? 'My App';
|
||||
useEffect(() => {
|
||||
document.title = currentTitle;
|
||||
}, [currentTitle]);
|
||||
|
||||
const {state, logout} = useAuth();
|
||||
return (
|
||||
<AppLayout primarySection="drawer">
|
||||
<div slot="drawer" className="flex flex-col justify-between h-full p-m">
|
||||
<header className="flex flex-col gap-m">
|
||||
<h1 className="text-l m-0">My App</h1>
|
||||
<nav>
|
||||
</nav>
|
||||
</header>
|
||||
<footer className="flex flex-col gap-s">
|
||||
{state.user ? (
|
||||
<>
|
||||
<div className="flex items-center gap-s">
|
||||
<Avatar theme="xsmall" name={state.user.name}/>
|
||||
{state.user.name}
|
||||
</div>
|
||||
<Button onClick={async () => logout()}>Sign out</Button>
|
||||
</>
|
||||
) : (
|
||||
<a href="/login">Sign in</a>
|
||||
)}
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<DrawerToggle slot="navbar" aria-label="Menu toggle"></DrawerToggle>
|
||||
<h2 slot="navbar" className="text-l m-0">
|
||||
{currentTitle}
|
||||
</h2>
|
||||
|
||||
<Outlet/>
|
||||
</AppLayout>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export default function TestView() {
|
||||
return (
|
||||
<h1>Hello Gameyfin!</h1>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user