Skip to content
Draft
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
4 changes: 1 addition & 3 deletions app/component/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import PropTypes from 'prop-types';
import React, { forwardRef } from 'react';
import cx from 'classnames';

const Card = forwardRef(({ className, children, ...rest }, ref) => {
const Card = forwardRef(({ className = undefined, children, ...rest }, ref) => {
return (
<div ref={ref} className={cx('card', className)} {...rest}>
{children}
Expand All @@ -17,6 +17,4 @@ Card.propTypes = {
children: PropTypes.node.isRequired,
};

Card.defaultProps = { className: undefined };

export default Card;
5 changes: 5 additions & 0 deletions app/component/Icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ const Icon = ({
viewBox={!omitViewBox ? viewBox : null}
className={cx('icon', className)}
aria-label={ariaLabel}
transform={
background?.props?.shape === 'stopsign'
? 'translate(0, -3.33)'
: undefined
}
>
{background}
<g
Expand Down
20 changes: 10 additions & 10 deletions app/component/icon/IconBackground.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';

const STOP_SIGN_POLE_WIDTH = 4;
const STOP_SIGN_POLE_WIDTH = 3;
const STOP_SIGN_POLE_X = 20 - STOP_SIGN_POLE_WIDTH / 2;

const IconBackground = ({ shape, color }) => {
Expand All @@ -10,23 +10,23 @@ const IconBackground = ({ shape, color }) => {
}
return (
<>
<circle
className="icon-circle"
cx="20"
cy="20"
fill={color}
r={shape === 'stopsign' ? '13.33' : '20'}
/>
{shape === 'stopsign' && (
<rect
x={STOP_SIGN_POLE_X}
y="33.33"
y="30"
width={STOP_SIGN_POLE_WIDTH}
height="6.67"
height="10"
fill="#333333"
rx="2"
/>
)}
<circle
className="icon-circle"
cx="20"
cy="20"
fill={color}
r={shape === 'stopsign' ? '13.33' : '20'}
/>
{shape === 'square' && (
<rect
className="icon-square"
Expand Down
70 changes: 0 additions & 70 deletions app/component/trafficnow/Alerts.js

This file was deleted.

119 changes: 119 additions & 0 deletions app/component/trafficnow/CanceledTripCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import React from 'react';
import { useRouter } from 'found';
import { DateTime } from 'luxon';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import { useConfigContext } from '../../configurations/ConfigContext';
import { PREFIX_TIMETABLE, routePagePath } from '../../util/path';
import Card from '../Card';
import Icon from '../Icon';
import CancelledDepartures from './components/CancelledDepartures';
import RouteBadgeGroup from './components/RouteBadgeGroup';
import DisruptionBadge from './DisruptionBadge';

const CanceledTripCard = ({ mode, totalCount, trips }) => {
const { router } = useRouter();
const { colors } = useConfigContext();

const handleRouteBadgeClick = url => e => {
e.preventDefault();
e.stopPropagation();
router.push(url);
};

/* eslint-disable no-param-reassign */
const groupedTrips = trips.reduce((container, { start, trip }) => {
if (!trip?.route?.gtfsId || !start?.schedule?.time?.departure) {
return container;
}

const shortName = trip?.route?.shortName || 'unknown';
if (container[shortName]) {
container[shortName].trips.push({
...trip,
departureTime: DateTime.fromISO(
start?.schedule.time.departure,
).toFormat('HH:mm'),
});
} else {
container[shortName] = {
routeGtfsId: trip.route.gtfsId,
trips: [
{
...trip,
departureTime: DateTime.fromISO(
start?.schedule.time.departure,
).toFormat('HH:mm'),
},
],
};
}
return container;
}, {});

const isSingleRoute = Object.keys(groupedTrips).length === 1;

return (
<Card
className="disruption-card clickable"
onClick={handleRouteBadgeClick(`/liikenne/peruutukset/${mode}`)}
>
<header>
<DisruptionBadge showIcon variant="WARNING" label="NO_SERVICE" />
<button type="button">
<Icon
img="icon_arrow-collapse--right"
color={colors.primary}
className="disruption-card__icon"
/>
</button>
</header>
<div className="badges">
<RouteBadgeGroup
mode={mode}
stopPropagation
routes={Object.entries(groupedTrips).map(
([shortName, { routeGtfsId, trips: groupedRouteTrips }]) => ({
id: shortName,
name: shortName,
url: routePagePath(routeGtfsId, PREFIX_TIMETABLE),
gtfsId: routeGtfsId,
trips: groupedRouteTrips,
}),
)}
renderRouteSuffix={({ trips: groupedRouteTrips }) =>
isSingleRoute ? (
<CancelledDepartures
departures={groupedRouteTrips.map(
({ tripId, departureTime }) => ({
tripId,
departureTime,
}),
)}
/>
) : null
}
renderSuffix={
totalCount > trips.length ? (
<span style={{ backgroundColor: '#F2F5F7' }}>
<Icon img="icon_three-dots" width={1.3} height={1.3} />
</span>
) : null
}
/>
</div>
<div className="disruption-card__body-row-validity-icon text-xs">
<Icon img="icon_clock" />
<FormattedMessage id="valid" default="Active" />
</div>
</Card>
);
};

CanceledTripCard.propTypes = {
mode: PropTypes.string.isRequired,
totalCount: PropTypes.number.isRequired,
trips: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
};

export default CanceledTripCard;
Loading