Skip to content

Commit 35aebf7

Browse files
kagiurazwliew
authored andcommitted
fix: 🐛 bug fixes (auto campus switch, term/holiday distinction)
1 parent 28f5887 commit 35aebf7

File tree

6 files changed

+98
-17
lines changed

6 files changed

+98
-17
lines changed

website/src/views/components/bus-map/ISBServices.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ $route-colors: (
112112
}
113113

114114
.subtext {
115+
font-size: 0.75rem;
115116
font-weight: 700;
116117
color: var(--gray);
117118
text-shadow: var(--map-bg) 1px 0px 0px, var(--map-bg) 0.540302px 0.841471px 0px,

website/src/views/components/bus-map/LocationMap.tsx

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FC, useState, useContext, useCallback, memo, useEffect } from 'react';
2-
import { LatLngBoundsExpression, Map } from 'leaflet';
2+
import { LatLngBoundsExpression, LatLngBoundsLiteral, LatLngExpression, Map } from 'leaflet';
33
import {
44
MapContainer,
55
Marker,
@@ -32,23 +32,23 @@ const ViewingBounds = {
3232
coordinates: [
3333
[1.2846, 103.7908],
3434
[1.3061, 103.7633],
35-
] as LatLngBoundsExpression,
35+
] as LatLngBoundsLiteral,
3636
minZoom: 15,
3737
centerpoint: [
3838
[1.2907, 103.7854],
3939
[1.3021, 103.7691],
40-
] as LatLngBoundsExpression,
40+
] as LatLngBoundsLiteral,
4141
},
4242
BTC: {
4343
coordinates: [
4444
[1.3249, 103.8122],
4545
[1.3164, 103.8226],
46-
] as LatLngBoundsExpression,
46+
] as LatLngBoundsLiteral,
4747
minZoom: 16.5,
4848
centerpoint: [
4949
[1.31874, 103.82009],
5050
[1.32358, 103.81405],
51-
] as LatLngBoundsExpression,
51+
] as LatLngBoundsLiteral,
5252
},
5353
};
5454

