This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDisplay.tsx
79 lines (73 loc) · 2.29 KB
/
Display.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import React, { PureComponent } from "react";
import { DestinationSidebarView } from "./DestinationSidebarView";
import { DisplayMapContainer } from "./DisplayMapContainer";
import "./display.css";
import { PublishedItinerary } from "../../authoring/data/PublishedItinerary";
import { DestinationDetails } from "./DestinationDetails";
interface Props {
trip: PublishedItinerary | undefined;
}
interface State {
focusedStopID: string | null;
}
export default class DisplayComponent extends PureComponent<Props, State> {
constructor(props) {
super(props);
this.state = {
focusedStopID: null
};
}
render() {
const { trip } = this.props;
if (trip) {
const { description, sequence, stops, title, paths, points } = trip;
const { focusedStopID } = this.state;
return (
<div className="page">
<h1>{title}</h1>
<p>{description}</p>
<DisplayMapContainer
focusedStop={focusedStopID ? stops[focusedStopID] : null}
setFocus={this.setFocus}
className="map"
accessToken={process.env.REACT_APP_MAPBOX_API_KEY!}
paths={paths}
points={points}
/>
<section className="sidebar">
<section className="stops">
{sequence.map(id => {
const stop = stops[id];
const focused = id === focusedStopID;
return (
<DestinationSidebarView
key={stop.id}
duration={stop.lengthOfStay}
focused={focused}
name={stop.title}
onClick={() => {
if (focusedStopID === id) {
this.setFocus(null);
} else {
this.setFocus(id);
}
}}
/>
);
})}
</section>
<section>{focusedStopID && <DestinationDetails stop={stops[focusedStopID]} />}</section>
</section>
</div>
);
}
return <h1>No trip itinerary given</h1>;
}
setFocus = (id: string | null) => {
if (id) {
this.setState({ focusedStopID: id });
} else {
this.setState({ focusedStopID: null });
}
};
}