Skip to content

Commit

Permalink
Added humble beginnings of frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkmcc committed Nov 13, 2023
1 parent d48ad77 commit efee572
Show file tree
Hide file tree
Showing 26 changed files with 2,822 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/frontend/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
24 changes: 24 additions & 0 deletions app/frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
27 changes: 27 additions & 0 deletions app/frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
```

- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
13 changes: 13 additions & 0 deletions app/frontend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
38 changes: 38 additions & 0 deletions app/frontend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "frontend",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"@auth0/auth0-react": "^2.2.3",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@fontsource/inter": "^5.0.15",
"@mui/icons-material": "^5.14.16",
"@mui/joy": "^5.0.0-beta.14",
"@mui/material": "^5.14.17",
"@tanstack/react-router": "^0.0.1-beta.209",
"@tanstack/router-devtools": "^0.0.1-alpha.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@vitejs/plugin-react": "^4.0.3",
"eslint": "^8.45.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"prettier": "^3.0.3",
"typescript": "^5.0.2",
"vite": "^4.4.5"
}
}
1 change: 1 addition & 0 deletions app/frontend/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added app/frontend/src/App.css
Empty file.
99 changes: 99 additions & 0 deletions app/frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import "./App.css";
import { useAuth0, withAuthenticationRequired } from "@auth0/auth0-react";
import Sidebar from "./components/Sidebar.tsx";
import Box from "@mui/joy/Box";
import {
Outlet,
RootRoute,
Route,
Router,
RouterProvider,
} from "@tanstack/react-router";
import { Home } from "./routes";
import { Projects } from "./routes/Projects.tsx";
import { Agents, AllHosts, Deploy, Groups } from "./routes/hosts";

const rootRoute = new RootRoute({
component: withAuthenticationRequired(Root),
});

const homeRoute = new Route({
getParentRoute: () => rootRoute,
component: Home,
path: "/",
});

const projectsRoute = new Route({
getParentRoute: () => rootRoute,
component: Projects,
path: "/projects",
});

const hostsRoute = new Route({
getParentRoute: () => rootRoute,
path: "/hosts",
});

const hostsAllRoute = new Route({
getParentRoute: () => hostsRoute,
path: "/",
component: AllHosts,
});

const hostsGroupsRoute = new Route({
getParentRoute: () => hostsRoute,
path: "/groups",
component: Groups,
});

const hostsAgentsRoute = new Route({
getParentRoute: () => hostsRoute,
path: "/agents",
component: Agents,
});

const hostsDeployRoute = new Route({
getParentRoute: () => hostsRoute,
path: "/deploy",
component: Deploy,
});

const settingsRoute = new Route({
getParentRoute: () => rootRoute,
path: "/settings",
component: () => <p>Settings route</p>,
});

const routeTree = rootRoute.addChildren([
homeRoute,
projectsRoute,
hostsRoute,
hostsAllRoute,
hostsGroupsRoute,
hostsAgentsRoute,
hostsDeployRoute,
settingsRoute,
]);
const router = new Router({ routeTree });

declare module "@tanstack/react-router" {
interface Register {
router: typeof router;
}
}

function Root() {
return (
<Box sx={{ display: "flex", minHeight: "100dvh" }}>
<Sidebar />
<Outlet />
</Box>
);
}

function App() {
const auth0 = useAuth0();
return <RouterProvider router={router} context={{ auth0 }} />;
}

export default App;
1 change: 1 addition & 0 deletions app/frontend/src/assets/react.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions app/frontend/src/components/ColorSchemeToggle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import DarkModeRoundedIcon from "@mui/icons-material/DarkModeRounded";
import LightModeIcon from "@mui/icons-material/LightMode";
import { IconButtonProps, useColorScheme } from "@mui/joy";
import { useEffect, useState } from "react";
import IconButton from "@mui/joy/IconButton";

export default function ColorSchemeToggle({
onClick,
sx,
...props
}: IconButtonProps) {
const { mode, setMode } = useColorScheme();
const [mounted, setMounted] = useState(false);
useEffect(() => {
setMounted(true);
}, []);
if (!mounted) {
return (
<IconButton
size="sm"
variant="outlined"
color="neutral"
{...props}
sx={sx}
disabled
/>
);
}
return (
<IconButton
id="toggle-mode"
size="sm"
variant="outlined"
color="neutral"
{...props}
onClick={(event) => {
if (mode === "light") {
setMode("dark");
} else {
setMode("light");
}
onClick?.(event);
}}
sx={[
{
"& > *:first-child": {
display: mode === "dark" ? "none" : "initial",
},
"& > *:last-child": {
display: mode === "light" ? "none" : "initial",
},
},
...(Array.isArray(sx) ? sx : [sx]),
]}
>
<DarkModeRoundedIcon />
<LightModeIcon />
</IconButton>
);
}
Loading

0 comments on commit efee572

Please sign in to comment.