@@ -139,16 +139,25 @@ function MapFocusSetter({ focusStop }: { focusStop: string | null }) {
139139

140140
function MapBoundsSetter({ campus }: { campus: 'KRC' | 'BTC' }) {
141141
const map = useMap();
142-
const { coordinates, minZoom, centerpoint } = ViewingBounds[campus];
142+
const { coordinates, minZoom } = ViewingBounds[campus];
143143

144144
useEffect(() => {
145145
const duration = 500;
146-
map.flyToBounds(centerpoint, { duration: duration / 1000, maxZoom: 15, easeLinearity: 0.1 });
146+
// map.flyToBounds(centerpoint, { duration: duration / 1000, maxZoom: 15, easeLinearity: 0.1 });
147147
// wait until above is done
148-
setTimeout(() => {
149-
map.setMaxBounds(coordinates);
150-
map.setMinZoom(minZoom);
151-
}, duration);
148+
// setTimeout(() => {
149+
map.setMaxBounds(coordinates);
150+
map.setMinZoom(minZoom);
151+
// center map to centerpoint immediately, without animation
152+
const centerbounds = ViewingBounds[campus].centerpoint;
153+
const centerpoint: LatLngExpression = [
154+
(centerbounds[0][0] + centerbounds[1][0]) / 2,
155+
(centerbounds[0][1] + centerbounds[1][1]) / 2,
156+
];
157+
map.setView(centerpoint, minZoom, {
158+
animate: false,
159+
});
160+
// }, duration);
152161
}, [campus]);
153162
return null;
154163
}

website/src/views/mobility/MobilityContainer/MobilityContainer.tsx

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import useScrollToTop from 'views/hooks/useScrollToTop';
99
import LocationMap from 'views/components/bus-map/LocationMap';
1010
import NoFooter from 'views/layout/NoFooter';
1111
import { getRouteSegments, getServiceStatus } from 'utils/mobility';
12+
import NUSModerator from 'nusmoderator';
13+
import { setTime } from 'utils/timify';
1214
import styles from './MobilityContainer.scss';
1315
import ServiceDetails from '../ServiceDetails';
1416
import ServiceList from '../ServiceList';
@@ -28,6 +30,13 @@ const getPropsFromMatch = (match: Match<Params>) => ({
2830
slug: match.params.slug,
2931
});
3032

33+
const BTCStops = [
34+
// college green, oth bldg, and bg mrt
35+
'CG',
36+
'OTH',
37+
'BG-MRT',
38+
];
39+
3140
const MobilityContainer = () => {
3241
useScrollToTop();
3342

@@ -40,31 +49,55 @@ const MobilityContainer = () => {
4049
const [selectedService, setSelectedService] = useState<ISBService | null>(null);
4150

4251
const [serviceStatus, setServiceStatus] = useState<ServiceStatus[]>([]);
52+
53+
const acadWeekInfo = NUSModerator.academicCalendar.getAcadWeekInfo(new Date());
54+
const busPeriod =
55+
acadWeekInfo.sem === 'Semester 1' || acadWeekInfo.sem === 'Semester 2' ? 'term' : 'vacation';
4356
useEffect(() => {
44-
setServiceStatus(getServiceStatus());
57+
setServiceStatus(getServiceStatus(busPeriod));
4558
const interval = setInterval(() => {
46-
setServiceStatus(getServiceStatus());
59+
setServiceStatus(getServiceStatus(busPeriod));
4760
}, 1000 * 60 * 0.25);
4861
return () => clearInterval(interval);
4962
}, []);
5063

64+
const setFocusStopAndCampus = (stop: string) => {
65+
if (campus === 'KRC' && BTCStops.includes(stop)) {
66+
setCampus('BTC');
67+
} else if (campus === 'BTC' && !BTCStops.includes(stop)) {
68+
setCampus('KRC');
69+
}
70+
setTimeout(() => setFocusStop(stop), 100);
71+
// setFocusStop(stop);
72+
};
73+
5174
// window.scrollTo(0, 0); when type or slug changes
5275
useEffect(() => {
5376
window.scrollTo(0, 0);
5477
if (type === 'stop') {
55-
setFocusStop(slug);
78+
console.log('A');
79+
setFocusStopAndCampus(slug);
5680
} else if (type === 'service') {
5781
const service = isbServices.find((s) => s.id === slug);
5882
if (service) {
5983
setSelectedService(service);
60-
setFocusStop(service.stops[0]);
84+
setFocusStopAndCampus(service.stops[0]);
6185
}
6286
} else if (type === undefined) {
6387
setSelectedService(null);
6488
setFocusStop(null);
6589
}
6690
}, [type, slug]);
6791

92+
// // if focusStop is in different campus, switch campus
93+
// useEffect(() => {
94+
// if (focusStop && campus === 'KRC' && BTCStops.includes(focusStop)) {
95+
// setCampus('BTC');
96+
// } else if (focusStop && campus === 'BTC' && !BTCStops.includes(focusStop)) {
97+
// setCampus('KRC');
98+
// }
99+
// }, [focusStop, campus]);
100+
68101
return (
69102
<>
70103
<div className={styles.pageContainer}>

website/src/views/mobility/StopDetails.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
margin-top: -0.5rem;
88
}
99

10+
.stopDetails {
11+
h1 {
12+
margin-bottom: 0;
13+
}
14+
}
15+
1016
.incomingBusesWrapper {
1117
overflow: auto;
1218
margin: 1rem 0 1.5rem;

website/src/views/mobility/StopDetails.tsx

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,11 +468,42 @@ function StopDetails(props: Props) {
468468
// )
469469
// .sort((a, b) => a.number - b.number);
470470

471+
const subtitle = [];
472+
if (ShortName !== LongName) {
473+
subtitle.push(<span>{LongName}</span>);
474+
}
475+
476+
if (stopDetails.opposite) {
477+
const oppositeStop = isbStops.find((s) => s.name === stopDetails.opposite);
478+
const oppositeStopName = oppositeStop?.ShortName || stopDetails.opposite;
479+
subtitle.push(
480+
<span>
481+
{
482+
// if opposite stop name starts with "Opp", OR this stop name starts with "Opp" and the other one ends in the same, don't show "Opp: "
483+
// oppositeStopName.startsWith('Opp') ? '' : 'Opp: '
484+
(oppositeStopName.startsWith('Opp') && oppositeStopName.endsWith(ShortName)) ||
485+
(ShortName.startsWith('Opp') && oppositeStopName.endsWith(ShortName.replace('Opp ', '')))
486+
? ''
487+
: 'Opp: '
488+
}{' '}
489+
<Link to={`/mobility/stop/${stopDetails.opposite}`}>{oppositeStopName}</Link>
490+
</span>,
491+
);
492+
}
493+
471494
return (
472-
<div>
495+
<div className={styles.stopDetails}>
473496
<Title description={`NUS Internal Shuttle Bus ${LongName} Stop`}>{`${ShortName}`}</Title>
474497
<h1>{ShortName}</h1>
475-
{ShortName !== LongName && <h2 className={classNames('h3', styles.fullname)}>{LongName}</h2>}
498+
<p>
499+
{/* show subtitiles with " • " as the delimiter */}
500+
{subtitle.map((s, i) => (
501+
<Fragment key={i}>
502+
{i > 0 && ' • '}
503+
{s}
504+
</Fragment>
505+
))}
506+
</p>
476507

477508
<div className={styles.incomingBusesWrapper}>
478509
<ol className={styles.incomingBuses}>

website/src/views/mobility/isb.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ interface ISBStop {
6666
collapseBehavior?: string;
6767
collapsePair?: string;
6868
collapseLabel?: undefined;
69+
opposite: string | null;
6970
}
7071

7172
interface ScheduleBlock {

0 commit comments

Comments
 (0)