Skip to content

Commit

Permalink
docs: added documentation + some housekeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
jeafreezy committed Oct 21, 2024
1 parent 8bc4a82 commit f9202a4
Show file tree
Hide file tree
Showing 64 changed files with 546 additions and 178 deletions.
3 changes: 2 additions & 1 deletion frontend/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# fAIr Frontend

This project is a frontend web application built using **React 18**, **TypeScript**, and **Vite**. The app leverages modern libraries such as **@hotosm/ui**, **Shoelace**, and **Framer Motion** for UI components, and **React Router** for client-side routing.
This project is a frontend web application built using **React 18**, **TypeScript**, and **Vite**. The app leverages modern libraries such as **@hotosm/ui**, and **Shoelace** for UI components, and **React Router** for client-side routing.

## Table of Contents

Expand Down Expand Up @@ -60,6 +60,7 @@ Here's an overview of the folder structure:
│ ├── app/ # Contains the application routes and providers.
│ ├── assets/ # Static assets specific to the app (images, icons, etc.).
│ ├── components/ # Reusable components and layouts.
| |── features/ # Contains the main features of the application.
│ ├── hook/ # Reusable hooks.
│ ├── styles/ # Global styles.
│ ├── utils/ # Utility functions, application content and constants.
Expand Down
15 changes: 12 additions & 3 deletions frontend/src/app/routes/models/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
import Pagination, {
PAGE_LIMIT,
} from "@/features/models/components/pagination";
import { buildDateFilterQueryString } from "@/utils";
import { APP_CONTENT, buildDateFilterQueryString } from "@/utils";
import { PageHeader } from "@/features/models/components/";
import { dateFilters } from "@/features/models/components/filters/date-range-filter";
import { ORDERING_FIELDS } from "@/features/models/components/filters/ordering-filter";
Expand Down Expand Up @@ -68,6 +68,7 @@ const ClearFilters = ({
return (
<div className={`${isMobile ? "block md:hidden" : "hidden md:block"}`}>
{canClearAllFilters ? (
// @ts-expect-error bad type definition
<Button variant="tertiary" size="medium" onClick={clearAllFilters}>
Clear filters
</Button>
Expand All @@ -90,7 +91,9 @@ const SetMapToggle = ({
className={`${isMobile ? "inline-flex md:hidden" : "hidden md:inline-flex"} items-center gap-x-4`}
role="button"
>
<p className="text-body-2base text-nowrap">Map View</p>
<p className="text-body-2base text-nowrap">
{APP_CONTENT.models.modelsList.filtersSection.mapViewToggleText}
</p>
<Switch
checked={query[SEARCH_PARAMS.mapIsActive] as boolean}
disabled={query[SEARCH_PARAMS.layout] == LayoutView.LIST}
Expand Down Expand Up @@ -370,7 +373,13 @@ export const ModelsPage = () => {
) : (
<div className="flex items-center justify-between w-full my-10">
<div className="w-full flex items-center justify-between">
<p className="font-semibold text-body-3">{data?.count} models</p>
<p className="font-semibold text-body-3">
{data?.count}{" "}
{
APP_CONTENT.models.modelsList.sortingAndPaginationSection
.modelCountSuffix
}
</p>
<SetMapToggle query={query} updateQuery={updateQuery} isMobile />
</div>
<div className="flex items-center gap-x-9">
Expand Down
16 changes: 11 additions & 5 deletions frontend/src/app/routes/models/model-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { ModelDetailsSkeleton } from "@/features/models/components/skeletons";
import { useModelDetails } from "@/features/models/hooks/use-models";
import { useDialog } from "@/hooks/use-dialog";
import { APPLICATION_ROUTES } from "@/utils";
import { APP_CONTENT, APPLICATION_ROUTES } from "@/utils";
import { useEffect } from "react";
import { useNavigate, useParams } from "react-router-dom";

Expand Down Expand Up @@ -61,25 +61,31 @@ export const ModelDetailsPage = () => {
openModelFilesDialog={openModelFilesDialog}
openTrainingAreaDialog={openDialog}
/>
<ModelDetailsSection title="Properties">
<ModelDetailsSection
title={APP_CONTENT.models.modelsDetailsCard.propertiesSectionTitle}
>
<ModelDetailsProperties
trainingId={data?.published_training as number}
thumbnailURL={data?.thumbnail_url}
/>
</ModelDetailsSection>
<div className="flex md:hidden">
<ButtonWithIcon
label="Submit a training request"
label={APP_CONTENT.models.modelsDetailsCard.submitTrainingRequest}
variant="dark"
size="medium"
prefixIcon={RequestIcon}
/>
</div>
{/* mobile */}
<ModelDetailsSection title="Training History">
<ModelDetailsSection
title={
APP_CONTENT.models.modelsDetailsCard.trainingHistorySectionTitle
}
>
<div className="md:flex self-end hidden">
<ButtonWithIcon
label="Submit a training request"
label={APP_CONTENT.models.modelsDetailsCard.submitTrainingRequest}
variant="dark"
size="medium"
prefixIcon={RequestIcon}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/routes/not-found.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const PageNotFound = () => {
: APP_CONTENT.pageNotFound.messages.pageNotFound}
</p>
</div>
<h1 className="w-[200px] text-[200px] lg:w-[450px] lg:text-[450px] flex items-center justify-center font-semibold text-light-gray relative">
<h1 className="w-72 text-[200px] lg:w-[450px] lg:text-[450px] flex items-center justify-center font-semibold text-light-gray relative">
404
<span className="absolute flex items-center w-full justify-center h-full">
{/* Icon */}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/errors/fallback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const MainErrorFallback = () => {
<Button
variant="primary"
onClick={() => window.location.reload()}
className="max-w-[300px]"
className="max-w-80"
>
{APP_CONTENT.errorBoundary.button}
</Button>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/errors/under-construction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const PageUnderConstruction = () => {
<Button
variant="primary"
onClick={() => window.location.assign(window.location.origin)}
className="max-w-[300px]"
className="max-w-80"
>
{APP_CONTENT.construction.button}
</Button>
Expand Down
Empty file removed frontend/src/components/index.ts
Empty file.
2 changes: 1 addition & 1 deletion frontend/src/components/layouts/root-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useEffect } from "react";

const RootLayout = () => {
const { pathname } = useLocation();
// Scroll to top on new page.
// Scroll to top on page switch.
useEffect(() => {
window.scrollTo(0, 0);
}, [pathname]);
Expand Down
10 changes: 6 additions & 4 deletions frontend/src/components/ui/animated-beam/animated-beam.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { RefObject, useEffect, useId, useState } from "react";
import { motion } from "framer-motion";
import { cn } from "@/utils";

export interface AnimatedBeamProps {
type AnimatedBeamProps = {
className?: string;
containerRef: RefObject<HTMLElement>; // Container ref
containerRef: RefObject<HTMLElement>;
fromRef: RefObject<HTMLElement>;
toRef: RefObject<HTMLElement>;
curvature?: number;
Expand All @@ -23,9 +23,9 @@ export interface AnimatedBeamProps {
startYOffset?: number;
endXOffset?: number;
endYOffset?: number;
}
};

export const AnimatedBeam: React.FC<AnimatedBeamProps> = ({
const AnimatedBeam: React.FC<AnimatedBeamProps> = ({
className,
containerRef,
fromRef,
Expand Down Expand Up @@ -187,3 +187,5 @@ export const AnimatedBeam: React.FC<AnimatedBeamProps> = ({
</svg>
);
};

export default AnimatedBeam;
2 changes: 1 addition & 1 deletion frontend/src/components/ui/animated-beam/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./animated-beam";
export { default as AnimatedBeam } from "./animated-beam";
5 changes: 4 additions & 1 deletion frontend/src/components/ui/badge/badge.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TBadgeVariants } from "@/types";
import { cn } from "@/utils";

type BadgeProps = {
variant: TBadgeVariants;
Expand All @@ -24,7 +25,9 @@ const Badge: React.FC<BadgeProps> = ({
};
return (
<button
className={`h-8 w-fit ${variants[variant]} ${rounded ? "rounded-full p-2" : "rounded-2xl py-1 px-3 "} ${className}`}
className={cn(
`h-8 w-fit ${variants[variant]} ${rounded ? "rounded-full p-2" : "rounded-2xl py-1 px-3 "} ${className}`,
)}
onClick={onClick}
>
<span className="font-medium capitalize text-body-3 flex items-center justify-center">
Expand Down
18 changes: 7 additions & 11 deletions frontend/src/components/ui/button/button.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
import SlButton from "@shoelace-style/shoelace/dist/react/button/index.js";
import "./button.css";
import { Spinner } from "@/components/ui/spinner";

export type ButtonVariant =
| "primary"
| "secondary"
| "tertiary"
| "default"
| "dark";

export type ButtonSize = "large" | "medium" | "small";
import { cn } from "@/utils";
import { ButtonSize, ButtonVariant } from "@/types";

type ButtonProps = {
children: React.ReactNode;
variant?: ButtonVariant;
className?: string;
onClick?: (event: any) => void;
onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void;
spinner?: boolean;
size?: ButtonSize;
disabled?: boolean;
Expand All @@ -41,8 +34,11 @@ const Button: React.FC<ButtonProps> = ({
//@ts-expect-error bad type definition
variant={variant}
size={size}
className={`button ${variant} ${className} ${capitalizeText && "capitalize"}`}
className={cn(
`button ${variant} ${className} ${capitalizeText && "capitalize"}`,
)}
style={{ width: "100%" }}
//@ts-expect-error bad type definition
onClick={onClick}
disabled={disabled}
slot={slot}
Expand Down
24 changes: 13 additions & 11 deletions frontend/src/components/ui/button/icon-button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import Button, { ButtonSize, ButtonVariant } from "./button";
import { ButtonSize, ButtonVariant } from "@/types";
import { Button } from "@/components/ui/button";

const ButtonWithIcon = ({
type ButtonWithIconProps = {
onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void;
label: string;
variant: ButtonVariant;
size?: ButtonSize;
prefixIcon: React.ElementType;
suffixIcon?: React.ElementType;
capitalizeText?: boolean;
className?: string;
};
const ButtonWithIcon: React.FC<ButtonWithIconProps> = ({
onClick,
prefixIcon: PrefixIcon,
suffixIcon: SuffixIcon,
Expand All @@ -9,15 +20,6 @@ const ButtonWithIcon = ({
size = "medium",
capitalizeText = true,
className,
}: {
onClick?: () => void;
label: string;
variant: ButtonVariant;
size?: ButtonSize;
prefixIcon: React.ElementType;
suffixIcon?: React.ElementType;
capitalizeText?: boolean;
className?: string;
}) => (
<div role="button">
<Button
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/ui/codeblock/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./codeblock";
export { default as CodeBlock } from "./codeblock";
12 changes: 7 additions & 5 deletions frontend/src/components/ui/data-table/data-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ import {
TableRow,
} from "@/components/ui/table";

interface DataTableProps<TData, TValue> {
type DataTableProps<TData, TValue> = {
columns: ColumnDef<TData, TValue>[];
data: TData[];
sorting?: SortingState;
setSorting?: React.Dispatch<React.SetStateAction<SortingState>>;
onRowClick?: (row: TData) => void;
}
};

export function DataTable<TData, TValue>({
const DataTable = <TData, TValue>({
columns,
data,
sorting,
setSorting,
onRowClick,
}: DataTableProps<TData, TValue>) {
}: DataTableProps<TData, TValue>) => {
const table = useReactTable({
data,
columns,
Expand Down Expand Up @@ -91,4 +91,6 @@ export function DataTable<TData, TValue>({
</TableBody>
</Table>
);
}
};

export default DataTable;
2 changes: 1 addition & 1 deletion frontend/src/components/ui/data-table/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./data-table";
export { default as DataTable } from "./data-table";
1 change: 0 additions & 1 deletion frontend/src/components/ui/dialog/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const Dialog: React.FC<DialogProps> = ({
e.preventDefault();
closeDialog();
}}

style={{
//@ts-expect-error bad type definition
"--width":
Expand Down
4 changes: 0 additions & 4 deletions frontend/src/components/ui/drawer/drawer.module.css

This file was deleted.

2 changes: 1 addition & 1 deletion frontend/src/components/ui/drawer/drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import "./drawer.css";

type DrawerProps = {
open: boolean;
setOpen: (v: boolean) => void;
setOpen: (open: boolean) => void;
placement: "top" | "bottom" | "end";
children: React.ReactNode;
label?: string;
Expand Down
13 changes: 9 additions & 4 deletions frontend/src/components/ui/dropdown/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import SlCheckbox from "@shoelace-style/shoelace/dist/react/checkbox/index.js";
import "./dropdown.css";
import ChevronDownIcon from "../icons/chevron-down";
import { useEffect, useState } from "react";
import { cn } from "@/utils";

export type DropdownMenuItem = {
value: string;
Expand All @@ -18,8 +19,8 @@ export type DropdownMenuItem = {
type DropDownProps = {
placement?: "bottom-end" | "top-end" | "bottom-start";
children?: React.ReactNode;
onDropdownShow?: () => void;
onDropdownHide?: () => void;
onDropdownShow?: (event: React.MouseEvent<HTMLDivElement>) => void;
onDropdownHide?: (event: React.MouseEvent<HTMLDivElement>) => void;
menuItems?: DropdownMenuItem[];
dropdownIsOpened: boolean;
className?: string;
Expand Down Expand Up @@ -97,7 +98,9 @@ const DropDown: React.FC<DropDownProps> = ({
return (
<SlDropdown
placement={placement}
// @ts-expect-error bad type definition
onSlShow={onDropdownShow}
// @ts-expect-error bad type definition
onSlHide={onDropdownHide}
className={className}
disabled={disabled}
Expand All @@ -111,7 +114,9 @@ const DropDown: React.FC<DropDownProps> = ({
{triggerComponent}
{!disableCheveronIcon && (
<ChevronDownIcon
className={`w-3 h-3 text-dark ml-2 transition-all ${dropdownIsOpened && "rotate-180"}`}
className={cn(
`w-3 h-3 text-dark ml-2 transition-all ${dropdownIsOpened && "rotate-180"}`,
)}
/>
)}
</div>
Expand All @@ -122,7 +127,7 @@ const DropDown: React.FC<DropDownProps> = ({
<SlMenuItem
key={`dropdown-menu-item-${id}`}
value={menuItem.value}
className={`${menuItem.className} ${menuItemTextSize}`}
className={cn(`${menuItem.className} ${menuItemTextSize}`)}
onClick={menuItem.onClick}
disabled={menuItem.disabled ?? false}
>
Expand Down
Empty file.
Loading

0 comments on commit f9202a4

Please sign in to comment.