Skip to content

Commit d2269c4

Browse files
authored
Merge pull request #5210 from HSLdevcom/DT-6620
DT-6620:Fix top cards width and another small adjustments
2 parents ec7fa53 + 3b4c03e commit d2269c4

File tree

5 files changed

+98
-62
lines changed

5 files changed

+98
-62
lines changed

app/component/itinerary/navigator/NaviCardContainer.js

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,34 @@ import { updateClient, getTopics } from '../ItineraryPageUtils';
1818

1919
const TIME_AT_DESTINATION = 3; // * 10 seconds
2020
const TOPBAR_PADDING = 8; // pixels
21+
const HIDE_TOPCARD_DURATION = 2000; // milliseconds
2122

2223
function addMessages(incominMessages, newMessages) {
2324
newMessages.forEach(m => {
2425
incominMessages.set(m.id, m);
2526
});
2627
}
28+
29+
const handleLegChange = (leg, firstLeg, time) => {
30+
let legType;
31+
if (time < legTime(firstLeg.start)) {
32+
legType = LEGTYPE.PENDING;
33+
} else if (leg) {
34+
if (!leg.transitLeg) {
35+
if (leg.current >= TIME_AT_DESTINATION) {
36+
legType = LEGTYPE.WAIT;
37+
} else {
38+
legType = LEGTYPE.MOVE;
39+
}
40+
} else {
41+
legType = LEGTYPE.TRANSIT;
42+
}
43+
} else {
44+
legType = LEGTYPE.WAIT;
45+
}
46+
return legType;
47+
};
48+
2749
function NaviCardContainer(
2850
{
2951
focusToLeg,
@@ -36,6 +58,7 @@ function NaviCardContainer(
3658
nextLeg,
3759
firstLeg,
3860
lastLeg,
61+
previousLeg,
3962
isJourneyCompleted,
4063
},
4164
context,
@@ -45,8 +68,7 @@ function NaviCardContainer(
4568
const [messages, setMessages] = useState(new Map());
4669
// notifications that are shown to the user.
4770
const [activeMessages, setActiveMessages] = useState([]);
48-
const [topPosition, setTopPosition] = useState(0);
49-
71+
const [legChanging, setLegChanging] = useState(false);
5072
const legRef = useRef(currentLeg);
5173
const focusRef = useRef(false);
5274
// Destination counter. How long user has been at the destination. * 10 seconds
@@ -73,14 +95,6 @@ function NaviCardContainer(
7395
updateClient(topics, context);
7496
}, []);
7597

76-
useEffect(() => {
77-
if (cardRef.current) {
78-
const contentHeight = cardRef.current.getBoundingClientRect();
79-
// Navistack top position depending on main card height.
80-
setTopPosition(contentHeight.bottom + TOPBAR_PADDING);
81-
}
82-
}, [currentLeg, cardExpanded]);
83-
8498
useEffect(() => {
8599
const incomingMessages = new Map();
86100

@@ -113,9 +127,14 @@ function NaviCardContainer(
113127
...getAdditionalMessages(nextLeg, time, intl, config, messages),
114128
]);
115129
}
130+
let timeoutId;
116131
if (legChanged) {
117132
updateClient(topics, context);
118133
setCardExpanded(false);
134+
setLegChanging(true);
135+
timeoutId = setTimeout(() => {
136+
setLegChanging(false);
137+
}, HIDE_TOPCARD_DURATION);
119138
if (currentLeg) {
120139
focusToLeg?.(currentLeg);
121140
}
@@ -161,32 +180,27 @@ function NaviCardContainer(
161180
// Todo: this works in transit legs, but do we need additional logic for bikes / scooters?
162181
destCountRef.current = 0;
163182
}
183+
184+
return () => clearTimeout(timeoutId);
164185
}, [time]);
165186

166-
let legType;
167-
168-
if (time < legTime(firstLeg.start)) {
169-
legType = LEGTYPE.PENDING;
170-
} else if (currentLeg) {
171-
if (!currentLeg.transitLeg) {
172-
if (destCountRef.current >= TIME_AT_DESTINATION) {
173-
legType = LEGTYPE.WAIT;
174-
} else {
175-
legType = LEGTYPE.MOVE;
176-
}
177-
} else {
178-
legType = LEGTYPE.TRANSIT;
179-
}
180-
} else {
181-
legType = LEGTYPE.WAIT;
182-
}
187+
// LegChange fires animation, we need to keep the old data until card goes out of the view.
188+
const l = legChanging ? previousLeg : currentLeg;
189+
const legType = handleLegChange(l, firstLeg, time);
183190

184191
const containerTopPosition =
185192
mapLayerRef.current.getBoundingClientRect().top + TOPBAR_PADDING;
186-
193+
let className;
194+
if (isJourneyCompleted) {
195+
className = 'slide-out';
196+
} else if (legChanging) {
197+
className = 'hide-card';
198+
} else {
199+
className = 'show-card';
200+
}
187201
return (
188202
<div
189-
className={`navi-card-container ${isJourneyCompleted ? 'slide-out' : ''}`}
203+
className={`navi-card-container ${className}`}
190204
style={{ top: containerTopPosition }}
191205
>
192206
<button
@@ -197,7 +211,7 @@ function NaviCardContainer(
197211
>
198212
<div className="content">
199213
<NaviCard
200-
leg={currentLeg}
214+
leg={l}
201215
nextLeg={nextLeg}
202216
cardExpanded={cardExpanded}
203217
legType={legType}
@@ -209,11 +223,7 @@ function NaviCardContainer(
209223
</div>
210224
</button>
211225
{activeMessages.length > 0 && (
212-
<NaviStack
213-
messages={activeMessages}
214-
handleRemove={handleRemove}
215-
topPosition={topPosition}
216-
/>
226+
<NaviStack messages={activeMessages} handleRemove={handleRemove} />
217227
)}
218228
</div>
219229
);
@@ -237,6 +247,7 @@ NaviCardContainer.propTypes = {
237247
nextLeg: legShape,
238248
firstLeg: legShape,
239249
lastLeg: legShape,
250+
previousLeg: legShape,
240251
isJourneyCompleted: PropTypes.bool,
241252

242253
/*
@@ -251,6 +262,7 @@ NaviCardContainer.defaultProps = {
251262
nextLeg: undefined,
252263
firstLeg: undefined,
253264
lastLeg: undefined,
265+
previousLeg: undefined,
254266
isJourneyCompleted: false,
255267
};
256268

app/component/itinerary/navigator/NaviContainer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ function NaviContainer(
8686
firstLeg={firstLeg}
8787
lastLeg={lastLeg}
8888
isJourneyCompleted={isJourneyCompleted}
89+
previousLeg={previousLeg}
8990
/>
9091
{isJourneyCompleted && isNavigatorIntroDismissed && (
9192
<NavigatorOutroModal

app/component/itinerary/navigator/NaviStack.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import PropTypes from 'prop-types';
33
import cx from 'classnames';
44
import NaviMessage from './NaviMessage';
55

6-
const NaviStack = ({ messages, handleRemove, topPosition }) => {
6+
const NaviStack = ({ messages, handleRemove }) => {
77
return (
8-
<div className={cx('info-stack', 'slide-in')} style={{ top: topPosition }}>
8+
<div className={cx('info-stack', 'slide-in')}>
99
{messages.map((notification, index) => (
1010
<NaviMessage
1111
key={notification.id}
@@ -29,7 +29,6 @@ NaviStack.propTypes = {
2929
}),
3030
).isRequired,
3131
handleRemove: PropTypes.func.isRequired,
32-
topPosition: PropTypes.number.isRequired,
3332
};
3433

3534
export default NaviStack;

app/component/itinerary/navigator/NaviUtils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ export const getItineraryAlerts = (
321321
<span className="header"> {alert.alertHeaderText}</span>
322322
</div>
323323
),
324-
id: alert.id,
324+
id: `${alert.effectiveStartDate}-${alert.alertDescriptionText}`,
325325
}));
326326
});
327327
const abortTrip = <FormattedMessage id="navigation-abort-trip" />;
@@ -368,6 +368,7 @@ export const getItineraryAlerts = (
368368
content,
369369
id: `canceled-${legId}`,
370370
hideClose: true,
371+
expiresOn: alert.effectiveEndDate * 1000,
371372
});
372373
}
373374
});

app/component/itinerary/navigator/navigator.scss

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
$fixed-width-padding: 16px;
2+
13
.navi-start-container {
24
padding: 0 10px;
35

@@ -48,12 +50,19 @@
4850
&.slide-out {
4951
animation: slideUpToTop 3s ease-out forwards;
5052
}
53+
54+
&.hide-card {
55+
animation: hideTopCard 2s ease-out forwards;
56+
pointer-events: none;
57+
}
58+
59+
&.show-card {
60+
animation: slideDownFromTop 2s ease-out forwards;
61+
}
5162
}
5263

5364
.navitop {
54-
margin-bottom: 5px;
55-
width: 92%;
56-
margin-left: 8px;
65+
margin: 0 var(--space-s) 5px var(--space-s);
5766
border-radius: 8px;
5867
min-height: 70px;
5968
color: black;
@@ -62,6 +71,7 @@
6271
align-items: center;
6372
letter-spacing: -0.3px;
6473
box-shadow: 0 2px 4px 0 rgba(51, 51, 51, 0.2);
74+
width: calc(100vw - #{$fixed-width-padding});
6575

6676
&.expanded {
6777
max-height: unset;
@@ -120,10 +130,9 @@
120130

121131
.wait-leg {
122132
display: flex;
123-
align-items: center;
124133
margin-top: 3px;
125134
flex-direction: column;
126-
align-self: flex-start;
135+
align-items: flex-start;
127136

128137
.route-info {
129138
display: flex;
@@ -365,9 +374,10 @@
365374
.info-stack {
366375
position: fixed;
367376
height: 69px;
368-
margin-left: 8px;
369-
width: 90%;
370377
letter-spacing: -0.3px;
378+
width: calc(100% - #{$fixed-width-padding});
379+
margin-right: 8px;
380+
margin-left: 8px;
371381

372382
div:first-child {
373383
margin-top: 0;
@@ -418,6 +428,8 @@
418428
.navi-alert-content {
419429
width: 100%;
420430
margin: 0 8px;
431+
display: flex;
432+
flex-direction: column;
421433
}
422434
}
423435

@@ -428,6 +440,7 @@
428440
display: flex;
429441
flex-direction: column;
430442
margin: 0 8px;
443+
width: 100%;
431444

432445
span:first-child {
433446
font-weight: $font-weight-medium;
@@ -443,24 +456,24 @@
443456
font-size: $font-size-small;
444457
}
445458
}
459+
}
446460

447-
.alt-btn {
448-
display: flex;
449-
flex-direction: column;
450-
width: 100%;
451-
452-
.show-options {
453-
padding: var(--space-s, 16px) var(--space-xs, 8px)
454-
var(--space-s, 16px) var(--space-s, 16px);
455-
background: #0074bf;
456-
color: #fff;
457-
border-radius: 999px; // var(--radius-radius-medium, 8px);
458-
margin-top: var(--space-xxs);
461+
.alt-btn {
462+
display: flex;
463+
flex-direction: column;
464+
width: 100%;
459465

460-
/* box-shadow-card-s-strong */
461-
box-shadow: 0 2px 4px 0
462-
var(--color-shadow-strong, rgba(51, 51, 51, 0.2));
463-
}
466+
.show-options {
467+
padding: var(--space-s, 16px) var(--space-xs, 8px) var(--space-s, 16px)
468+
var(--space-s, 16px);
469+
background: #0074bf;
470+
color: #fff;
471+
border-radius: 999px; // var(--radius-radius-medium, 8px);
472+
margin-top: var(--space-xxs);
473+
474+
/* box-shadow-card-s-strong */
475+
box-shadow: 0 2px 4px 0
476+
var(--color-shadow-strong, rgba(51, 51, 51, 0.2));
464477
}
465478
}
466479

@@ -601,6 +614,16 @@
601614
}
602615
}
603616

617+
@keyframes hideTopCard {
618+
from {
619+
transform: translateY(0);
620+
}
621+
622+
to {
623+
transform: translateY(-100%);
624+
}
625+
}
626+
604627
@keyframes slideUpFromBottom {
605628
from {
606629
transform: translateY(100%);

0 commit comments

Comments
 (0)