Skip to content

Commit

Permalink
fix(client): improvements to mobile UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivo committed Apr 23, 2023
1 parent 7814ca4 commit 2d2b316
Show file tree
Hide file tree
Showing 30 changed files with 178 additions and 188 deletions.
16 changes: 4 additions & 12 deletions apps/client/content/definitions/Post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import { defineDocumentType } from "contentlayer/source-files";
import GithubSlugger from "github-slugger";
import readingTime from "reading-time";

// DON'T EVER MOVE THIS TO NON-RELATIVE IMPORTS
// IT'LL BREAK
import { formatShortDate } from "../../src/lib/formatShortDate";

// esbuild doesn't support module aliases 😤🤌
Expand Down Expand Up @@ -43,18 +46,7 @@ export const Post = defineDocumentType(() => ({
);
}
},
tweetIds: {
type: "json",
resolve: (doc) => {
const tweetMatches = doc.body.raw.match(
/<StaticTweet\sid="[0-9]+"[\s\S]*?\/>/g
);
const tweetIDs = tweetMatches?.map(
(tweet: any) => tweet.match(/[0-9]+/g)[0]
);
return tweetIDs ?? [];
}
},
readingTime: { type: "json", resolve: (doc) => readingTime(doc.body.raw) },
publishedAtFormatted: {
type: "string",
resolve: (doc) => formatShortDate(doc.publishedAt)
Expand Down
2 changes: 2 additions & 0 deletions apps/client/contentlayer.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import rehypePrettyCode from "rehype-pretty-code";
import rehypeSlug from "rehype-slug";
import remarkGfm from "remark-gfm";

// DON'T EVER MOVE THIS TO NON-RELATIVE IMPORTS
// IT'LL BREAK
import { Post } from "./content/definitions/Post";
import { HEADING_LINK_ANCHOR } from "./src/lib/constants";
import {
Expand Down
1 change: 1 addition & 0 deletions apps/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"react-i18next": "^12.2.0",
"react-icons": "^4.8.0",
"react-transition-group": "^4.4.5",
"reading-time": "^1.5.0",
"rehype-pretty-code": "^0.9.4",
"sharp": "^0.31.3",
"shiki": "^0.14.1",
Expand Down
5 changes: 4 additions & 1 deletion apps/client/public/locales/en-US/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
"back-to-home": "Go back to Home"
}
},
"loading": "Loading..."
"loading": "Loading...",
"blog": {
"readtime": "{{minutes}} min read"
}
}
3 changes: 3 additions & 0 deletions apps/client/src/@types/contentlayer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ type PostProps = {
code: string;
raw?: string;
};
readingTime: {
minutes: number;
};
status?: string;
headings?: string[];
tweetIds?: string[];
Expand Down
5 changes: 2 additions & 3 deletions apps/client/src/components/Container/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import { useContext } from "react";

import { Main } from "@app/components/Container/Main";
import { Header } from "@app/components/Header";
import { Sidebar } from "@app/components/Sidebar";
import { SidebarContext, SidebarProvider } from "@app/context/SidebarContext";
import { useTheme } from "@app/context/ThemeContext";

import { Sidebar } from "../Sidebar";

