Skip to content

Commit

Permalink
Upgrade prettier, add some ui elements, add the Register page. (#670)
Browse files Browse the repository at this point in the history
  • Loading branch information
acrantel committed Feb 8, 2024
1 parent 4fefb80 commit 3166ce9
Show file tree
Hide file tree
Showing 29 changed files with 885 additions and 490 deletions.
7 changes: 0 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ repos:
args: ["--fix=lf"]
- id: trailing-whitespace

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
hooks:
- id: prettier
types_or: [css, html, javascript, json, jsx, markdown]
exclude: ^frontend/public/assets

- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.5.1
hooks:
Expand Down
4 changes: 3 additions & 1 deletion frontend2/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{}
{
"plugins": ["prettier-plugin-tailwindcss"]
}
213 changes: 108 additions & 105 deletions frontend2/package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion frontend2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"dependencies": {
"@headlessui/react": "^1.7.15",
"@headlessui/tailwindcss": "^0.2.0",
"@heroicons/react": "^2.0.18",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
Expand Down Expand Up @@ -60,7 +61,8 @@
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-react": "^7.32.2",
"js-cookie": "^3.0.5",
"prettier": "2.8.8",
"prettier": "^3.0.2",
"prettier-plugin-tailwindcss": "^0.5.3",
"react-scripts": "5.0.1",
"tailwindcss": "^3.3.2",
"typescript": "^4.9.5"
Expand Down
14 changes: 7 additions & 7 deletions frontend2/src/components/BattlecodeTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ function BattlecodeTable<T>({
bottomElement,
}: TableProps<T>): React.ReactElement {
return (
<div className="w-5/6 pl-50">
<table className="w-full text-sm text-left text-gray-500">
<thead className="text-xs text-gray-700 uppercase bg-gray-50">
<div className="pl-50 w-5/6">
<table className="w-full text-left text-sm text-gray-500">
<thead className="bg-gray-50 text-xs uppercase text-gray-700">
<tr>
{columns.map((col, idx) => (
<th key={idx} scope="col" className="px-8 py-3">
Expand All @@ -48,12 +48,12 @@ function BattlecodeTable<T>({
}}
className={
idx % 2 === 0
? `bg-white border-b ${
? `border-b bg-white ${
onRowClick !== undefined
? "cursor-pointer hover:bg-gray-100 hover:text-gray-700"
: ""
}}`
: `bg-gray-50 border-b ${
: `border-b bg-gray-50 ${
onRowClick !== undefined
? "cursor-pointer hover:bg-gray-100 hover:text-gray-700"
: ""
Expand All @@ -64,7 +64,7 @@ function BattlecodeTable<T>({
<th
key={idx}
scope="row"
className="px-8 py-3 font-medium text-gray-900 whitespace-nowrap"
className="whitespace-nowrap px-8 py-3 font-medium text-gray-900"
>
{col.value(row)}
</th>
Expand All @@ -74,7 +74,7 @@ function BattlecodeTable<T>({
</tbody>
</table>
{loading && (
<div className="w-full h-64 flex flex-row items-center justify-center">
<div className="flex h-64 w-full flex-row items-center justify-center">
<Spinner />
</div>
)}
Expand Down
10 changes: 5 additions & 5 deletions frontend2/src/components/BattlecodeTableBottomElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ const BattlecodeTableBottomElement: React.FC<TableBottomProps> = ({
return [1, "..."].concat(
Array.from(
{ length: MAX_PAGES - 2 },
(_, idx) => pageCount - MAX_PAGES + idx + 3
)
(_, idx) => pageCount - MAX_PAGES + idx + 3,
),
);
} else {
return [1, "..."]
.concat(
Array.from(
{ length: MAX_PAGES - 4 },
(_, idx) => idx + currentPage - 5
)
(_, idx) => idx + currentPage - 5,
),
)
.concat(["...", pageCount]);
}
Expand All @@ -73,7 +73,7 @@ const BattlecodeTableBottomElement: React.FC<TableBottomProps> = ({
</span>{" "}
of <span className="font-semibold text-gray-900">{totalCount}</span>
</span>
<ul className="inline-flex -space-x-px text-sm h-8">
<ul className="inline-flex h-8 -space-x-px text-sm">
<li>
<DirectionPageButton
forward={false}
Expand Down
2 changes: 1 addition & 1 deletion frontend2/src/components/EpisodeLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const EpisodeLayout: React.FC = () => {
return (
<div className="h-screen">
<Navbar />
<div className="flex flex-row h-full">
<div className="flex h-full flex-row">
<Sidebar />
<Outlet />
</div>
Expand Down
2 changes: 1 addition & 1 deletion frontend2/src/components/PrivateRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const PrivateRoute: React.FC = () => {
return null;
} else {
return (
<div className="h-screen flex items-center justify-center">
<div className="flex h-screen items-center justify-center">
<Spinner />
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion frontend2/src/components/Spinner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Spinner: React.FC<SpinnerProps> = ({ size }) => (
aria-hidden="true"
className={`w-${size ?? 16} h-${
size ?? 16
} mr-2 text-gray-200 animate-spin fill-blue-600`}
} mr-2 animate-spin fill-blue-600 text-gray-200`}
// className="w-16 h-16 mr-2 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600"
viewBox="0 0 100 101"
fill="none"
Expand Down
25 changes: 19 additions & 6 deletions frontend2/src/components/elements/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
import React from "react";
import Icon, { type IconName } from "./Icon";

interface ButtonProps extends React.ComponentPropsWithoutRef<"button"> {
variant?: string;
label?: string;
iconName?: IconName;
fullWidth?: boolean;
className?: string;
}

const variants: Record<string, string> = {
"": "bg-gray-50 text-gray-900 hover:bg-gray-100 ring-gray-300 ring-1 ring-inset",
dark: "bg-gray-700 text-gray-50 hover:bg-gray-800",
"": "bg-gray-50 text-gray-800 hover:bg-gray-100 hover:ring-gray-900 hover:text-black ring-gray-500 ring-1 ring-inset",
dark: "bg-cyan-700 text-white hover:bg-cyan-800",
};

const Button: React.FC<ButtonProps> = ({ variant, label, ...rest }) => {
variant = variant ?? "";
const variantStyle = variants[variant];
const Button: React.FC<ButtonProps> = ({
variant = "",
label,
iconName,
fullWidth = false,
className = "",
...rest
}) => {
const variantStyle = `${variants[variant]} ${
fullWidth ? "w-full" : ""
} ${className}`;
return (
<button
// default button type
type="button"
className={`rounded-md px-2.5 py-1.5 text-sm font-semibold shadow-sm ${variantStyle}`}
className={`flex h-9 flex-row items-center justify-center gap-1.5 rounded px-2.5 py-1.5 font-medium shadow-sm ${variantStyle}`}
{...rest}
>
{iconName !== undefined && <Icon name={iconName} size="sm" />}
{label}
</button>
);
Expand Down
17 changes: 17 additions & 0 deletions frontend2/src/components/elements/FormError.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from "react";

const FormError: React.FC<{ message?: string; className?: string }> = ({
message,
className,
}) => {
return (
<span
role="alert"
className={`absolute mt-0.5 text-xs text-red-700 ${className ?? ""}`}
>
{message ?? "This field is invalid."}
</span>
);
};

export default FormError;
20 changes: 20 additions & 0 deletions frontend2/src/components/elements/FormLabel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from "react";

const FormLabel: React.FC<{
label?: string;
required?: boolean;
className?: string;
}> = ({ label, required = false, className }) => {
return (
<div
className={`flex flex-row items-center gap-1 text-sm font-medium leading-6 text-gray-700 ${
className ?? ""
}`}
>
{label}
{required && <span className="text-red-700"> *</span>}
</div>
);
};

export default FormLabel;
85 changes: 85 additions & 0 deletions frontend2/src/components/elements/Icon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import React from "react";
import {
ClipboardDocumentIcon as ClipboardDocumentIcon24,
HomeIcon as HomeIcon24,
MapIcon as MapIcon24,
TrophyIcon as TrophyIcon24,
ChartBarIcon as ChartBarIcon24,
ClockIcon as ClockIcon24,
UserGroupIcon as UserGroupIcon24,
ArrowUpTrayIcon as ArrowUpTrayIcon24,
PlayCircleIcon as PlayCircleIcon24,
ChevronDownIcon as ChevronDownIcon24,
CheckIcon as CheckIcon24,
InformationCircleIcon as InformationCircleIcon24,
} from "@heroicons/react/24/outline";

import {
ClipboardDocumentIcon as ClipboardDocumentIcon20,
HomeIcon as HomeIcon20,
MapIcon as MapIcon20,
TrophyIcon as TrophyIcon20,
ChartBarIcon as ChartBarIcon20,
ClockIcon as ClockIcon20,
UserGroupIcon as UserGroupIcon20,
ArrowUpTrayIcon as ArrowUpTrayIcon20,
PlayCircleIcon as PlayCircleIcon20,
ChevronDownIcon as ChevronDownIcon20,
CheckIcon as CheckIcon20,
InformationCircleIcon as InformationCircleIcon20,
} from "@heroicons/react/20/solid";

const icons24 = {
clipboard_document: ClipboardDocumentIcon24,
home: HomeIcon24,
map: MapIcon24,
trophy: TrophyIcon24,
chart_bar: ChartBarIcon24,
clock: ClockIcon24,
user_group: UserGroupIcon24,
arrow_up_tray: ArrowUpTrayIcon24,
play_circle: PlayCircleIcon24,
chevron_down: ChevronDownIcon24,
check: CheckIcon24,
information_circle: InformationCircleIcon24,
};

const icons20 = {
clipboard_document: ClipboardDocumentIcon20,
home: HomeIcon20,
map: MapIcon20,
trophy: TrophyIcon20,
chart_bar: ChartBarIcon20,
clock: ClockIcon20,
user_group: UserGroupIcon20,
arrow_up_tray: ArrowUpTrayIcon20,
play_circle: PlayCircleIcon20,
chevron_down: ChevronDownIcon20,
check: CheckIcon20,
information_circle: InformationCircleIcon20,
};

export type IconName = keyof typeof icons24 | keyof typeof icons20;

export interface IconProps {
name: IconName;
size?: "sm" | "md" | "xs";
className?: string;
}

const sizeToClass = {
sm: "h-5 w-5",
md: "h-6 w-6",
xs: "h-4 w-4",
};

const Icon: React.FC<IconProps> = ({
name,
size = "md",
className = "",
}: IconProps) => {
const IconComponent = size === "md" ? icons24[name] : icons20[name];
return <IconComponent className={`${sizeToClass[size]} ${className}`} />;
};

export default Icon;
42 changes: 23 additions & 19 deletions frontend2/src/components/elements/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
import React, { forwardRef } from "react";
import FormError from "./FormError";
import FormLabel from "./FormLabel";

interface InputProps extends React.ComponentPropsWithoutRef<"input"> {
label?: string;
required?: boolean;
className?: string;
errorMessage?: string;
}

const Input = forwardRef<HTMLInputElement, InputProps>(function Input(
{ label, required, ...rest },
ref
{ label, required = false, className = "", errorMessage, ...rest },
ref,
) {
required = required ?? false;
const invalid = errorMessage !== undefined;
return (
<div className="w-full">
{label !== undefined && (
<label className="flex flex-col w-full gap-1 text-sm font-medium leading-6 text-gray-900">
<span>
{label}
{required && <span className="text-red-700"> *</span>}
</span>
</label>
)}
<div className="relative rounded-md shadow-sm">
<input
ref={ref}
className="block w-full rounded-md border-0 py-1.5 px-2 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-1 focus:ring-inset focus:ring-gray-700 sm:text-sm sm:leading-6"
{...rest}
/>
</div>
<div className={`relative ${invalid ? "mb-1" : ""} ${className}`}>
<label>
<FormLabel label={label} required={required} />
<div className="relative rounded-md shadow-sm">
<input
ref={ref}
aria-invalid={errorMessage !== undefined ? "true" : "false"}
className={`block w-full rounded-md border-0 px-2 py-1.5 text-gray-900 ring-1 ring-inset
ring-gray-300 placeholder:text-gray-400 focus:outline-none focus:ring-1 focus:ring-inset
focus:ring-cyan-600 sm:text-sm sm:leading-6
${invalid ? "ring-red-500" : ""}`}
{...rest}
/>
</div>
{invalid && <FormError message={errorMessage} />}
</label>
</div>
);
});
Expand Down
Loading

0 comments on commit 3166ce9

Please sign in to comment.