Skip to content
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

Location Filter Styling #561

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Location Filter Styling #561

wants to merge 8 commits into from

Conversation

cnk2024
Copy link
Contributor

@cnk2024 cnk2024 commented Feb 23, 2025

Description

Made SelectLocation.tsx more readable, better styling

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • bun test
  • loaded locally, no new errors

Test Configuration:

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

- Separate component with css called in ListPage.tsx
- Hijacks the current search feature (not its own filter)
- Possibly to do: make it work with other incoming filters
- Fragment still needed for some reason in SelectLocation.tsx
Copy link

vercel bot commented Feb 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
cmueats ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 23, 2025 0:26am

Copy link
Collaborator

@cirex-web cirex-web left a comment

Choose a reason for hiding this comment

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

Variable names are better! See comments

@@ -3,43 +3,46 @@ import { IReadOnlyLocation_FromAPI_PostProcessed } from '../types/locationTypes'
import './SelectLocation.css';

type SelectLocationProps = {
SSQ: (value: React.SetStateAction<string>) => void;
l: IReadOnlyLocation_FromAPI_PostProcessed[] | undefined;
setSearchQuery: (value: React.SetStateAction<string>) => void;
Copy link
Collaborator

Choose a reason for hiding this comment

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

React.SetStateAction<string> is a good way of typing this! (I would've done (value:string)=>void but that doesn't fully cover the type)

We can actually replace (value: React.SetStateAction<string>) => void; with React.Dispatch<React.SetStateAction<string>> to be even more semantically correct.

function SelectLocation({ SSQ, l }: SelectLocationProps) {
if (l === undefined) {
function SelectLocation({ setSearchQuery, locations }: SelectLocationProps) {
if (locations === undefined) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

good use of strict equality === checking!

Comment on lines +19 to 24
let locationStrings = locations.map((locationObj) => locationObj.location);
locationStrings = locationStrings.map((locationObj) =>
locationObj.indexOf(',') === -1
? locationObj
: locationObj.slice(0, locationObj.indexOf(',')),
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like extracting the

			? locationObj
			: locationObj.slice(0, locationObj.indexOf(','))

into its own outer function with a signature like getPrimaryLocation(locationString:string)=>string and writing const locationStrings = locations.map((locationObj) => getPrimaryLocation(locationObj.location)); would be more clear for future maintenence.


locationStrings = Array.from(new Set(locationStrings));
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about [...new Set(locationStrings)];? And how about making it more clear what we're doing here by calling this new variable const dedeupedLocationStrings = [...new Set(locationStrings)];`?

And I do agree it might be a bit jank to convert to a set and then back into a list. If you think the other methods outlined here are cleaner, go for it!

// The whole thing breaks if this useless, extraneous piece is deleted.
// i don't know why.
return <>🥥</>;
return <>BUG: breaks if removed</>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I found the issue! It's a bug with million.vite in vite.config.ts, not with this code. I recommend deleting that and uninstalling million (it's supposed to make react apps more performant, but cmueats is relatively lightweight.) @GhostOf0days let me know if you disagree.

Copy link
Member

Choose a reason for hiding this comment

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

I do like Million, but yeah, we shouldn't need it for CMUEats. Removing is fine.

@GhostOf0days
Copy link
Member

GhostOf0days commented Feb 23, 2025

@cirex-web Wanted your opinion on this, but I do think the UI looks out of place compared to the rest of the UI. Should also change CSS for that.

Screenshot 2025-02-23 at 2 08 22 AM

@GhostOf0days
Copy link
Member

Update: It looks fine on mobile but off on my MacBook.

@cirex-web
Copy link
Collaborator

What browser are you on?

@GhostOf0days
Copy link
Member

Safari

@GhostOf0days
Copy link
Member

Will need to do more to add back the dropdwon arrow, but looking into it, it's because Apple forces their version for the select button. To force custom version, add the following (but this leads to dropwdown arrow disappearing, so need to fix that as well maybe with background image, etc. Good resource: https://stackoverflow.com/questions/14218307/select-arrow-style-change):

-webkit-appearance: none;
-moz-appearance: none;
appearance: none;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants