Skip to content

Commit 8bab7ec

Browse files
Merge master into dev (#847)
* 824 unable to select time all rooms page (#827) * changed value to defaultValue to fix bug with not being able to select time on all rooms page * added unit test * removed comment * fixed linting errors * fix: Compare location by id then long rather than just long (#844) * fix: Compare location by id then long rather than just long * fix: linting issues --------- Co-authored-by: Joshua Pozzolungo <jpozzolungo2@gmail.com>
1 parent 0281da0 commit 8bab7ec

1 file changed

Lines changed: 47 additions & 2 deletions

File tree

frontend/views/CardList.tsx

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,51 @@ const FlipMoveGrid = styled(FlipMove)(({ theme }) => ({
2020
gridGap: "20px",
2121
}));
2222

23+
const getBuildingPosition = (building: Building): number | null => {
24+
const match = building.id.match(/(\d+)$/);
25+
26+
if (!match) {
27+
return null;
28+
}
29+
30+
return Number(match[1]);
31+
};
32+
33+
const compareBuildingPosition = (
34+
a: Building,
35+
b: Building,
36+
direction: "lowerToUpper" | "upperToLower"
37+
): number => {
38+
const aPosition = getBuildingPosition(a);
39+
const bPosition = getBuildingPosition(b);
40+
41+
if (aPosition == null && bPosition == null) {
42+
return a.name.localeCompare(b.name);
43+
}
44+
45+
if (aPosition == null) {
46+
return 1;
47+
}
48+
49+
if (bPosition == null) {
50+
return -1;
51+
}
52+
53+
const positionDiff = aPosition - bPosition;
54+
55+
if (positionDiff !== 0) {
56+
return direction === "lowerToUpper" ? positionDiff : -positionDiff;
57+
}
58+
59+
const longDiff = a.long - b.long;
60+
61+
if (longDiff !== 0) {
62+
return direction === "lowerToUpper" ? longDiff : -longDiff;
63+
}
64+
65+
return a.name.localeCompare(b.name);
66+
};
67+
2368
const FlippableCard = React.forwardRef<HTMLDivElement, { buildingId: string }>(
2469
({ buildingId }, ref) => {
2570
const displayMobile = useMediaQuery(useTheme().breakpoints.down("sm"));
@@ -59,9 +104,9 @@ const CardList: React.FC<{
59104
.sort((a, b) => {
60105
switch (sort) {
61106
case "lowerToUpper":
62-
return a.long - b.long;
107+
return compareBuildingPosition(a, b, "lowerToUpper");
63108
case "upperToLower":
64-
return b.long - a.long;
109+
return compareBuildingPosition(a, b, "upperToLower");
65110
case "nearest":
66111
return userLat && userLng
67112
? calculateDistance(userLat, userLng, a.lat, a.long) -

0 commit comments

Comments
 (0)