Skip to content

Commit

Permalink
ci: adds prettier formatting file and formats all frontend files
Browse files Browse the repository at this point in the history
  • Loading branch information
calisio committed Aug 7, 2024
1 parent 2805242 commit ee300e6
Show file tree
Hide file tree
Showing 102 changed files with 6,626 additions and 6,249 deletions.
30 changes: 15 additions & 15 deletions frontend/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,18 +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 },
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 }
]
}
};
2 changes: 1 addition & 1 deletion frontend/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "next/core-web-vitals"
"extends": "next/core-web-vitals"
}
6 changes: 6 additions & 0 deletions frontend/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "none",
"tabWidth": 4,
"semi": true,
"singleQuote": true
}
26 changes: 13 additions & 13 deletions frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ This template provides a minimal setup to get React working in Vite with HMR and

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
- [@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:
- Configure the top-level `parserOptions` property like this:

```js
export default {
// other rules...
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
project: ["./tsconfig.json", "./tsconfig.node.json"],
tsconfigRootDir: __dirname,
},
// other rules...
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
- 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
18 changes: 9 additions & 9 deletions frontend/index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>UnlockEd</title>
<link href="/fonts/fonts.css" rel="stylesheet" type="text/css" />
</head>
<head>
<meta charset="UTF-8" />
<title>UnlockEd</title>
<link href="/fonts/fonts.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
94 changes: 47 additions & 47 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
{
"name": "unlockedv2",
"private": true,
"version": "0.0.0",
"type": "module",
"proxy": "http://localhost:8080",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint-staged": "oxlint src",
"preview": "vite preview",
"prepare": "cd .. && husky frontend/.husky"
},
"dependencies": {
"autoprefixer": "^10.4.19",
"axios": "^1.6.8",
"daisyui": "^4.10.5",
"oxlint": "^0.3.2",
"postcss": "^8.4.38",
"prettier": "^3.2.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.51.3",
"react-router-dom": "^6.23.0",
"recharts": "^2.12.7",
"swr": "^2.2.5",
"tailwindcss": "^3.4.3",
"usehooks-ts": "^3.1.0"
},
"devDependencies": {
"@heroicons/react": "^2.0.18",
"@tailwindcss/forms": "^0.5.3",
"@tailwindcss/typography": "^0.5.10",
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^8.57.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"husky": "^9.0.11",
"typescript": "^5.2.2",
"vite": "^5.2.0"
},
"lint-staged": {
"**/*.{js,tsx,ts,css,md}": "prettier --write"
}
"name": "unlockedv2",
"private": true,
"version": "0.0.0",
"type": "module",
"proxy": "http://localhost:8080",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint-staged": "oxlint src",
"preview": "vite preview",
"prepare": "cd .. && husky frontend/.husky"
},
"dependencies": {
"autoprefixer": "^10.4.19",
"axios": "^1.6.8",
"daisyui": "^4.10.5",
"oxlint": "^0.3.2",
"postcss": "^8.4.38",
"prettier": "^3.2.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.51.3",
"react-router-dom": "^6.23.0",
"recharts": "^2.12.7",
"swr": "^2.2.5",
"tailwindcss": "^3.4.3",
"usehooks-ts": "^3.1.0"
},
"devDependencies": {
"@heroicons/react": "^2.0.18",
"@tailwindcss/forms": "^0.5.3",
"@tailwindcss/typography": "^0.5.10",
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^8.57.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"husky": "^9.0.11",
"typescript": "^5.2.2",
"vite": "^5.2.0"
},
"lint-staged": {
"**/*.{js,tsx,ts,css,md}": "prettier --write"
}
}
8 changes: 4 additions & 4 deletions frontend/postcss.config.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
plugins: {
tailwindcss: {},
autoprefixer: {}
}
};
126 changes: 63 additions & 63 deletions frontend/src/AuthContext.tsx
Original file line number Diff line number Diff line change
@@ -1,81 +1,81 @@
import "@/bootstrap";
import '@/bootstrap';
import React, {
createContext,
useContext,
useEffect,
useState,
Dispatch,
SetStateAction,
} from "react";
import { User } from "./types";
import axios from "axios";
createContext,
useContext,
useEffect,
useState,
Dispatch,
SetStateAction
} from 'react';
import { User } from './types';
import axios from 'axios';

interface AuthContextType {
user: User | null;
setUser: Dispatch<SetStateAction<User | null>>;
user: User | null;
setUser: Dispatch<SetStateAction<User | null>>;
}

const AuthContext = createContext<AuthContextType | null>(null);

export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
children,
children
}) => {
const [user, setUser] = useState<User | null>(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
const fetchUser = async () => {
try {
const response = await axios.get(`/api/auth`);
setUser(response.data);
} catch (error) {
console.log("Authentication check failed", error);
setUser(null);
} finally {
setLoading(false);
}
};
fetchUser();
}, []);
const [user, setUser] = useState<User | null>(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
const fetchUser = async () => {
try {
const response = await axios.get(`/api/auth`);
setUser(response.data);
} catch (error) {
console.log('Authentication check failed', error);
setUser(null);
} finally {
setLoading(false);
}
};
fetchUser();
}, []);

if (loading) {
return <div>Loading...</div>;
}
if (!user) {
return null;
} else if (
user.password_reset === true &&
window.location.pathname !== "/reset-password"
) {
window.location.href = "/reset-password";
return null;
}
return (
<AuthContext.Provider value={{ user, setUser }}>
{children}
</AuthContext.Provider>
);
if (loading) {
return <div>Loading...</div>;
}
if (!user) {
return null;
} else if (
user.password_reset === true &&
window.location.pathname !== '/reset-password'
) {
window.location.href = '/reset-password';
return null;
}
return (
<AuthContext.Provider value={{ user, setUser }}>
{children}
</AuthContext.Provider>
);
};

export const useAuth = () => {
const context = useContext(AuthContext);
if (!context) {
throw new Error("useAuth must be used within an AuthProvider");
}
return context;
const context = useContext(AuthContext);
if (!context) {
throw new Error('useAuth must be used within an AuthProvider');
}
return context;
};

export const handleLogout = async () => {
try {
await axios.post("/api/logout");
const logout_response = await axios.get("/self-service/logout/browser");
if (logout_response.data.logout_url) {
window.location.href = logout_response.data.logout_url;
} else {
console.log("Logout failed", logout_response);
window.location.href = "/self-service/login/browser";
try {
await axios.post('/api/logout');
const logout_response = await axios.get('/self-service/logout/browser');
if (logout_response.data.logout_url) {
window.location.href = logout_response.data.logout_url;
} else {
console.log('Logout failed', logout_response);
window.location.href = '/self-service/login/browser';
}
} catch (error) {
window.location.href = '/login';
console.log('Logout failed', error);
}
} catch (error) {
window.location.href = "/login";
console.log("Logout failed", error);
}
};
4 changes: 2 additions & 2 deletions frontend/src/Components/ApplicationLogo.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HTMLAttributes } from "react";
import { HTMLAttributes } from 'react';

export default function ApplicationLogo(props: HTMLAttributes<HTMLElement>) {
return <img {...props} src="/ul-logo.png" />;
return <img {...props} src="/ul-logo.png" />;
}
20 changes: 10 additions & 10 deletions frontend/src/Components/Brand.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export default function Brand() {
return (
<div className="flex flex-col justify-between items-center space-x-2">
<img className="h-12" src="/ul-logo.png" />
<h1 className="text-2xl">
<span className="text-primary">Unlock</span>
<span className="text-secondary">Ed</span>
<span className="text-base">v2</span>
</h1>
</div>
);
return (
<div className="flex flex-col justify-between items-center space-x-2">
<img className="h-12" src="/ul-logo.png" />
<h1 className="text-2xl">
<span className="text-primary">Unlock</span>
<span className="text-secondary">Ed</span>
<span className="text-base">v2</span>
</h1>
</div>
);
}
Loading

0 comments on commit ee300e6

Please sign in to comment.