Skip to content

Commit 7f48311

Browse files
authored
Merge pull request #119 from codeforpdx/install-frontend-formatter
DX: Install formatter for frontend code
2 parents 0a60ccf + a83f4b4 commit 7f48311

File tree

14 files changed

+111
-70
lines changed

14 files changed

+111
-70
lines changed

.github/workflows/pr-check.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ jobs:
6666
- name: Install dependencies
6767
run: npm ci
6868

69+
- name: Run linting checks
70+
run: npm run lint
71+
- name: Run format checks
72+
run: npx prettier --check .
73+
6974
- name: Build frontend
7075
run: npm run build
71-
72-
- name: Run linting checks
73-
run: npm run lint

frontend/eslint.config.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
1-
import js from '@eslint/js'
2-
import globals from 'globals'
3-
import reactHooks from 'eslint-plugin-react-hooks'
4-
import reactRefresh from 'eslint-plugin-react-refresh'
5-
import tseslint from 'typescript-eslint'
1+
import js from "@eslint/js";
2+
import globals from "globals";
3+
import reactHooks from "eslint-plugin-react-hooks";
4+
import reactRefresh from "eslint-plugin-react-refresh";
5+
import tseslint from "typescript-eslint";
6+
import eslintConfigPrettier from "eslint-config-prettier/flat";
67

78
export default tseslint.config(
8-
{ ignores: ['dist'] },
9+
{ ignores: ["dist"] },
910
{
10-
extends: [js.configs.recommended, ...tseslint.configs.recommended],
11-
files: ['**/*.{ts,tsx}'],
11+
extends: [
12+
js.configs.recommended,
13+
...tseslint.configs.recommended,
14+
eslintConfigPrettier,
15+
],
16+
files: ["**/*.{ts,tsx}"],
1217
languageOptions: {
1318
ecmaVersion: 2020,
1419
globals: globals.browser,
1520
},
1621
plugins: {
17-
'react-hooks': reactHooks,
18-
'react-refresh': reactRefresh,
22+
"react-hooks": reactHooks,
23+
"react-refresh": reactRefresh,
1924
},
2025
rules: {
2126
...reactHooks.configs.recommended.rules,
22-
'react-refresh/only-export-components': [
23-
'warn',
27+
"react-refresh/only-export-components": [
28+
"warn",
2429
{ allowConstantExport: true },
2530
],
2631
},
2732
},
28-
)
33+
);

frontend/index.html

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
3-
<head>
4-
<meta charset="UTF-8"/>
3+
<head>
4+
<meta charset="UTF-8" />
55
<title>Tenant First Aid</title>
6-
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<script
8-
src="https://www.datadoghq-browser-agent.com/us5/v6/datadog-rum.js"
9-
type="text/javascript">
10-
</script>
8+
src="https://www.datadoghq-browser-agent.com/us5/v6/datadog-rum.js"
9+
type="text/javascript"
10+
></script>
1111
<script>
12-
window.DD_RUM && window.DD_RUM.init({
13-
clientToken: 'pub14aa0f102cb53f847ac602ce8c2e14b2',
14-
applicationId: '51dade6d-207e-4a25-b659-fbbbe95a48b6',
15-
site: 'us5.datadoghq.com',
16-
service: 'tenant-first-aid',
17-
env: 'prod',
18-
version: '1.0.0',
19-
sessionSampleRate: 100,
20-
sessionReplaySampleRate: 100,
21-
defaultPrivacyLevel: 'allow',
22-
allowedTracingUrls: ["https://tenantfirstaid.com",],
12+
window.DD_RUM &&
13+
window.DD_RUM.init({
14+
clientToken: "pub14aa0f102cb53f847ac602ce8c2e14b2",
15+
applicationId: "51dade6d-207e-4a25-b659-fbbbe95a48b6",
16+
site: "us5.datadoghq.com",
17+
service: "tenant-first-aid",
18+
env: "prod",
19+
version: "1.0.0",
20+
sessionSampleRate: 100,
21+
sessionReplaySampleRate: 100,
22+
defaultPrivacyLevel: "allow",
23+
allowedTracingUrls: ["https://tenantfirstaid.com"],
2324
});
2425
</script>
25-
</head>
26-
<body>
27-
<div id="root"></div>
28-
<script type="module" src="/src/main.tsx"></script>
29-
</body>
30-
</html>
26+
</head>
27+
<body>
28+
<div id="root"></div>
29+
<script type="module" src="/src/main.tsx"></script>
30+
</body>
31+
</html>

frontend/package-lock.json

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"dev": "vite",
88
"build": "tsc -b && vite build",
99
"lint": "eslint .",
10+
"format": "prettier --write .",
1011
"preview": "vite preview"
1112
},
1213
"dependencies": {
@@ -23,9 +24,11 @@
2324
"@types/react-dom": "^19.0.4",
2425
"@vitejs/plugin-react": "^4.3.4",
2526
"eslint": "^9.22.0",
27+
"eslint-config-prettier": "^10.1.5",
2628
"eslint-plugin-react-hooks": "^5.2.0",
2729
"eslint-plugin-react-refresh": "^0.4.19",
2830
"globals": "^16.0.0",
31+
"prettier": "^3.5.3",
2932
"typescript": "~5.7.2",
3033
"typescript-eslint": "^8.26.1",
3134
"vite": "^6.3.1"

frontend/src/contexts/SessionContext.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,20 @@ export default function SessionContextProvider({ children }: Props) {
1616
const handleNewSession = async () => {
1717
// Clear the session by making a request to clear server-side session
1818
try {
19-
await fetch('/api/clear-session', {
20-
method: 'POST',
21-
credentials: 'include'
19+
await fetch("/api/clear-session", {
20+
method: "POST",
21+
credentials: "include",
2222
});
2323
// Refresh the page to start fresh
2424
window.location.reload();
2525
} catch (error) {
26-
console.error('Failed to clear session:', error);
26+
console.error("Failed to clear session:", error);
2727
// Fallback: just refresh the page
2828
window.location.reload();
2929
}
3030
};
3131

32-
const sessionContextObject = useMemo(
33-
() => ({ handleNewSession }),
34-
[]
35-
);
32+
const sessionContextObject = useMemo(() => ({ handleNewSession }), []);
3633

3734
return (
3835
<SessionContext.Provider value={sessionContextObject}>

frontend/src/hooks/useMessages.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export interface IMessage {
99

1010
async function fetchChatHistory() {
1111
try {
12-
const response = await fetch('/api/history', {
13-
credentials: 'include'
12+
const response = await fetch("/api/history", {
13+
credentials: "include",
1414
});
1515
let history: IMessage[] = await response.json();
1616
let messageId = Date.now();
@@ -29,7 +29,7 @@ async function addNewMessage(userMessage: string) {
2929
const response = await fetch("/api/query", {
3030
method: "POST",
3131
headers: { "Content-Type": "application/json" },
32-
credentials: 'include',
32+
credentials: "include",
3333
body: JSON.stringify({ message: userMessage }),
3434
});
3535
return response.body?.getReader();
@@ -43,8 +43,7 @@ export default function useMessages() {
4343
});
4444

4545
const addMessage = useMutation({
46-
mutationFn: async (userMessage: string) =>
47-
await addNewMessage(userMessage),
46+
mutationFn: async (userMessage: string) => await addNewMessage(userMessage),
4847
});
4948

5049
useEffect(() => {

frontend/src/hooks/useSession.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default function useSession() {
55
const context = use(SessionContext);
66
if (context === null) {
77
throw new Error(
8-
"useSession can only be used within SessionContextProvider"
8+
"useSession can only be used within SessionContextProvider",
99
);
1010
}
1111
return context;

frontend/src/main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ ReactDOM.createRoot(document.getElementById("root")!).render(
1111
<QueryClientProvider client={queryClient}>
1212
<App />
1313
</QueryClientProvider>
14-
</React.StrictMode>
14+
</React.StrictMode>,
1515
);

frontend/src/pages/Chat/components/InputField.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ export default function InputField({
5858
// Update only the bot's message
5959
setMessages((prev) =>
6060
prev.map((msg) =>
61-
msg.messageId === botMessageId ? { ...msg, content: fullText } : msg
62-
)
61+
msg.messageId === botMessageId
62+
? { ...msg, content: fullText }
63+
: msg,
64+
),
6365
);
6466
}
6567
} catch (error) {
@@ -71,8 +73,8 @@ export default function InputField({
7173
...msg,
7274
content: "Sorry, I encountered an error. Please try again.",
7375
}
74-
: msg
75-
)
76+
: msg,
77+
),
7678
);
7779
} finally {
7880
setIsLoading(false);

0 commit comments

Comments
 (0)