├── .gitignore
├── README.md
├── package-lock.json
├── package.json
├── public
├── event-map-social-preview.jpg
├── favicon.ico
├── index.html
├── logo192.png
├── logo512.png
├── manifest.json
└── robots.txt
├── src
├── App.js
├── App.scss
├── App.test.js
├── EventList.js
├── History.js
├── Map.js
├── MobileList.js
├── SearchBar.js
├── Util.js
├── downArrow.svg
├── img
│ ├── icon_512x512.png
│ ├── marker-shadow.png
│ ├── w-marker-icon-2x-highlighted.png
│ └── w-marker-icon-2x.png
├── index.css
├── index.js
├── logo.svg
└── serviceWorker.js
└── yarn.lock
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | src/js/old.js
3 | todo.txt
4 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
5 |
6 | # dependencies
7 | /node_modules
8 | /.pnp
9 | .pnp.js
10 |
11 | # testing
12 | /coverage
13 |
14 | # production
15 | /build
16 |
17 | # misc
18 | .DS_Store
19 | .env.local
20 | .env.development.local
21 | .env.test.local
22 | .env.production.local
23 |
24 | npm-debug.log*
25 | yarn-debug.log*
26 | yarn-error.log*
27 | src/ScrapCode.js
28 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Event Map
2 |
3 | This project provides a map of all of the events specific to an organization's account in Mobilize America. It loads the events via the Mobilize API ([docs for /events endpoint](https://github.com/mobilizeamerica/api#request-2)).
4 |
5 | The project originated with the [Tech for Warren group](https://github.com/techforwarren/eventmap) in 2019.
6 |
7 | ## Working version
8 |
9 | The event map is now live at [https://hope-and-code-labs.github.io/eventmap/](https://hope-and-code-labs.github.io/eventmap/)! Future merges to the `gh-pages` branch will update this site.
10 |
11 | ## Getting Started - Cloning & Installation
12 |
13 | You can clone the GitHub repo or download it from the repo page. After it is on your local machine, be sure to run `npm install` to install all dependencies.
14 |
15 | Change the `mobilizeOrgId` variable in src/App.js to reflect your organization's id in Mobilize. The default is the organization id for the Warren for President campaign.
16 |
17 | ## Running App Locally - `npm start`
18 |
19 | Runs the app in the development mode.
20 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
21 |
22 | The page will reload if you make edits.
23 | You will also see any lint errors in the console.
24 |
25 |
26 | ## Deploying For Github Pages - `npm run deploy`
27 |
28 | Should ideally be done from the `main` branch.
29 |
30 | Follows the create-react-app [Github Pages deployment steps](https://facebook.github.io/create-react-app/docs/deployment).
31 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "eventmap",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@types/lodash.sortby": "^4.7.6",
7 | "history": "^4.10.1",
8 | "leaflet": "^1.5.1",
9 | "lodash.groupby": "^4.6.0",
10 | "lodash.sortby": "^4.7.0",
11 | "moment": "^2.24.0",
12 | "node-sass": "^7.0.0",
13 | "query-string": "^6.8.3",
14 | "react": "^16.9.0",
15 | "react-device-detect": "^1.9.10",
16 | "react-dom": "^16.9.0",
17 | "react-ga": "^2.7.0",
18 | "react-scripts": "3.1.1",
19 | "twix": "^1.3.0"
20 | },
21 | "scripts": {
22 | "start": "react-scripts start",
23 | "build": "react-scripts build",
24 | "test": "jest --watchAll",
25 | "eject": "react-scripts eject",
26 | "predeploy": "npm run build",
27 | "deploy": "gh-pages -d build"
28 | },
29 | "eslintConfig": {
30 | "extends": "react-app"
31 | },
32 | "browserslist": {
33 | "production": [
34 | ">0.2%",
35 | "not dead",
36 | "not op_mini all"
37 | ],
38 | "development": [
39 | "last 1 chrome version",
40 | "last 1 firefox version",
41 | "last 1 safari version"
42 | ]
43 | },
44 | "homepage": "https://hope-and-code-labs.github.io/eventmap/",
45 | "devDependencies": {
46 | "gh-pages": "^2.1.1"
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/public/event-map-social-preview.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/techforwarren/eventmap/9a0a092ff8e774cbce013bcd9887ec1ca65689f5/public/event-map-social-preview.jpg
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/techforwarren/eventmap/9a0a092ff8e774cbce013bcd9887ec1ca65689f5/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | above a
8 | * scrolling list of events that match the search criteria.
9 | * The width of the first column is constrained. The right
10 | * column contains the map and it grows/shrinks to use up
11 | * all of the remaining available space.
12 | *
13 | * On mobile, there is a single column that contains (in
14 | * order from top to bottom): the search criteria then
15 | * the map and then an area where the event details are
16 | * provided along with buttons (previous, Info/RSVP, next).
17 | *
18 | * As you will see, we use CSS grid to implement this layout.
19 | *
20 | * To distinguish between the desktop and mobile cases, there
21 | * is a class defined for each case: "appIsDesktop" and
22 | * "appIsMobile".
23 | *
24 | */
25 |
26 | .appIsDesktop {
27 | display: grid; /* on desktop use a two column grid layout - right column grows/shrinks */
28 | grid-template-columns: minmax(180px,300px) auto;
29 |
30 | #map{
31 | height: 100vh;
32 | z-index: 9;
33 | }
34 |
35 | }
36 |
37 | .appIsMobile {
38 | display: grid; /* on mobile use a row grid with three rows: search, map, card & nav */
39 | grid-template-rows: min-content auto min-content;
40 |
41 | #map{
42 | z-index: 9; /* frm: not sure z-index does anything for mobile */
43 | }
44 |
45 | }
46 |
47 | .app{
48 | height: 100vh;
49 |
50 | #startLoad{
51 | position: fixed;
52 | width: 100%;
53 | z-index: 10;
54 | text-align: center;
55 | padding-top: 20vh;
56 | background-color: rgba(183, 228, 207,0.85);
57 | height: 100%;
58 | color: #232444;
59 | margin-top: 0px;
60 |
61 | @media only screen and (max-width: 425px) {
62 | padding-top: 25vh;
63 | }
64 |
65 |
66 | #firstLine, #secondLine, #thirdLine{
67 | display: block;
68 | margin-top: 0px;
69 | margin-bottom: 0px;
70 |
71 | }
72 |
73 | #firstLine, #thirdLine{
74 | font-size: 10vh;
75 | img{
76 | height: 10vh;
77 | }
78 |
79 | @media only screen and (max-width: 768px) {
80 | font-size: 10vw;
81 | img{
82 | height: 10vw;
83 | }
84 | }
85 | }
86 | #secondLine{
87 | font-size: 20vh;
88 | color: white;
89 | font-style: italic;
90 | text-shadow: -1px -1px 0 #232444, 1px -1px 0 #232444, -1px 1px 0 #232444, 1px 1px 0 #232444;
91 | @media only screen and (max-width: 768px) {
92 | font-size: 20vw;
93 | }
94 | }
95 |
96 | #searchCTA{
97 | color: #b61b28;
98 | font-style: italic;
99 | font-size: 3vh;
100 | @media only screen and (max-width: 768px) {
101 | font-size: 3vw;
102 | }
103 | }
104 |
105 |
106 | }
107 |
108 | }
109 |
110 | html, body, #root, .app {
111 | height: 100%;
112 | }
113 |
114 | .searchBar{
115 | background-color: #232444;
116 | z-index:11; /* frm: not sure we need z-index anymore */
117 | box-shadow: 10px 0px 5px rgba(0, 0, 0, .3);
118 | }
119 |
120 | .desktopSearch {
121 | /* For desktop, we want two rows: 1) search criteria and 2) the scrolling list of events */
122 | height: 100vh;
123 | display: grid;
124 | grid-template-rows: auto auto;
125 | grid-gap: 0;
126 | }
127 |
128 | .mobileSearch {
129 | width: 100%;
130 | top: 0;
131 | left: 0;
132 | box-shadow: 0px 5px 5px rgba(0, 0, 0, .3);
133 | touch-action: manipulation;
134 |
135 | #zipForm{
136 | padding-left: 0%;
137 | padding-right: 5%;
138 | }
139 |
140 | #zipInput {
141 | -webkit-border-radius: 0;
142 | border-radius: 0;
143 | -webkit-box-shadow: none;
144 | box-shadow: none;
145 | width: 80%;
146 | }
147 | #locateMe {
148 | width: 25% !important;
149 | }
150 |
151 | .kindOfEvent, .searchRange{
152 | padding-top: 1%;
153 | padding-bottom: 1%;
154 | }
155 |
156 | }
157 |
158 | .activeList{
159 | padding-bottom: 0px;
160 | }
161 |
162 | .userInput{
163 |
164 | display: flex;
165 | align-items: flex-end;
166 | justify-content: center;
167 | padding-left: 5%;
168 | padding-right: 5%;
169 | padding-top: 5%;
170 | padding-bottom: 5%;
171 |
172 | #zipForm{
173 | display: flex;
174 | flex-flow:row nowrap;
175 | align-items: flex-end;
176 | justify-content: space-between;
177 | background-color:#232444;
178 | border-right: 1px solid white;
179 | padding-right: 9%;
180 | }
181 |
182 | label[for=zipInput] {
183 | color: white;
184 | position: fixed;
185 | font-size: 24px;
186 | }
187 |
188 | [data-has-input=true] label[for=zipInput] {
189 | color: transparent;
190 | }
191 |
192 | #zipInput{
193 | height: 30%;
194 | width: 80%;
195 | font-size: 24px;
196 | margin-right: 13%;
197 | color: white;
198 | display: block;
199 | background: none;
200 | border: none;
201 | border-bottom: 1px solid white;
202 | z-index:10;
203 | }
204 |
205 | #rangeInput{
206 | height: 30%;
207 | min-width:105px;
208 | font-size: 24px;
209 | border: none;
210 | background: none;
211 |
212 | }
213 |
214 | #submitZip{
215 | height: 35px;
216 | padding: 0;
217 | font-size: 24px;
218 | color: white;
219 | background-color: #232444;
220 | border: none;
221 | }
222 |
223 | #submitZip{
224 | height: 35px;
225 | padding: 0;
226 | font-size: 24px;
227 | color: white;
228 | background-color: #232444;
229 | border: none;
230 | }
231 |
232 |
233 | #locateMe {
234 | height: 35px;
235 | padding: 0;
236 | padding-left: 7%;
237 | color: white;
238 | background-color: #232444;
239 | border: none;
240 | img {
241 | width: 35px;
242 | z-index: 12;
243 | }
244 | }
245 |
246 |
247 | }
248 |
249 | .userOptions{
250 | display: flex;
251 | flex-wrap: wrap;
252 | background-color: #f5f5f5;
253 | }
254 |
255 | .searchRange{
256 | font-size: 16px;
257 | background-color: #f5f5f5;
258 | height:30px;
259 | line-height:30px;
260 | text-align: left;
261 | padding-left: 5px;
262 | }
263 |
264 | .searchRange select{
265 | background: none;
266 | font-size: 16px;
267 | background-color: #f5f5f5;
268 | border: none;
269 | padding: 0px 5px 0px 5px;
270 | appearance: none;
271 | -moz-appearance: none;
272 | -webkit-appearance: none;
273 | background-image: url(./downArrow.svg);
274 | background-position: calc(100% - 8px) 85%;
275 | background-size: 12px 12px;
276 | background-repeat: no-repeat;
277 |
278 | }
279 |
280 | .kindOfEvent {
281 | font-size: 16px;
282 | background-color: #f5f5f5;
283 | height:30px;
284 | line-height:30px;
285 | text-align: left;
286 | padding-left: 5px;
287 | }
288 |
289 | .kindOfEvent > p {
290 | margin: 0; /* inhibit normal margins - so we can pack stuff together */
291 | }
292 |
293 | .searchRange > p {
294 | margin: 0; /* inhibit normal margins - so we can pack stuff together */
295 | }
296 |
297 | .kindOfEvent select{
298 | background: none;
299 | font-size: 16px;
300 | background-color: #f5f5f5;
301 | border: none;
302 | padding: 0px 20px 0px 5px;
303 | appearance: none;
304 | -moz-appearance: none;
305 | -webkit-appearance: none;
306 | background-image: url(./downArrow.svg);
307 | background-position: calc(100% - 8px) 85%;
308 | background-size: 12px 12px;
309 | background-repeat: no-repeat;
310 |
311 | }
312 |
313 |
314 |
315 | .eventList{
316 | background-color: white;
317 | overflow:hidden;
318 | overflow-y:scroll;
319 | margin-bottom: 0px;
320 | padding-left: 0px;
321 | margin-top: 0px;
322 |
323 | .eventCard{
324 | text-decoration: none;
325 | color: #232444;
326 |
327 | h3{
328 | text-transform: uppercase;
329 | }
330 |
331 | :hover{
332 | color: white;
333 | }
334 |
335 | li{
336 | list-style-type: none;
337 | padding-left: 10%;
338 | padding-right: 10%;
339 | padding-top: 5%;
340 | padding-bottom: 5%;
341 | border-top: 1px solid #E8E8E8;
342 | border-bottom: 1px solid #E8E8E8;
343 | position: relative;
344 |
345 | .eventRSVP{
346 | visibility: hidden;
347 | text-align: right;
348 | }
349 |
350 | }
351 |
352 | li:hover{
353 | background-color: #232444;
354 |
355 | .eventRSVP{
356 | visibility: visible;
357 | }
358 | }
359 |
360 | }
361 |
362 | .kicker{
363 | list-style-type: none;
364 | padding-left: 10%;
365 | padding-right: 10%;
366 | padding-top: 5%;
367 | padding-bottom: 5%;
368 | border-top: 1px solid #E8E8E8;
369 | border-bottom: 1px solid #E8E8E8;
370 | position: relative;
371 | }
372 |
373 | }
374 |
375 | .mobileList{
376 | margin: none;
377 | font-size:calc(10px + 1vw);
378 | touch-action: manipulation;
379 |
380 | .eventCard{
381 |
382 | text-decoration: none;
383 | color: #232444;
384 | z-index: 10;
385 | bottom: 10%;
386 | background-color: white;
387 | left: 5%;
388 | max-height: 30vh;
389 | min-height: 10vh;
390 |
391 | h3{
392 | margin-top: 10px;
393 | margin-bottom: 10px;
394 | text-transform: uppercase;
395 | }
396 |
397 | p {
398 | margin: 2px;
399 | }
400 |
401 | .mobileInfo{
402 | padding-left: 5%;
403 | padding-right: 5%;
404 | padding-bottom: 1%;
405 |
406 | .eventRSVP{
407 | display: none;
408 | }
409 |
410 | }
411 | }
412 |
413 | .mobileNavWrapper { /* contains navigation buttons (next/prev) and Info/RSVP button */
414 | display: flex;
415 | flex-direction: row;
416 | justify-content: space-around;
417 | }
418 |
419 | button{
420 | bottom: 3%;
421 | z-index: 10;
422 | background-color: #232444;
423 | border: none;
424 | color: white;
425 | font-size: 16px;
426 | height: 30px;
427 |
428 | }
429 | #mobileRSVP{
430 | flex: 1; /* Info/RSVP button stretches to use up all available space */
431 | a{
432 | text-decoration: none;
433 | color:white;
434 | }
435 | }
436 | #leftIndex{
437 | width: 50px;
438 | border-right: 3px solid white; /* separate nav button from RSVP/Info button */
439 | }
440 | #rightIndex{
441 | width: 50px;
442 | border-left: 3px solid white; /* separate nav button from RSVP/Info button */
443 | }
444 | }
445 |
446 |
447 |
448 | // Disables the up/down arrows on the number input
449 | input[type="number"]::-webkit-outer-spin-button,
450 | input[type="number"]::-webkit-inner-spin-button {
451 | -webkit-appearance: none;
452 | margin: 0;
453 | }
454 | input[type="number"] {
455 | -moz-appearance: textfield;
456 | }
457 |
--------------------------------------------------------------------------------
/src/App.test.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/techforwarren/eventmap/9a0a092ff8e774cbce013bcd9887ec1ca65689f5/src/App.test.js
--------------------------------------------------------------------------------
/src/EventList.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import moment from 'moment';
3 | import groupBy from 'lodash.groupby';
4 | import sortBy from 'lodash.sortby';
5 | import { eventHasValidLocation } from './Util';
6 | require('twix');
7 |
8 |
9 | const MAX_DAYS_IN_LIST = 4;
10 |
11 | function EventTimes(props) {
12 | const { rawTimes } = props;
13 | let sortedTimesByDate = groupBy(sortBy(rawTimes,
14 | // Sort all of the ranges by when they start;
15 | // Unix returns the millisecond time, so all
16 | // events will be different
17 | (item) => { return item.start.unix() }),
18 | // Group the ranges by the day they happen on;
19 | // fully including the year, month, and day
20 | // in that order guarantees that normal sorting
21 | // will respect 9/31 v 10/1, and 2020/01 vs 2019/12
22 | (item) => { return item.start.format('YYYY-MM-DD') }
23 | )
24 |
25 | let sortedDates = Object.keys(sortedTimesByDate).sort();
26 |
27 | const dateRowFactory = (date) => {
28 | let times = sortedTimesByDate[date];
29 | let dayStr = times[0].start.format('ddd M/D')
30 | let timeStrs = times.map((time) => time.range.format({ hideDate : true })).join(', ')
31 | return (
32 |
33 | { dayStr }{' | '}{ timeStrs }
34 |
35 | )
36 | }
37 |
38 | if (sortedDates.length <= MAX_DAYS_IN_LIST) {
39 | return sortedDates.map(dateRowFactory)
40 | } else {
41 | let nextDay = sortedDates[MAX_DAYS_IN_LIST - 1];
42 | let lastDay = sortedDates[sortedDates.length - 1];
43 | let nextStart = sortedTimesByDate[nextDay][0].start;
44 | let lastStart = sortedTimesByDate[lastDay][0].start;
45 | return sortedDates.slice(0,MAX_DAYS_IN_LIST - 1).map(dateRowFactory).concat(
46 |
47 | More Times from {nextStart.twix(lastStart, { allDay : true }).format()}
48 |
49 | )
50 | }
51 | }
52 |
53 | export function EventList(props) {
54 | let listEvents;
55 | if(props.events.length > 0){
56 | listEvents = props.events.map((event) => {
57 |
58 | // Normalize Mobilize's time formatting into
59 | // easy-to-use moments
60 | let rawTimes = event['timeslots'].map((timeslot) => {
61 | let start = moment(timeslot.start_date * 1000);
62 | let end = moment(timeslot.end_date * 1000);
63 | return {
64 | start, end,
65 | range: start.twix(end)
66 | }
67 | })
68 |
69 | //Location filter: if user has clicked on a marker, then only show events at that location
70 | if(props.locFilt != null){
71 | if(eventHasValidLocation(event)) {
72 | if(event['location']['location']['latitude'] !== props.locFilt['lat'] || event['location']['location']['longitude'] !== props.locFilt['lng']){
73 | return(null); // event is not at the location filter's coordinates
74 | }
75 | } else {
76 | return(null); // event is private - no location, hence no marker
77 | }
78 | }
79 |
80 | return (
81 |
{ props.updatedHover(event['currentTarget'].getAttribute('coord')) }}
91 | onMouseLeave={(event) => { props.updatedHover(null) }}>
92 |
93 |
94 |
{event['title']}
95 |
{event['location']['venue']} {event['location']['locality'] ? "in" : ""} {event['location']['locality']}
96 |
97 |
Click to RSVP
98 |
99 |
100 |
101 |
102 | )
103 | });
104 | } else {
105 | listEvents = null;
106 | }
107 |
108 | // At this point listEvents is either null or the HTML for a list of each of the events
109 |
110 | return (
111 |
116 | );
117 |
118 | }
119 |
120 | export default EventList;
121 |
--------------------------------------------------------------------------------
/src/History.js:
--------------------------------------------------------------------------------
1 | import { createBrowserHistory } from 'history';
2 | const history = createBrowserHistory();
3 |
4 | export default history;
--------------------------------------------------------------------------------
/src/Map.js:
--------------------------------------------------------------------------------
1 | import React, { useState, useEffect, useRef } from 'react';
2 | import L from 'leaflet';
3 | import gMark from './img/w-marker-icon-2x.png';
4 | import hMark from './img/w-marker-icon-2x-highlighted.png';
5 | import sMark from './img/marker-shadow.png';
6 | import { eventHasValidLocation } from './Util';
7 |
8 | export function Map(props){
9 |
10 | const [center, setCenter] = useState([39.8283, -98.5795]); // center of the USA
11 | const [locations, setLocations] = useState({}); // set of unique lat/longs for events
12 | const [newCenter, setNewCenter] = useState(false);
13 | const map = useRef();
14 | const markers = useRef();
15 |
16 | //Called to set/unset location filter
17 | function locationFilter(event, set){
18 |
19 | if(set){
20 | props.selectLoc({
21 | 'lat': event['latlng']['lat'],
22 | 'lng': event['latlng']['lng']
23 | });
24 | } else {
25 | props.selectLoc(null);
26 | }
27 | }
28 |
29 | //First render
30 | useEffect(() => {
31 | var lastScroll = new Date().getTime();
32 | var wheelDeltaList = [];
33 |
34 | // override the scrollwheelzoom
35 | L.Map.ScrollWheelZoomExtended = L.Map.ScrollWheelZoom.extend({
36 | _performZoom: function() {
37 | var currentScrollTime = new Date().getTime();
38 | var map = this._map,
39 | zoom = map.getZoom(),
40 | delta = this._delta,
41 | normalizedDelta = 0,
42 | snap = this._map.options.zoomSnap || 0; // ??? frm: why use this._map instead of just map
43 |
44 | wheelDeltaList.push(Math.abs(delta));
45 | var average = 0;
46 | for(let i = 0; i< wheelDeltaList.length; i++){
47 | average += wheelDeltaList[i];
48 | }
49 | average = average / wheelDeltaList.length;
50 |
51 | var diffSquaredTotal= 0;
52 | for(let i = 0; i < wheelDeltaList.length; i++){
53 | var diff = wheelDeltaList[i] - average;
54 | diffSquaredTotal += Math.pow(diff,2);
55 | }
56 |
57 | var standardDeviation = Math.sqrt(diffSquaredTotal/wheelDeltaList.length);
58 | map.stop(); // stop panning and fly animations if any
59 |
60 | var deltaTime = currentScrollTime - lastScroll;
61 |
62 | var d2 = this._delta / (this._map.options.wheelPxPerZoomLevel * 4), // ??? frm: why use this._map instead of just map
63 | d3 = 4 * Math.log(2 / (1 + Math.exp(-Math.abs(d2)))) / Math.LN2,
64 | d4 = snap ? Math.ceil(d3 / snap) * snap : d3,
65 | normalizedDelta = map._limitZoom(zoom + (this._delta > 0 ? d4 : -d4)) - zoom;
66 |
67 | this._delta = 0;
68 | this._startTime = null;
69 | lastScroll = currentScrollTime;
70 | if (!normalizedDelta) {
71 | return;
72 | }
73 |
74 | if(deltaTime < 1000 && ((average+standardDeviation) >= Math.abs(delta))){
75 | return;
76 | } else if (map.options.scrollWheelZoom === 'center') {
77 | map.setZoom(zoom + normalizedDelta);
78 | } else {
79 | map.setZoomAround(this._lastMousePos, zoom + normalizedDelta);
80 | }
81 | wheelDeltaList = [];
82 | }
83 | });
84 |
85 | L.Map.addInitHook('addHandler', 'scrollWheelZoomExtended', L.Map.ScrollWheelZoomExtended);
86 |
87 | // Create the map with US center
88 | map.current = L.map('map', {
89 | zoomControl: false,
90 | scrollWheelZoom: false,
91 | scrollWheelZoomExtended: true
92 | }).setView(center, (props.events != null) ? 8 : 4);
93 |
94 | //Initializes layergroup
95 | markers.current = L.featureGroup().addTo(map.current);
96 | markers.current.on("click", (event) => locationFilter(event, true));
97 | map.current.on("click", (event) => locationFilter(event, false));
98 |
99 |
100 | // Set up the OSM layer
101 | L.tileLayer(
102 | 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
103 | attribution: 'Map data ©
OpenStreetMap contributors',
104 | maxZoom: 18
105 | }).addTo(map.current);
106 |
107 | L.control.zoom({
108 | position: 'topright'
109 | }).addTo(map.current);
110 |
111 | }, []);
112 |
113 |
114 | //When locations are updated, generate new markers
115 | useEffect(() => {
116 |
117 | if(Object.keys(locations).length > 0){
118 | markers.current.clearLayers();
119 |
120 | if(newCenter){
121 | map.current.setView(center, 8);
122 | setNewCenter(false);
123 | }
124 |
125 |
126 | var generalIcon = new L.Icon({
127 | iconUrl: gMark,
128 | shadowUrl: sMark,
129 | iconSize: [25, 41],
130 | iconAnchor: [12, 41],
131 | popupAnchor: [1, -34],
132 | shadowSize: [41, 41],
133 | });
134 | var highlightedIcon = new L.Icon({
135 | iconUrl: hMark,
136 | shadowUrl: sMark,
137 | iconSize: [25, 41],
138 | iconAnchor: [12, 41],
139 | popupAnchor: [1, -34],
140 | shadowSize: [41, 41],
141 | });
142 |
143 | for (var key in locations) {
144 | let highlighted = false;
145 |
146 | if(key === props.hoverMarker || (props.locFilt !== null && key === props.locFilt['lat'] + "&" + props.locFilt['lng'])){
147 | console.log("matching");
148 | highlighted = true;
149 | }
150 |
151 |
152 |
153 | let cord = key.split("&");
154 |
155 | if(highlighted){
156 | L.marker([parseFloat(cord[0]), parseFloat(cord[1])], {icon: highlightedIcon, zIndexOffset: 1000}).addTo(markers.current);
157 | } else {
158 | L.marker([parseFloat(cord[0]), parseFloat(cord[1])], {icon: generalIcon}).addTo(markers.current);
159 | }
160 |
161 |
162 | }
163 |
164 | /* ??? frm: The current code immediately below does not correctly resize and
165 | * rezoom on mobile. The problem is that the amount of space used
166 | * for each card varies, and hence the amount of space available
167 | * for the map can change every time the cardIndex changes.
168 | *
169 | * The code below tells the map to resize (by calling invlidatesize() )
170 | * everytime the hoverMarker changes which is almost correct. Instead
171 | * it should resize every time the cardIndex changes.
172 | *
173 | * Unfortuately, the Map currently does not know about the cardIndex
174 | * It would be easy to pass it in the way the hoverMarker is currently
175 | * passed in, but I want to wait and make that change in a separate
176 | * pull request (there is another related issue/bug concerning hoverMarker
177 | * on mobile that I will change at the same time).
178 | *
179 | * I am also not going to create an issue for this on github yet
180 | * because this is not a problem in the old UI - so it doesn't make
181 | * sense to create an issue that is not yet a problem in production.
182 | * I will create an issue once the new tiled layout is merged...
183 | */
184 |
185 | // zoom to marker bounds, plus padding to make sure entire marker is visible
186 | // ??? frm: probably only have to invalidateSize() on mobile... (but it is a cheap op)
187 | map.current.invalidateSize(); // make sure the map fits its allocated space (mobile issue)
188 | map.current.fitBounds(markers.current.getBounds().pad(0.1));
189 | }
190 | }, [locations, props.hoverMarker, props.locFilt]);
191 |
192 | //Iterates through new events
193 | useEffect(() => {
194 |
195 | if(props.events != null){
196 |
197 | if(props.events.length > 0){
198 |
199 | //Initiates map's focus at the first event (typically the closest to the provided zipcode) with a valid lat & long position
200 |
201 | // Find out whether there are any events in the list that are not private
202 | let first = -1;
203 | for (let i=0; i
283 | );
284 | }
285 |
286 | export default Map;
287 |
--------------------------------------------------------------------------------
/src/MobileList.js:
--------------------------------------------------------------------------------
1 | import React, { useEffect } from 'react';
2 | import moment from 'moment';
3 | import groupBy from 'lodash.groupby';
4 | import sortBy from 'lodash.sortby';
5 | import { eventHasValidLocation } from './Util';
6 | require('twix');
7 |
8 | const MAX_DAYS_IN_LIST = 1;
9 |
10 | function EventTimes(props) {
11 | const { rawTimes } = props;
12 | let sortedTimesByDate = groupBy(sortBy(rawTimes,
13 | // Sort all of the ranges by when they start;
14 | // Unix returns the millisecond time, so all
15 | // events will be different
16 | (item) => { return item.start.unix() }),
17 | // Group the ranges by the day they happen on;
18 | // fully including the year, month, and day
19 | // in that order guarantees that normal sorting
20 | // will respect 9/31 v 10/1, and 2020/01 vs 2019/12
21 | (item) => { return item.start.format('YYYY-MM-DD') }
22 | )
23 |
24 | let sortedDates = Object.keys(sortedTimesByDate).sort();
25 |
26 | const dateRowFactory = (date) => {
27 | let times = sortedTimesByDate[date];
28 | let dayStr = times[0].start.format('ddd M/D')
29 | let timeStrs = times.map((time) => time.range.format({ hideDate : true })).join(', ')
30 | return (
31 |
46 | More Times from {nextStart.twix(lastStart, { allDay : true }).format()}
47 |
48 | )
49 | }
50 | }
51 |
52 |
53 | /*
54 | * Utility functions for the actions for the "previous" and "next" buttons.
55 | * In each case we want to decrement/increment the cardIndex so that the
56 | * app will show the previoius/next event. But we also want to make sure
57 | * that the location filter (locFilt in App.js) is reset to null since
58 | * if we change the current event, we may move to a new location (lat/long)
59 | * and we do not want the map to continue to highlight the old locFilt
60 | * location (lat/long).
61 | */
62 |
63 | function clickPrevious(props) {
64 | if (!(props.cardIndex > 0)) { // verify that there is indeed a previous event
65 | console.warn("clickPrevious: cardIndex is not > 0");
66 | return;
67 | }
68 | props.updateCardIndex(props.cardIndex-1);
69 | props.selectLoc(null);
70 | }
71 |
72 | function clickNext(props, listEvents) {
73 | if (!(props.cardIndex < listEvents.length-1)) { // verify that there is a next event
74 | console.warn("clickNext: cardIndex is too large");
75 | return;
76 | }
77 | props.updateCardIndex(props.cardIndex+1);
78 | props.selectLoc(null);
79 | }
80 |
81 | export function MobileList(props){
82 |
83 | //Mobile's location filter doesn't filter but moves the currentIndex to the location's first event
84 | useEffect(() => {
85 |
86 | /*
87 | * If the location filter (locFilt) has changed then reset the cardIndex global.
88 | *
89 | * The location filter changes when the user clicks on a marker on the map. In this case we
90 | * set the cardIndex to the first event in the list of events that has the same lat/long
91 | * as the event the user clicked on (the click stores that event's lat/long in locFilt).
92 | *
93 | */
94 |
95 | if (props.locFilt !== null) {
96 |
97 | // Reset the cardIndex to the first event that matches the location of the locFilt location
98 | for(let x = 0; x < props.events.length; x++) {
99 | let event = props.events[x];
100 |
101 | if (eventHasValidLocation(event) &&
102 | (event['location']['location']['latitude'] === props.locFilt['lat'] ||
103 | event['location']['location']['longitude'] === props.locFilt['lng']))
104 | {
105 | // We have found the first event in the list that has the sae lat/long as the new location filter
106 | props.updateCardIndex(x); // set the cardIndex to the index of the matching event
107 | x = props.events.length; // fast forward to exit the loop
108 | }
109 | }
110 | }
111 | }, [props.locFilt])
112 |
113 | if (!props.events) { // MobileList should only be invoked if there are events, but just to be safe...
114 | console.warn("MobileList: props.events is null");
115 | return;
116 | }
117 |
118 | let listEvents = {};
119 | if(props.events.length > 0){
120 | listEvents = props.events.map((event, index) => {
121 |
122 | // Normalize Mobilize's time formatting into
123 | // easy-to-use moments
124 | let rawTimes = event['timeslots'].map((timeslot) => {
125 | let start = moment(timeslot.start_date * 1000);
126 | let end = moment(timeslot.end_date * 1000);
127 | return {
128 | start, end,
129 | range: start.twix(end)
130 | }
131 | })
132 |
133 | return (
134 | /*
135 | * frm: Original code that made the event text be an anchor tag.
136 | *
137 | * I changed this because with the new layout, the next and previous buttons
138 | * are right next to the event text, making it too easy to mistakenly
139 | * activate the anchor instead of just going to next/previous event.
140 | *
141 |