Skip to content

Commit b711753

Browse files
committed
fix: prettier
1 parent 2c7e3d8 commit b711753

File tree

7 files changed

+109
-106
lines changed

7 files changed

+109
-106
lines changed

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@
3333
"typescript-eslint": "^8.26.1",
3434
"vite": "^6.3.1"
3535
}
36-
}
36+
}

frontend/src/hooks/useMessages.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,14 @@ export default function useMessages() {
5757
});
5858

5959
const initChat = useMutation({
60-
mutationFn: async ({ city, state }: { city: string | null; state: string }) =>
61-
await initNewChat(city, state),
62-
})
60+
mutationFn: async ({
61+
city,
62+
state,
63+
}: {
64+
city: string | null;
65+
state: string;
66+
}) => await initNewChat(city, state),
67+
});
6368

6469
useEffect(() => {
6570
if (data && data.length !== 0) {

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

Lines changed: 76 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -2,88 +2,89 @@ import { useState } from "react";
22
import useMessages, { IMessage } from "../../../hooks/useMessages";
33

44
const CitySelectOptions = {
5-
"portland": {
6-
city: "portland",
7-
state: "or",
8-
label: "Portland"
9-
},
10-
"eugene": {
11-
city: "eugene",
12-
state: "or",
13-
label: "Eugene"
14-
},
15-
"oregon": {
16-
city: null,
17-
state: "or",
18-
label: "Other city in Oregon"
19-
},
20-
"other": {
21-
city: null,
22-
state: null,
23-
label: "City in another state"
24-
}
5+
portland: {
6+
city: "portland",
7+
state: "or",
8+
label: "Portland",
9+
},
10+
eugene: {
11+
city: "eugene",
12+
state: "or",
13+
label: "Eugene",
14+
},
15+
oregon: {
16+
city: null,
17+
state: "or",
18+
label: "Other city in Oregon",
19+
},
20+
other: {
21+
city: null,
22+
state: null,
23+
label: "City in another state",
24+
},
2525
};
2626

2727
interface Props {
28-
setMessages: React.Dispatch<React.SetStateAction<IMessage[]>>;
28+
setMessages: React.Dispatch<React.SetStateAction<IMessage[]>>;
2929
}
3030

3131
export default function CitySelectField({ setMessages }: Props) {
32-
const [city, setCity] = useState<string | null>(null);
33-
const [invalidCity, setInvalidCity] = useState<boolean>(false);
34-
const { initChat } = useMessages();
32+
const [city, setCity] = useState<string | null>(null);
33+
const [invalidCity, setInvalidCity] = useState<boolean>(false);
34+
const { initChat } = useMessages();
3535

36-
const handleCityChange = async (key: string | null) => {
37-
setCity(key);
38-
const selectedCity = CitySelectOptions[key as keyof typeof CitySelectOptions];
39-
if (selectedCity && selectedCity.state) {
40-
setInvalidCity(false);
36+
const handleCityChange = async (key: string | null) => {
37+
setCity(key);
38+
const selectedCity =
39+
CitySelectOptions[key as keyof typeof CitySelectOptions];
40+
if (selectedCity && selectedCity.state) {
41+
setInvalidCity(false);
4142

42-
try {
43-
await initChat({ city: selectedCity.city, state: selectedCity.state });
43+
try {
44+
await initChat({ city: selectedCity.city, state: selectedCity.state });
4445

45-
// Initial bot message that's not included in history
46-
const botMessageId = (Date.now() + 1).toString();
47-
setMessages((prev) => [
48-
...prev,
49-
{
50-
role: "assistant",
51-
content: "Ask me anything about Oregon tenant rights and assistance.",
52-
messageId: botMessageId,
53-
},
54-
]);
55-
} catch (error) {
56-
console.error("Error initializing session:", error);
57-
setInvalidCity(true);
58-
}
59-
} else {
60-
setInvalidCity(true);
61-
}
62-
};
46+
// Initial bot message that's not included in history
47+
const botMessageId = (Date.now() + 1).toString();
48+
setMessages((prev) => [
49+
...prev,
50+
{
51+
role: "assistant",
52+
content:
53+
"Ask me anything about Oregon tenant rights and assistance.",
54+
messageId: botMessageId,
55+
},
56+
]);
57+
} catch (error) {
58+
console.error("Error initializing session:", error);
59+
setInvalidCity(true);
60+
}
61+
} else {
62+
setInvalidCity(true);
63+
}
64+
};
6365

64-
return (
65-
<div className="flex flex-col gap-2">
66-
<p className="text-center text-[#888] mb-10">
67-
{invalidCity ?
68-
"Unfortunately we can only answer questions about tenant rights in Oregon right now." :
69-
"Welcome to Tenant First Aid! I can answer your questions about tenant rights in Oregon. To get started, what city are you located in?"
70-
}
71-
</p>
72-
<select
73-
name="city"
74-
value={city || ""}
75-
onChange={e => handleCityChange(e.target.value)}
76-
className="p-3 border-1 border-[#ddd] rounded-md box-border transition-colors duration-300 focus:outline-0 focus:border-[#4a90e2] focus:shadow-[0_0_0_2px_rgba(74,144,226,0.2)]"
77-
>
78-
<option value="" disabled>
79-
Select a city
80-
</option>
81-
{Object.entries(CitySelectOptions).map(([key, option]) => (
82-
<option key={key} value={key}>
83-
{option.label}
84-
</option>
85-
))}
86-
</select>
87-
</div>
88-
);
89-
}
66+
return (
67+
<div className="flex flex-col gap-2">
68+
<p className="text-center text-[#888] mb-10">
69+
{invalidCity
70+
? "Unfortunately we can only answer questions about tenant rights in Oregon right now."
71+
: "Welcome to Tenant First Aid! I can answer your questions about tenant rights in Oregon. To get started, what city are you located in?"}
72+
</p>
73+
<select
74+
name="city"
75+
value={city || ""}
76+
onChange={(e) => handleCityChange(e.target.value)}
77+
className="p-3 border-1 border-[#ddd] rounded-md box-border transition-colors duration-300 focus:outline-0 focus:border-[#4a90e2] focus:shadow-[0_0_0_2px_rgba(74,144,226,0.2)]"
78+
>
79+
<option value="" disabled>
80+
Select a city
81+
</option>
82+
{Object.entries(CitySelectOptions).map(([key, option]) => (
83+
<option key={key} value={key}>
84+
{option.label}
85+
</option>
86+
))}
87+
</select>
88+
</div>
89+
);
90+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ export default function InputField({
7070
prev.map((msg) =>
7171
msg.messageId === botMessageId
7272
? {
73-
...msg,
74-
content: "Sorry, I encountered an error. Please try again.",
75-
}
73+
...msg,
74+
content: "Sorry, I encountered an error. Please try again.",
75+
}
7676
: msg,
7777
),
7878
);

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { IMessage } from "../../../hooks/useMessages";
22

3-
43
/* This was commented out because with new laws added (e.g. ORS Ch. 105)
54
* and different municipal codes (e.g. Portland's code),
65
* citation hightlighting was becoming too complex. We should revisit this
@@ -53,17 +52,17 @@ interface Props {
5352
onStatuteClick: (statute: string) => void;
5453
}
5554

56-
export default function MessageContent({
57-
message,
58-
isLoading,
59-
}: Props) {
55+
export default function MessageContent({ message, isLoading }: Props) {
6056
return (
6157
<>
6258
<strong>{message.role === "assistant" ? "Bot: " : "You: "}</strong>
6359
{message.role === "assistant" && message.content === "" && isLoading ? (
6460
<span className="animate-dot-pulse">...</span>
6561
) : (
66-
<span className="whitespace-pre-wrap" dangerouslySetInnerHTML={{ __html: message.content }}></span>
62+
<span
63+
className="whitespace-pre-wrap"
64+
dangerouslySetInnerHTML={{ __html: message.content }}
65+
></span>
6766
)}
6867
</>
6968
);

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,28 @@ export default function MessageWindow({
5353
</div>
5454
) : (
5555
<div
56-
className={`max-h-[calc(100dvh-240px)] sm:max-h-[calc(100dvh-20rem)] mx-auto max-w-[700px] ${isOngoing ? "overflow-y-scroll" : "overflow-y-none"
57-
}`}
56+
className={`max-h-[calc(100dvh-240px)] sm:max-h-[calc(100dvh-20rem)] mx-auto max-w-[700px] ${
57+
isOngoing ? "overflow-y-scroll" : "overflow-y-none"
58+
}`}
5859
ref={messagesRef}
5960
>
6061
{isOngoing ? (
6162
<div className="flex flex-col gap-4">
6263
{messages.map((message) => (
6364
<div
64-
className={`flex w-full ${message.role === "assistant"
65-
? "justify-start"
66-
: "justify-end"
67-
}`}
65+
className={`flex w-full ${
66+
message.role === "assistant"
67+
? "justify-start"
68+
: "justify-end"
69+
}`}
6870
key={message.messageId}
6971
>
7072
<div
71-
className={`message-bubble p-3 rounded-2xl max-w-[95%] ${message.role === "assistant"
72-
? "bg-slate-200 rounded-tl-sm"
73-
: "bg-[#1F584F] text-white rounded-tr-sm"
74-
}`}
73+
className={`message-bubble p-3 rounded-2xl max-w-[95%] ${
74+
message.role === "assistant"
75+
? "bg-slate-200 rounded-tl-sm"
76+
: "bg-[#1F584F] text-white rounded-tr-sm"
77+
}`}
7578
>
7679
<MessageContent
7780
message={message}
@@ -101,21 +104,16 @@ export default function MessageWindow({
101104
onClick={handleClearSession}
102105
title="Clear Chat"
103106
>
104-
105107
Clear Chat
106108
</button>
107109
<div className="">
108-
<ExportMessagesButton
109-
messages={messages}
110-
111-
/>
110+
<ExportMessagesButton messages={messages} />
112111
</div>
113112
</div>
114113
</>
115114
) : (
116115
<CitySelectField setMessages={setMessages} />
117116
)}
118-
119117
</div>
120118
</>
121119
);

frontend/src/style.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ body {
3737
}
3838

3939
.message-bubble a {
40-
@apply inline text-blue-600 underline cursor-pointer transition-colors hover:bg-blue-200 rounded
41-
}
40+
@apply inline text-blue-600 underline cursor-pointer transition-colors hover:bg-blue-200 rounded;
41+
}

0 commit comments

Comments
 (0)