Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function App() {
<ErrorBoundary fallback={<ErrorBoundaryFallback />}>
<BrowserRouter>
<div className="App">
<Banner />
{/* <Banner /> */}
{/* <div className="AdBanner">
CMUEats is now up to date with the official dining website! Sorry for the inconvenience.
&gt;_&lt;
Expand Down
14 changes: 11 additions & 3 deletions src/assets/select.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 28 additions & 2 deletions src/components/SelectLocation.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
.filter-container {
display: flex;
align-items: center;
gap: 0.5rem;
}

.filter-label {
color: var(--text-primary);
font-family: var(--text-primary-font);
font-weight: 500;
font-size: 1rem;
white-space: nowrap;
}

@media screen and (min-width: 900px) {
.filter-label {
font-size: 1.2rem;
}
}

.select {
appearance: none;
cursor: pointer;
display: block;
min-width: 500px;
min-width: 220px;
width: fit-content;

padding: 0.8rem 0.9rem;
border-radius: 1rem;
background: var(--input-bg) url(../assets/select.svg) no-repeat calc(100% - 10px) 50%;
background: var(--input-bg) url(../assets/select.svg) no-repeat calc(100% - 5px) 50%;
outline: none;
border: 1px solid transparent;
box-shadow: 0 0 0 2px rgba(255, 255, 255, 0);
Expand All @@ -23,6 +43,12 @@
opacity: 0;
}

@media screen and (min-width: 900px) {
.select {
min-width: 300px;
}
}

.select:hover {
transition: all 0.5s;
box-shadow: 0 0 40px var(--hover-accent-color);
Expand Down
29 changes: 17 additions & 12 deletions src/components/SelectLocation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ function getPrimaryLocation(locationString: string) {
function SelectLocation({ setLocationFilterQuery, locations }: SelectLocationProps) {
if (locations === undefined) {
return (
<select className="select">
{/* Keep label the same as the default option below to reduce loading jank */}
<option value="" label="Filter by Building" />
</select>
<div className="filter-container">
<span className="filter-label">Filter by building:</span>
<select className="select">
<option value="">None</option>
</select>
</div>
);
}

Expand All @@ -27,14 +29,17 @@ function SelectLocation({ setLocationFilterQuery, locations }: SelectLocationPro
const dedeupedLocationStrings = [...new Set(locationStrings)];

return (
<select onChange={(e) => setLocationFilterQuery(e.target.value)} className="select">
<option value="" key="Filter by Building" label="Filter by Building" />
{dedeupedLocationStrings.map((location) => (
<option key={location} value={location}>
{location}
</option>
))}
</select>
<div className="filter-container">
<span className="filter-label">Filter by building:</span>
<select onChange={(e) => setLocationFilterQuery(e.target.value)} className="select">
<option value="">None</option>
{dedeupedLocationStrings.map((location) => (
<option key={location} value={location}>
{location}
</option>
))}
</select>
</div>
);
}

Expand Down
34 changes: 34 additions & 0 deletions src/components/SortBy.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.sort-container {
display: flex;
align-items: center;
gap: 0.5rem;
}

.sort-label {
color: var(--text-primary);
font-family: var(--text-primary-font);
font-weight: 500;
font-size: 1rem;
white-space: nowrap;
}

@media screen and (min-width: 900px) {
.sort-label {
font-size: 1.2rem;
}
}

.sort-select {
width: 180px;
min-width: 0;
}

.Locations-header__filters .select:not(.sort-select) {
width: 220px;
}

@media screen and (min-width: 900px) {
.Locations-header__filters .select:not(.sort-select) {
width: 440px;
}
}
119 changes: 119 additions & 0 deletions src/components/SortBy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { useEffect } from 'react';
import './SortBy.css';
import { getUserToDestinationPath } from '../util/cmuMapsApi';
import { IReadOnlyLocation_FromAPI_PostProcessed } from '../types/locationTypes';

interface SortByProps {
setSortBy: (sortBy: string) => void;
sortBy: string;
locations?: IReadOnlyLocation_FromAPI_PostProcessed[];
onLocationDistancesCalculated?: (distances: Map<number, number>) => void;
}

