Skip to content

Commit

Permalink
Feat: add footer countdown to pickup/dropoff stops (#26)
Browse files Browse the repository at this point in the history
* move LiveText to components

* feat: add arriving in live countdown as suggested by reddit user ParaMike46

* bump version to 0.7.11
  • Loading branch information
david-abell authored Apr 11, 2024
1 parent e9566bb commit 80fefcd
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "irish-buses",
"version": "0.7.10",
"version": "0.7.11",
"type": "module",
"scripts": {
"dev": "next dev",
Expand Down
56 changes: 37 additions & 19 deletions src/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
formatReadableDelay,
getDelayStatus,
getDelayedTime,
getDifferenceInSeconds,
isPastArrivalTime,
} from "@/lib/timeHelpers";
import { TripUpdate } from "@/types/realtime";
Expand Down Expand Up @@ -38,7 +39,7 @@ function Footer({
const [count, setCount] = useState<number>(0);
useInterval(() => {
setCount(count + 1);
}, 15000);
}, 1000);

const lastStopId = useMemo(() => {
if (!!destination) return "";
Expand Down Expand Up @@ -122,6 +123,14 @@ function Footer({
!!dropOffArrivalTime &&
isPastArrivalTime(realtimeDropOffArrivalTime ?? dropOffArrivalTime);

const liveTextArrivalTime = isPastPickup
? realtimeDropOffArrivalTime
: realtimePickupArrivalTime;

const liveTextContent = liveTextArrivalTime
? formatReadableDelay(getDifferenceInSeconds(liveTextArrivalTime), true)
: "";

return (
<div className="absolute bottom-0 z-[1000] mx-auto min-h-[6rem] w-full overflow-x-auto p-4 lg:max-w-7xl lg:px-10">
<div className="rounded-lg bg-background/90 p-4">
Expand All @@ -147,24 +156,33 @@ function Footer({
)}
</p>

<p
className={
dropOffDelayStatus === "early"
? "text-green-700 dark:text-green-500"
: dropOffDelayStatus === "late"
? "text-red-700 dark:text-red-500"
: ""
}
>
<span className="whitespace-nowrap">
{dropOffDelay ?? ""}
</span>{" "}
{isPastDropOff
? "Completed"
: isPastPickup
? dropOffDelayStatus
: pickupDelayStatus}
</p>
{!!trip && (
<p>
{isPastDropOff ? (
"Completed"
) : isPastPickup ? (
<span>
Dropping off {dropOffDelayStatus} in{" "}
{liveTextContent ?? ""}
</span>
) : (
<span>
Picking up {pickupDelayStatus} in{" "}
<span
className={`whitespace-nowrap ${
dropOffDelayStatus === "early"
? "text-green-700 dark:text-green-500"
: dropOffDelayStatus === "late"
? "text-red-700 dark:text-red-500"
: ""
}`}
>
{liveTextContent ?? ""}
</span>
</span>
)}
</p>
)}
</div>
}
</AccordionTrigger>
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/components/Map/Bus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useInterval } from "usehooks-ts";
import { Stop, StopTime } from "@prisma/client";
import { Position } from "@turf/helpers";
import { TripUpdate } from "@/types/realtime";
import LiveText, { LiveTextColor } from "../ui/LiveText";
import LiveText, { LiveTextColor } from "../LiveText";
import LiveVehicleTooltip from "./LiveVehicleTooltip";

type Props = {
Expand Down

0 comments on commit 80fefcd

Please sign in to comment.