Skip to content

Commit ae6e97d

Browse files
authored
feat(venues): add highlighting for matched substrings in Venue Search (#3722)
1 parent 512d3e8 commit ae6e97d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

website/src/views/venues/VenueList.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ import { Link, LinkProps } from 'react-router-dom';
66
import { Venue, VenueLocationMap } from 'types/venues';
77
import { venuePage } from 'views/routes/paths';
88

9+
import { highlight } from 'utils/react';
10+
import { tokenize } from 'utils/moduleSearch';
911
import styles from './VenueList.scss';
1012

1113
type Props = {
1214
venues: Venue[];
1315
venueLocations?: VenueLocationMap;
1416
selectedVenue?: Venue | null;
1517
linkProps?: Omit<LinkProps, 'to'>;
18+
query?: string;
1619
};
1720

1821
const VenueList: React.FC<Props> = (props) => {
@@ -21,6 +24,8 @@ const VenueList: React.FC<Props> = (props) => {
2124
const venueList = groupBy(physicalVenues, (venue) => venue.charAt(0).toUpperCase());
2225
const sortedVenueList = sortBy(toPairs(venueList), ([key]) => key);
2326

27+
const tokens = props.query ? tokenize(props.query.toLowerCase()) : [];
28+
2429
return (
2530
<ul className={styles.venueList}>
2631
{sortedVenueList.map(([heading, venues]) => (
@@ -41,15 +46,15 @@ const VenueList: React.FC<Props> = (props) => {
4146
)}
4247
{...props.linkProps}
4348
>
44-
<div>{venue}</div>
49+
<div>{highlight(venue, tokens)}</div>
4550
{props.venueLocations && props.venueLocations[venue] ? (
4651
<div
4752
className={classnames(
4853
'font-weight-light d-inline-block text-truncate',
4954
styles.subtitle,
5055
)}
5156
>
52-
{props.venueLocations[venue].roomName}
57+
<span>{highlight(`${props.venueLocations[venue].roomName}`, tokens)}</span>
5358
</div>
5459
) : null}
5560
</Link>

website/src/views/venues/VenuesContainer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ export class VenuesContainerComponent extends Component<Props, State> {
331331
venues={matchedVenues.map(([venue]) => venue)}
332332
venueLocations={venueLocations}
333333
selectedVenue={selectedVenue}
334+
query={searchTerm}
334335
/>
335336
)}
336337
</div>

0 commit comments

Comments
 (0)