function SortBy({ setSortBy, sortBy, locations, onLocationDistancesCalculated }: SortByProps) {
useEffect(() => {
if (sortBy === 'location' && locations && onLocationDistancesCalculated) {
if ('geolocation' in navigator) {
navigator.geolocation.getCurrentPosition(
async (position) => {
const { latitude, longitude } = position.coords;
const distances = new Map<number, number>();

const stackUnderground = locations.find((loc) => loc.name === "Stack'd Underground");
const exchange = locations.find((loc) => loc.name === 'The Exchange');
const tasteOfIndia = locations.find((loc) => loc.name === 'Taste Of India');
const tepperTaqueria = locations.find((loc) => loc.name === 'Tepper Taqueria');
const tahini = locations.find((loc) => loc.name === 'Tahini');

const modifiedLocations = locations.map((location) => {
if (location.name === "Stack'd Dessert Bar" && stackUnderground?.coordinates) {
return {
...location,
coordinates: stackUnderground.coordinates,
};
}
if (location.name === 'Zebra Lounge' && exchange?.coordinates) {
return {
...location,
coordinates: exchange.coordinates,
};
}
if (location.name === 'Sweet Plantain' && tasteOfIndia?.coordinates) {
return {
...location,
coordinates: tasteOfIndia.coordinates,
};
}
if (location.name === "De Fer Coffee & Tea At Resnik" && tasteOfIndia?.coordinates) {
return {
...location,
coordinates: tasteOfIndia.coordinates,
};
}
if (location.name === 'E.a.t. (evenings At Tepper) - Rohr Commons' && tepperTaqueria?.coordinates) {
return {
...location,
coordinates: tepperTaqueria.coordinates,
};
}
Comment on lines +29 to +58
Copy link
Collaborator

Choose a reason for hiding this comment

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

are these coordinate overwrites here because cmumaps can't accept the non-ovewritten coordinates?

if (location.name === 'Fire And Stone' && tahini?.coordinates) {
return {
...location,
coordinates: tahini.coordinates,
};
}
return location;
});

const pathPromises = modifiedLocations
.filter((location) => location.coordinates)
.map(async (location) => {
try {
const pathData = await getUserToDestinationPath(
latitude,
longitude,
location.coordinates!.lat,
location.coordinates!.lng,
);

if (pathData) {
return {
conceptId: location.conceptId,
distance: pathData.Fastest.path.distance,
};
}
return null;
} catch (error) {
return null;
}
});

const pathResults = await Promise.all(pathPromises);
pathResults.forEach((result) => {
if (result) {
distances.set(result.conceptId, result.distance);
}
});

onLocationDistancesCalculated(distances);
},
() => {
// Silently handle geolocation errors
},
);
}
}
}, [sortBy, locations, onLocationDistancesCalculated]);

return (
<div className="sort-container">
<span className="sort-label">Sort by:</span>
<select onChange={(e) => setSortBy(e.target.value)} value={sortBy} className="select sort-select">
<option value="closing-time">Closing time</option>
<option value="location">Location</option>
</select>
</div>
);
}

export default SortBy;
37 changes: 37 additions & 0 deletions src/pages/EateryCardGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export default function EateryCardGrid({
apiError,
pinnedIds,
updatePinnedIds,
sortBy,
locationDistances,
}: {
locations: IReadOnlyLocation_FromAPI_PostProcessed[] | undefined;
extraLocationData: IReadOnlyLocation_ExtraData_Map | undefined;
Expand All @@ -26,6 +28,8 @@ export default function EateryCardGrid({
apiError: boolean;
pinnedIds: Record<string, true>;
updatePinnedIds: (newPinnedIds: Record<string, true>) => void;
sortBy: string;
locationDistances: Map<number, number>;
}) {
if (locations === undefined || extraLocationData === undefined) {
// Display skeleton cards while loading
Expand Down Expand Up @@ -59,6 +63,39 @@ export default function EateryCardGrid({
if (locations.length === 0) return <NoResultsError onClear={() => setSearchQuery('')} />;

const compareLocations = (location1: IReadOnlyLocation_Combined, location2: IReadOnlyLocation_Combined) => {
if (sortBy === 'location') {
const state1 = location1.locationState;
const state2 = location2.locationState;

const getPriority = (state: LocationState) => {
if (state === LocationState.OPEN
|| state === LocationState.CLOSES_SOON) return 0;
if (state === LocationState.OPENS_SOON) return 1;
if (state === LocationState.CLOSED
|| state === LocationState.CLOSED_LONG_TERM) return 2;
return 3;
};
Comment on lines +70 to +77
Copy link
Collaborator

Choose a reason for hiding this comment

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

good - although this feels inverted since higher priority elements are sorted last lmao


const priority1 = getPriority(state1);
const priority2 = getPriority(state2);

if (priority1 !== priority2) {
return priority1 - priority2;
}

const distance1 = locationDistances.get(location1.conceptId);
const distance2 = locationDistances.get(location2.conceptId);

if (distance1 !== undefined && distance2 !== undefined) {
return distance1 - distance2;
}

if (distance1 !== undefined) return -1;
if (distance2 !== undefined) return 1;

return location1.name.localeCompare(location2.name);
}

const state1 = location1.locationState;
const state2 = location2.locationState;

Expand Down
Loading