Skip to content

Commit

Permalink
feat(client): loading state on auth form, added some content to home …
Browse files Browse the repository at this point in the history
…page
  • Loading branch information
Ivo committed Apr 21, 2023
1 parent 5021b51 commit f2a7122
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 22 deletions.
16 changes: 16 additions & 0 deletions apps/client/public/locales/en-US/home.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"title": "Home",
"callout": "Molecular Dynamics made easy",
"slogan": "The new home to easy MD generation and execution",
"description": "Welcome to the new Visual Dynamics.\nWith a revamped interface and a new methodology of generating and running GROMACS simulations we aim to provide faster, more reliable and replicable simulations, all this, through a new, more understandable and scalable codebase.",
"features": {
"runs-on-cloud": {
"title": "Runs on Cloud",
"description": "MD demands time, computational power, and even more computational power, so you can rely on us to this. We run 10 simultaneous MDs, with 6 CPU cores each."
},
"open-source": {
"title": "Free for... everyone",
"description": "We know running a MD is not something easy, with this in mind, we develop this piece of software as a free and open-source software. Run on our hardware, your hardware, deploy your own, it is totally up to you."
}
}
}
1 change: 1 addition & 0 deletions apps/client/public/locales/en-US/navigation.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"auth": {
"restore": "Trying to restore a session",
"role": {
"admin": "Administrator",
"user": "User"
Expand Down
43 changes: 39 additions & 4 deletions apps/client/src/components/Auth/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useState } from "react";
import { SubmitHandler, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { Lock, LogIn, LogOut, User, UserPlus } from "lucide-react";
import { Fingerprint, Lock, LogIn, LogOut, User, UserPlus } from "lucide-react";
import { useRouter } from "next/router";
import { signIn, signOut, useSession } from "next-auth/react";
import { useTranslation } from "next-i18next";
Expand All @@ -17,6 +18,7 @@ import { SelectTheme } from "../SelectTheme";

export function Auth() {
const { data: session, status } = useSession();
const [isAuthenticating, setIsAuthenticating] = useState(false);
const {
register,
reset,
Expand All @@ -32,11 +34,14 @@ export function Auth() {
identifier,
password
}) => {
setIsAuthenticating(true);
signIn("credentials", {
identifier,
password,
redirect: false
}).then(() => reset());
})
.then(() => reset())
.finally(() => setIsAuthenticating(false));
};

if (status === "authenticated") {
Expand Down Expand Up @@ -74,7 +79,12 @@ export function Auth() {
}

if (status === "loading") {
return <h1>loading</h1>;
return (
<div className="flex gap-x-1">
<Fingerprint className="h-5 w-5 animate-bounce" />
<p>{t("navigation:auth.restore")}</p>
</div>
);
}

return (
Expand All @@ -98,10 +108,35 @@ export function Auth() {
{...register("password")}
/>
<Button
disabled={isAuthenticating}
className="h-8"
LeftIcon={LogIn}
LeftIcon={!isAuthenticating ? LogIn : undefined}
type="submit"
>
{isAuthenticating ? (
<div
className="z-0"
role="status"
>
<svg
aria-hidden="true"
className="w-5 h-5 text-primary-100 animate-spin fill-primary-950"
viewBox="0 0 100 101"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
fill="currentColor"
/>
<path
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
fill="currentFill"
/>
</svg>
<span className="sr-only">Loading...</span>
</div>
) : null}
{t("navigation:forms.submit")}
</Button>
<div className="flex gap-x-2">
Expand Down
62 changes: 60 additions & 2 deletions apps/client/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,66 @@
import { CloudCog, Code2 } from "lucide-react";
import { useTranslation } from "next-i18next";

import { PageLayout } from "@app/components/Layout/Page";
import { withSSRTranslations } from "@app/hocs/withSSRTranslations";

export const getStaticProps = withSSRTranslations(undefined);
export const getStaticProps = withSSRTranslations(undefined, {
namespaces: ["home"]
});

export default function Home() {
return <PageLayout title="pages:home.title">bem vindo</PageLayout>;
const { t } = useTranslation(["home"]);

const features = [
{
name: "home:features.runs-on-cloud.title",
description: "home:features.runs-on-cloud.description",
icon: CloudCog
},
{
name: "home:features.open-source.title",
description: "home:features.open-source.description",
icon: Code2
}
];

return (
<PageLayout
className="gap-y-5"
title={t("home:title")}
>
<div className="text-center">
<h2 className="text-base font-semibold leading-7 text-primary-600 transition-all duration-500">
{t("home:callout")}
</h2>
<p className="text-3xl font-bold tracking-tight text-gray-900">
{t("home:slogan")}
</p>
</div>
<p className="text-justify text-lg leading-8 text-gray-600">
{t("home:description")}
</p>
<dl className="grid grid-cols-1 gap-x-8 gap-y-10 lg:grid-cols-2 lg:gap-y-16">
{features.map((feature) => (
<div
key={feature.name}
className="relative pl-12"
>
<dt className="text-base flex font-semibold text-gray-900">
<div className="absolute left-0 top-1 flex h-10 w-10 items-center justify-center rounded-lg bg-primary-600 transition-all duration-500">
<feature.icon
className="h-6 w-6 text-white"
aria-hidden="true"
/>
</div>
{t(feature.name)}
</dt>
<dd className="text-base text-gray-600">
{t(feature.description)}
</dd>
</div>
))}
</dl>
</PageLayout>
);
}
18 changes: 2 additions & 16 deletions apps/client/src/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,9 @@ html,
body {
font-family: "Inter", sans-serif;
font-family: "Space Grotesk", sans-serif;
white-space: pre-line;
}

pre > code {
display: grid;
}

/* code {
counter-reset: step;
counter-increment: step 1;
}
code .line::before {
content: counter(step);
counter-increment: step;
width: 1rem;
margin-right: 1.5rem;
display: inline-block;
text-align: right;
color: rgba(115, 138, 148, 0.4);
} */
}

0 comments on commit f2a7122

Please sign in to comment.