Skip to content

fix: keep location selection text unchanged during loading #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion frontend/src/pages/Chat/components/CitySelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ interface Props {

export default function CitySelectField({ setMessages }: Props) {
const [city, setCity] = useState<string | null>(null);
const [isLoading, setIsLoading] = useState(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think I've got a fix.

Instead of calling another state, we can define selectedCity outside handleCityChange. Something like:

const selectedCity = city
    ? CitySelectOptions[city as keyof typeof CitySelectOptions]
    : null;

Which keeps selectedCity null until city changes from setCity.

We can keep Line 39, but change it to a different name like selected to avoid clashing with selectedCity.

We could then switch up the condition in Line 67 to selectedCity === null || selectedCity.state given we switch up the order of the ternary:

{selectedCity === null || selectedCity.state
      ? "Welcome to Tenant First Aid! I can answer your questions about tenant rights in Oregon. To get started, what city are you located in."
      : "Unfortunately we can only answer questions about tenant rights in Oregon right now."}
Screen.Recording.2025-06-19.at.10.43.13.PM.mov

This should patch things up.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good catch!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would #139 work? I gave it a test and it seems to. I'm not sure if I'm missing some nuance though.

const { initChat } = useMessages();

const handleCityChange = async (key: string | null) => {
setCity(key);
setIsLoading(true);
const selectedCity =
CitySelectOptions[key as keyof typeof CitySelectOptions];
if (selectedCity && selectedCity.state) {
Expand All @@ -53,14 +55,16 @@ export default function CitySelectField({ setMessages }: Props) {
]);
} catch (error) {
console.error("Error initializing session:", error);
} finally {
setIsLoading(false);
}
}
};

return (
<div className="flex flex-col gap-2">
<p className="text-center text-[#888] mb-10">
{city
{city && !isLoading
? "Unfortunately we can only answer questions about tenant rights in Oregon right now."
: "Welcome to Tenant First Aid! I can answer your questions about tenant rights in Oregon. To get started, what city are you located in?"}
</p>
Expand Down