interface ILayout {
children: React.ReactNode;
}
Expand All @@ -24,7 +23,7 @@ export function Layout({ children }: ILayout) {
}`}
>
<Sidebar />
<div className="flex flex-col flex-1 w-full">
<div className="flex flex-col inset-0 w-full">
<Header />
<Main>{children}</Main>
</div>
Expand Down
6 changes: 3 additions & 3 deletions apps/client/src/components/Container/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { ReactNode, useLayoutEffect, useState } from "react";
import { useRouter } from "next/router";
import { useTranslation } from "next-i18next";

import { Breadcrumb } from "../Breadcrumb";
import { BreadcrumbItem } from "../Breadcrumb/BreadcrumbItem";
import { Breadcrumb } from "@app/components/Breadcrumb";
import { BreadcrumbItem } from "@app/components/Breadcrumb/BreadcrumbItem";

interface IMain {
children: ReactNode;
Expand Down Expand Up @@ -35,7 +35,7 @@ export function Main({ children }: IMain) {
}, [router.asPath]);

return (
<main className="transition-all border border-l-gray-400 border-t-gray-400 dark:border-l-gray-600 dark:border-t-gray-600 duration-150 h-full lg:rounded-tl-3xl overflow-y-auto text-gray-800 dark:text-gray-100 bg-gray-100 dark:bg-gray-950">
<main className="transition-all lg:border lg:border-l-gray-400 lg:border-t-gray-400 dark:lg:border-l-gray-600 dark:lg:border-t-gray-600 duration-150 h-full lg:rounded-tl-3xl overflow-y-auto text-gray-800 dark:text-gray-100 bg-gray-100 dark:bg-gray-950">
<div className="transition-all duration-150 flex sticky top-0 z-30 shadow-sm shadow-gray-300 dark:shadow-gray-900 bg-gray-100 dark:bg-gray-950 gap-x-2 px-6">
<Breadcrumb>
<BreadcrumbItem href="/">{t("common:app-name")}</BreadcrumbItem>
Expand Down
160 changes: 73 additions & 87 deletions apps/client/src/components/DynamicCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
import { useRouter } from "next/router";
import { useTranslation } from "next-i18next";

import { StatusButton } from "../Button/Status";
import { StatusButton } from "@app/components/Button/Status";
import { Spinner } from "@app/components/Spinner";

interface DynamicCardProps {
dynamic: Dynamic;
Expand All @@ -25,65 +26,42 @@ export function DynamicCard({ dynamic }: DynamicCardProps) {

return (
<div
className={clsx(
"p-2 flex flex-col gap-2 md:flex-row rounded-md w-full border",
{
"bg-cyan-400/20 border-cyan-600": dynamic.status === "running",
"bg-zinc-400/20 border-zinc-600": dynamic.status === "canceled",
"bg-yellow-400/20 border-yellow-600": dynamic.status === "queued",
"bg-emerald-400/20 border-emerald-600": dynamic.status === "finished",
"bg-red-400/20 border-red-600": dynamic.status === "error"
}
)}
className={clsx("p-2 flex gap-2 rounded-md w-full border", {
"bg-cyan-400/20 border-cyan-600": dynamic.status === "running",
"bg-zinc-400/20 border-zinc-600": dynamic.status === "canceled",
"bg-yellow-400/20 border-yellow-600": dynamic.status === "queued",
"bg-emerald-400/20 border-emerald-600": dynamic.status === "finished",
"bg-red-400/20 border-red-600": dynamic.status === "error"
})}
key={dynamic.celeryId}
>
{dynamic.status === "finished" ? (
<CheckCircle className="mt-2 h-8 w-8 stroke-emerald-950" />
<CheckCircle className="mt-2 min-h-[2rem] min-w-[2rem] stroke-emerald-950 dark:stroke-emerald-300" />
) : null}
{dynamic.status === "canceled" ? (
<Slash className="mt-2 h-8 w-8 stroke-zinc-950" />
<Slash className="mt-2 min-h-[2rem] min-w-[2rem] stroke-zinc-950 dark:stroke-zinc-300" />
) : null}
{dynamic.status === "queued" ? (
<Clock className="mt-2 h-8 w-8 stroke-yellow-950" />
<Clock className="mt-2 min-h-[2rem] min-w-[2rem] stroke-yellow-950 dark:stroke-yellow-300" />
) : null}
{dynamic.status === "error" ? (
<XCircle className="mt-2 h-8 w-8 stroke-red-950" />
<XCircle className="mt-2 min-h-[2rem] min-w-[2rem] stroke-red-950 dark:stroke-red-300" />
) : null}
{dynamic.status === "running" ? (
<div
className="mt-2 z-0"
role="status"
>
<svg
aria-hidden="true"
className="w-8 h-8 text-blue-100 animate-spin fill-blue-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>
<Spinner className="text-blue-100 min-h-[2rem] min-w-[2rem] fill-blue-950 dark:fill-blue-300" />
) : null}
<div>
<div className="flex flex-col gap-y-2">
<small className="text-xs leading-none">
{t("my-dynamics:dynamic.id")}: {dynamic.celeryId}
</small>
<p
className={clsx("flex", {
"text-cyan-950": dynamic.status === "running",
"text-zinc-950": dynamic.status === "canceled",
"text-yellow-950": dynamic.status === "queued",
"text-emerald-950": dynamic.status === "finished",
"text-red-950": dynamic.status === "error"
"text-cyan-950 dark:text-cyan-300": dynamic.status === "running",
"text-zinc-950 dark:text-zinc-300": dynamic.status === "canceled",
"text-yellow-950 dark:text-yellow-300": dynamic.status === "queued",
"text-emerald-950 dark:text-emerald-300":
dynamic.status === "finished",
"text-red-950 dark:text-red-300": dynamic.status === "error"
})}
>
<p className="font-bold">{dynamic.type}</p>: {dynamic.molecule} @{" "}
Expand All @@ -96,50 +74,58 @@ export function DynamicCard({ dynamic }: DynamicCardProps) {
second: "2-digit"
}).format(new Date(dynamic.timestamp))}
</p>
<small className="flex gap-x-1">
<Download className="h-4 w-4" />
{t("my-dynamics:downloads.title")}
</small>
<div className="flex gap-x-1 flex-wrap">
<StatusButton
LeftIcon={FileCode}
onClick={() =>
router.push(`/api/downloads/commands?taskId=${dynamic.celeryId}`)
}
status={dynamic.status}
>
{t("my-dynamics:downloads.commands")}
</StatusButton>
<StatusButton
disabled={dynamic.status === "running"}
LeftIcon={Scroll}
onClick={() =>
router.push(`/api/downloads/log?taskId=${dynamic.celeryId}`)
}
status={dynamic.status}
>
{t("my-dynamics:downloads.log")}
</StatusButton>
<StatusButton
disabled={dynamic.status === "running"}
LeftIcon={FileDigit}
onClick={() =>
router.push(`/api/downloads/results?taskId=${dynamic.celeryId}`)
}
status={dynamic.status}
>
{t("my-dynamics:downloads.results")}
</StatusButton>
<StatusButton
disabled={dynamic.status === "running"}
LeftIcon={Image}
onClick={() =>
router.push(`/api/downloads/figures?taskId=${dynamic.celeryId}`)
}
status={dynamic.status}
>
{t("my-dynamics:downloads.figures")}
</StatusButton>
<div className="flex flex-col gap-y-1">
<small className="flex gap-x-1">
<Download className="h-4 w-4" />
{t("my-dynamics:downloads.title")}
</small>
<div className="flex gap-2 flex-wrap">
<StatusButton
className="w-full md:w-fit"
LeftIcon={FileCode}
onClick={() =>
router.push(
`/api/downloads/commands?taskId=${dynamic.celeryId}`
)
}
status={dynamic.status}
>
{t("my-dynamics:downloads.commands")}
</StatusButton>
<StatusButton
className="w-full md:w-fit"
disabled={dynamic.status === "running"}
LeftIcon={Scroll}
onClick={() =>
router.push(`/api/downloads/log?taskId=${dynamic.celeryId}`)
}
status={dynamic.status}
>
{t("my-dynamics:downloads.log")}
</StatusButton>
<StatusButton
className="w-full md:w-fit"
disabled={dynamic.status === "running"}
LeftIcon={FileDigit}
onClick={() =>
router.push(`/api/downloads/results?taskId=${dynamic.celeryId}`)
}
status={dynamic.status}
>
{t("my-dynamics:downloads.results")}
</StatusButton>
<StatusButton
className="w-full md:w-fit"
disabled={dynamic.status === "running"}
LeftIcon={Image}
onClick={() =>
router.push(`/api/downloads/figures?taskId=${dynamic.celeryId}`)
}
status={dynamic.status}
>
{t("my-dynamics:downloads.figures")}
</StatusButton>
</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useTranslation } from "next-i18next";

import { Spinner } from "../Spinner";
import { Spinner } from "@app/components/Spinner";

interface DynamicRunningRealtimeLogProps {
logLines: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import clsx from "clsx";
import { ArrowRight, CheckCircle, Clock } from "lucide-react";
import { useTranslation } from "next-i18next";

import { Spinner } from "../Spinner";
import { Spinner } from "@app/components/Spinner";

interface DynamicRunningStepListProps {
activeSteps: string[];
Expand Down
9 changes: 4 additions & 5 deletions apps/client/src/components/Forms/ACPYPE.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { useRouter } from "next/router";
import { User } from "next-auth";
import { useTranslation } from "next-i18next";

import { Button } from "@app/components/Button";
import { Input } from "@app/components/Input";
import { Select } from "@app/components/Select";
import { Switch } from "@app/components/Switch";
import { api } from "@app/lib/api";
import {
ACPYPEFormSchema,
Expand All @@ -14,11 +18,6 @@ import { boxTypes } from "@app/utils/box-types";
import { acpypeForceFields } from "@app/utils/force-fields";
import { waterModels } from "@app/utils/water-models";

import { Button } from "../Button";
import { Input } from "../Input";
import { Select } from "../Select";
import { Switch } from "../Switch";

interface ACPYPEFormProps {
user: User;
}
Expand Down
9 changes: 4 additions & 5 deletions apps/client/src/components/Forms/APO.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { useRouter } from "next/router";
import { User } from "next-auth";
import { useTranslation } from "next-i18next";

import { Button } from "@app/components/Button";
import { Input } from "@app/components/Input";
import { Select } from "@app/components/Select";
import { Switch } from "@app/components/Switch";
import { api } from "@app/lib/api";
import {
APOFormSchema,
Expand All @@ -14,11 +18,6 @@ import { boxTypes } from "@app/utils/box-types";
import { apoForceFields } from "@app/utils/force-fields";
import { waterModels } from "@app/utils/water-models";

import { Button } from "../Button";
import { Input } from "../Input";
import { Select } from "../Select";
import { Switch } from "../Switch";

interface APOFormProps {
user: User;
}
Expand Down
9 changes: 4 additions & 5 deletions apps/client/src/components/Forms/PRODRG.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { useRouter } from "next/router";
import { User } from "next-auth";
import { useTranslation } from "next-i18next";

import { Button } from "@app/components/Button";
import { Input } from "@app/components/Input";
import { Select } from "@app/components/Select";
import { Switch } from "@app/components/Switch";
import { api } from "@app/lib/api";
import {
PRODRGFormSchema,
Expand All @@ -14,11 +18,6 @@ import { boxTypes } from "@app/utils/box-types";
import { prodrgForceFields } from "@app/utils/force-fields";
import { waterModels } from "@app/utils/water-models";

import { Button } from "../Button";
import { Input } from "../Input";
import { Select } from "../Select";
import { Switch } from "../Switch";

interface PRODRGFormProps {
user: User;
}
Expand Down

0 comments on commit 2d2b316

Please sign in to comment.