Skip to content

Commit

Permalink
Fix ETA null, Add Route Operator and Service Type Info, Reduce Duplic…
Browse files Browse the repository at this point in the history
…ate Route No (#202)

* - Fix Handle ETA may be null (@hk-bus-eta/pull/3)

* - Add Route Company and Service Type Info (if any) in both Stop Dialog and Home Screen (Favourites/Nearby Routes)

* - Reduce duplicate route no (hide special routes with higher service type value)
  • Loading branch information
chengkeith authored Sep 13, 2024
1 parent 7600417 commit fece3fa
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
33 changes: 28 additions & 5 deletions src/components/home/SuccinctTimeReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const SuccinctTimeReport = ({
} = useContext(DbContext);
const [routeNo] = routeId.split("-");
const [routeKey, seq] = routeId.split("/");
const { co, stops, dest, fares, faresHoliday, route } =
const { co, stops, dest, fares, faresHoliday, route, serviceType } =
routeList[routeKey] || DEFAULT_ROUTE;
const stopId = getStops(co, stops)[parseInt(seq, 10)];
const stop = stopList[stopId] || DEFAULT_STOP;
Expand Down Expand Up @@ -151,10 +151,22 @@ const SuccinctTimeReport = ({
<ListItem onClick={handleClick} sx={rootSx}>
<ListItemText
primary={
<RouteNo
routeNo={language === "zh" ? t(routeNo) : routeNo}
fontSize={co[0] === "mtr" ? "1.1rem" : undefined}
/>
<Box overflow="hidden">
<RouteNo
routeNo={language === "zh" ? t(routeNo) : routeNo}
fontSize={co[0] === "mtr" ? "1.1rem" : undefined}
/>
{parseInt(serviceType, 10) >= 2 && (
<Typography variant="caption" sx={specialTripSx}>
{t("特別班")}
</Typography>
)}
</Box>
}
secondary={
<Typography component="h4" variant="caption" sx={companySx}>
{co.map((co) => t(co)).join("+")}
</Typography>
}
/>
<ListItemText
Expand Down Expand Up @@ -269,3 +281,14 @@ const iconContainerSx: SxProps<Theme> = {
alignItems: "center",
justifyContent: "center",
};

const companySx: SxProps<Theme> = {
color: (theme) => theme.palette.text.secondary,
textOverflow: "ellipsis",
};

const specialTripSx: SxProps<Theme> = {
color: (theme) => theme.palette.text.secondary,
fontSize: "0.6rem",
marginLeft: "8px",
};
10 changes: 7 additions & 3 deletions src/components/home/lists/NearbyRouteList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ const getRoutes = ({
serviceDayMap: EtaDb["serviceDayMap"];
searchRange: number;
}): Partial<Record<TransportType, string>> => {
const addedList = [] as [string, Company, string][];
const nearbyRoutes = Object.entries(stopList)
.map((stop: [string, StopListEntry]): [string, StopListEntry, number] =>
// potentially could be optimized by other distance function
Expand All @@ -149,9 +150,12 @@ const getRoutes = ({
).forEach((co) => {
if (route.stops[co] && route.stops[co].includes(stopId)) {
if (acc[coToType[co]] === undefined) acc[coToType[co]] = [];
acc[coToType[co]].push(
key + "/" + route.stops[co].indexOf(stopId)
);
if(addedList.find(([_route, _co, _serviceType]) => _route == route.route && _co == co && _serviceType < route.serviceType) === undefined) {
acc[coToType[co]].push(
key + "/" + route.stops[co].indexOf(stopId)
);
addedList.push([route.route, co, route.serviceType]);
}
}
});
});
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/useStopEtas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ export const useStopEtas = ({
)
// sort to display the earliest arrival transport first
.sort(([keyA, a], [keyB, b]) => {
a = a.filter((e) => e.eta);
b = b.filter((e) => e.eta);
if (a.length === 0 && b.length === 0) return keyA < keyB ? -1 : 1;
if (a.length === 0) return 1;
if (b.length === 0) return -1;
if (isLightRail) {
Expand Down

0 comments on commit fece3fa

Please sign in to comment.