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

fix(DailySchedule): improve identification of today's service #2274

Merged
merged 1 commit into from
Dec 16, 2024
Merged
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
8 changes: 3 additions & 5 deletions assets/ts/helpers/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const serviceStartDateComparator = (
const isInRemovedDates = (service: Service, currentDate: Date): boolean =>
service.removed_dates.includes(dateObjectToString(currentDate));

const isInAddedDates = (service: Service, currentDate: Date): boolean =>
export const isInAddedDates = (service: Service, currentDate: Date): boolean =>
service.added_dates.includes(dateObjectToString(currentDate));

const isOnValidDay = (service: Service, currentDate: Date): boolean => {
Expand All @@ -40,10 +40,7 @@ export const isInCurrentService = (
): boolean => {
const serviceStartDate = stringToDateObject(service.start_date);
const serviceEndDate = stringToDateObject(service.end_date);
return (
isInAddedDates(service, currentDate) ||
(currentDate >= serviceStartDate && currentDate <= serviceEndDate)
);
return currentDate >= serviceStartDate && currentDate <= serviceEndDate;
};

export const isInCurrentRating = (
Expand Down Expand Up @@ -155,6 +152,7 @@ export const groupServicesByDateRating = (
// additionally, prioritize current service/rating in grouping
if (!service.rating_end_date) {
if (
isInAddedDates(service, currentDate) ||
isInCurrentService(service, currentDate) ||
isInCurrentRating(service, currentDate)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import UpcomingDepartures from "./upcoming-departures/UpcomingDepartures";
import { isSubwayRoute } from "../../../models/route";
import DailyScheduleSubway from "./daily-schedule/DailyScheduleSubway";
import formattedDate, { stringToDateObject } from "../../../helpers/date";
import { isInCurrentService } from "../../../helpers/service";
import { isInAddedDates, isInCurrentService } from "../../../helpers/service";

interface Props {
handleChangeDirection: (direction: DirectionId) => void;
Expand Down Expand Up @@ -46,8 +46,10 @@ const ScheduleModalContent = ({
}: Props): ReactElement<HTMLElement> | null => {
const { id: routeId } = route;

const serviceToday = services.some(service =>
isInCurrentService(service, stringToDateObject(today))
const serviceToday = services.some(
service =>
isInCurrentService(service, stringToDateObject(today)) ||
isInAddedDates(service, stringToDateObject(today))
);

const renderUpcomingDepartures = (): ReactElement<HTMLElement> =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ export const DailySchedule = ({
const currentServices = sortedServices.filter(service =>
isCurrentValidService(service, todayDate)
);
const todayServiceId =
currentServices.length > 0 ? currentServices[0].id : "";
const [defaultSelectedService] = currentServices.length
? currentServices
: sortedServices;
const todayService =
currentServices.find(service => !!service["default_service?"]) ||
currentServices[0];
const todayServiceId = todayService?.id || "";
const defaultSelectedService = todayService || sortedServices[0];

const [selectedService, setSelectedService] = useState(
defaultSelectedService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { shortDate, stringToDateObject } from "../../../../helpers/date";
import {
ServiceGroupNames,
dedupeServices,
isInAddedDates,
isInCurrentService
} from "../../../../helpers/service";

Expand Down Expand Up @@ -57,7 +58,10 @@ const ServiceOptGroup = ({
if (service.id === todayServiceId) {
// if it's the only service this rating, this service might not
// technically be now - adjust text for that
if (isInCurrentService(service, nowDate)) {
if (
isInCurrentService(service, nowDate) ||
isInAddedDates(service, nowDate)
) {
optionText += " (now)";
} else {
optionText += ` (Starting ${format(startDate, "MMMM d, y")})`;
Expand Down
Loading