@imerss/inat-components 1.1.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/PUBLISH.md +13 -0
  2. package/README.md +20 -0
  3. package/dist/index.d.ts +118 -73
  4. package/dist/index.js +322 -389
  5. package/dist/standalone.min.js +3 -0
  6. package/package.json +17 -5
  7. package/public/standalone.html +55 -0
  8. package/rollup.config.js +15 -4
  9. package/src/__shared/api/common-taxa.ts +3 -3
  10. package/src/__shared/api/favourites.ts +6 -11
  11. package/src/__shared/api/recent-observations.ts +3 -3
  12. package/src/__shared/api/summary.ts +1 -0
  13. package/src/__shared/constants.ts +3 -1
  14. package/src/__shared/index.ts +1 -1
  15. package/src/__shared/typings.ts +58 -44
  16. package/src/__shared/utils/configUtils.ts +10 -6
  17. package/src/__shared/utils/dateUtils.ts +1 -1
  18. package/src/components/common-taxa/common-taxa.tsx +34 -60
  19. package/src/components/error/error.tsx +1 -1
  20. package/src/components/favourites/favourites.tsx +35 -60
  21. package/src/components/hooks/hooks.tsx +20 -10
  22. package/src/components/loader/loader.tsx +1 -1
  23. package/src/components/observation/observation.tsx +5 -4
  24. package/src/components/recent-observations/recent-observations.tsx +43 -60
  25. package/src/components/shared/css/general.module.scss +5 -1
  26. package/src/components/summary/ObserverList.tsx +21 -15
  27. package/src/components/summary/summary.tsx +59 -51
  28. package/src/components/tabs/tabs.tsx +48 -27
  29. package/src/components/taxon-panel/taxon-panel.tsx +83 -77
  30. package/src/components/year-dropdown/year-dropdown.tsx +11 -7
  31. package/src/hooks/useLoadSourceData.ts +81 -0
  32. package/src/index.ts +1 -1
  33. package/src/types/index.d.ts +17 -0
  34. package/src/types/standalone.d.ts +6 -0
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsxs, jsx } from 'react/jsx-runtime';
2
- import React, { useCallback, useState, useEffect } from 'react';
2
+ import React, { useCallback, useState, useEffect, useMemo } from 'react';
3
3
  import fetch$1 from 'isomorphic-unfetch';
4
4
  import { format } from 'date-fns';
5
5
  import LoadingSpinner from 'react-spinners/MoonLoader.js';
@@ -31,6 +31,18 @@ var __assign = function() {
31
31
  return __assign.apply(this, arguments);
32
32
  };
33
33
 
34
+ function __rest(s, e) {
35
+ var t = {};
36
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
37
+ t[p] = s[p];
38
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
39
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
40
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
41
+ t[p[i]] = s[p[i]];
42
+ }
43
+ return t;
44
+ }
45
+
34
46
  function __awaiter(thisArg, _arguments, P, generator) {
35
47
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
36
48
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -70,26 +82,30 @@ function __generator(thisArg, body) {
70
82
  }
71
83
 
72
84
  var BASE_API_URL = 'https://api.inaturalist.org';
73
- var PER_PAGE = 100;
85
+ var NUM_RESULTS = 100;
86
+ var DEFAULT_NUM_YEARS = 10;
74
87
  var BASE_URL = "https://www.inaturalist.org"; // /people/name_here
75
88
  var ERROR_LOG_FILENAME = "inat-components-error.log";
89
+ var DEFAULT_ITEM_WIDTH = 150;
76
90
 
77
91
  var constants = /*#__PURE__*/Object.freeze({
78
92
  __proto__: null,
79
93
  BASE_API_URL: BASE_API_URL,
80
- PER_PAGE: PER_PAGE,
94
+ NUM_RESULTS: NUM_RESULTS,
95
+ DEFAULT_NUM_YEARS: DEFAULT_NUM_YEARS,
81
96
  BASE_URL: BASE_URL,
82
- ERROR_LOG_FILENAME: ERROR_LOG_FILENAME
97
+ ERROR_LOG_FILENAME: ERROR_LOG_FILENAME,
98
+ DEFAULT_ITEM_WIDTH: DEFAULT_ITEM_WIDTH
83
99
  });
84
100
 
85
101
  var getCommonTaxa = function (_a) {
86
- var year = _a.year, taxonId = _a.taxonId, placeId = _a.placeId, perPage = _a.perPage;
102
+ var year = _a.year, taxonId = _a.taxonId, placeId = _a.placeId, numResults = _a.numResults;
87
103
  return __awaiter(void 0, void 0, void 0, function () {
88
104
  var url, response, resp, sortedTaxa;
89
105
  return __generator(this, function (_b) {
90
106
  switch (_b.label) {
91
107
  case 0:
92
- url = "".concat(BASE_API_URL, "/v1/observations/species_counts?verifiable=true&spam=false&place_id=").concat(placeId, "&taxon_id=").concat(taxonId, "&locale=en-US&per_page=").concat(perPage);
108
+ url = "".concat(BASE_API_URL, "/v1/observations/species_counts?verifiable=true&spam=false&place_id=").concat(placeId, "&taxon_id=").concat(taxonId, "&locale=en-US&per_page=").concat(numResults);
93
109
  if (year !== "all") {
94
110
  url += "&d1=".concat(year, "-01-01&d2=").concat(year, "-12-31");
95
111
  }
@@ -132,22 +148,17 @@ var getCommonTaxa = function (_a) {
132
148
  };
133
149
 
134
150
  var getFavourites = function (_a) {
135
- var year = _a.year, taxonId = _a.taxonId, placeId = _a.placeId, perPage = _a.perPage;
151
+ var year = _a.year, taxonId = _a.taxonId, placeId = _a.placeId, numResults = _a.numResults;
136
152
  return __awaiter(void 0, void 0, void 0, function () {
137
153
  var url, response, resp, sortedTaxa;
138
154
  return __generator(this, function (_b) {
139
155
  switch (_b.label) {
140
156
  case 0:
141
- url = "".concat(BASE_API_URL, "/v1/observations?verifiable=true&order_by=votes&order=desc&page=1&spam=false&place_id=").concat(placeId, "&taxon_id=").concat(taxonId, "&locale=en-US&per_page=").concat(perPage);
157
+ url = "".concat(BASE_API_URL, "/v1/observations?verifiable=true&order_by=votes&order=desc&page=1&spam=false&place_id=").concat(placeId, "&taxon_id=").concat(taxonId, "&locale=en-US&per_page=").concat(numResults);
142
158
  if (year !== "all") {
143
159
  url += "&d1=".concat(year, "-01-01&d2=").concat(year, "-12-31");
144
160
  }
145
- return [4 /*yield*/, fetch$1(url, {
146
- // method: 'GET',
147
- // headers: {
148
- // Accept: 'application/json'
149
- // }
150
- })];
161
+ return [4 /*yield*/, fetch$1(url)];
151
162
  case 1:
152
163
  response = _b.sent();
153
164
  return [4 /*yield*/, response.json()];
@@ -164,18 +175,15 @@ var getFavourites = function (_a) {
164
175
  });
165
176
  return [2 /*return*/, {
166
177
  totalResults: resp.total_results,
167
- results: sortedTaxa.map(function (row) {
168
- var _a, _b;
169
- return ({
170
- id: row.id,
171
- imageUrl: ((_b = (_a = row.taxon) === null || _a === void 0 ? void 0 : _a.default_photo) === null || _b === void 0 ? void 0 : _b.square_url) || "",
172
- obsDate: row.observed_on_string,
173
- obsUrl: row.uri,
174
- taxonName: row.taxon.name || "",
175
- taxonCommonName: row.taxon.preferred_common_name,
176
- numFaves: row.faves.length
177
- });
178
- })
178
+ results: sortedTaxa.map(function (row) { return ({
179
+ id: row.id,
180
+ imageUrl: row.observation_photos[0].photo.url || "",
181
+ obsDate: row.observed_on_string,
182
+ obsUrl: row.uri,
183
+ taxonName: row.taxon.name || "",
184
+ taxonCommonName: row.taxon.preferred_common_name,
185
+ numFaves: row.faves.length
186
+ }); })
179
187
  }];
180
188
  }
181
189
  });
@@ -183,13 +191,13 @@ var getFavourites = function (_a) {
183
191
  };
184
192
 
185
193
  var getRecentObservations = function (_a) {
186
- var taxonId = _a.taxonId, placeId = _a.placeId, perPage = _a.perPage;
194
+ var taxonId = _a.taxonId, placeId = _a.placeId, numResults = _a.numResults;
187
195
  return __awaiter(void 0, void 0, void 0, function () {
188
196
  var url, response, obs;
189
197
  return __generator(this, function (_b) {
190
198
  switch (_b.label) {
191
199
  case 0:
192
- url = "".concat(BASE_API_URL, "/v1/observations?photos=true&per_page=").concat(perPage, "&taxon_id=").concat(taxonId, "&place_id=").concat(placeId, "&order=desc&order_by=observed_on");
200
+ url = "".concat(BASE_API_URL, "/v1/observations?photos=true&per_page=").concat(numResults, "&taxon_id=").concat(taxonId, "&place_id=").concat(placeId, "&order=desc&order_by=observed_on");
193
201
  return [4 /*yield*/, fetch$1(url)];
194
202
  case 1:
195
203
  response = _b.sent();
@@ -310,12 +318,6 @@ var getSeasonalityData = function (taxonId, placeId, year) { return __awaiter(vo
310
318
  });
311
319
  }); };
312
320
 
313
- var DataSource;
314
- (function (DataSource) {
315
- DataSource["autoLoad"] = "autoLoad";
316
- DataSource["dataProp"] = "dataProp";
317
- DataSource["url"] = "url";
318
- })(DataSource || (DataSource = {}));
319
321
  var Feature;
320
322
  (function (Feature) {
321
323
  Feature["commonTaxa"] = "commonTaxa";
@@ -323,32 +325,32 @@ var Feature;
323
325
  Feature["recentObservations"] = "recentObservations";
324
326
  Feature["stats"] = "stats";
325
327
  })(Feature || (Feature = {}));
326
- // I know this is duplicated, but it's very possible they could be different in future
327
- var Tab;
328
- (function (Tab) {
329
- Tab["recent"] = "recent";
330
- Tab["commonTaxa"] = "commonTaxa";
331
- Tab["favourites"] = "favourites";
332
- Tab["stats"] = "stats";
333
- })(Tab || (Tab = {}));
328
+ var DataSourceEnum;
329
+ (function (DataSourceEnum) {
330
+ DataSourceEnum["autoLoad"] = "autoLoad";
331
+ DataSourceEnum["url"] = "url";
332
+ })(DataSourceEnum || (DataSourceEnum = {}));
334
333
 
335
334
  /*
336
335
  * Note that right now the source filenames aren't configurable.
337
336
  */
338
- var getSourceFile = function (api, taxonInfo, placeInfo, year) {
337
+ var getSourceFile = function (api, taxon, place, year) {
338
+ if (!taxon || !place) {
339
+ return '';
340
+ }
339
341
  var yearStr = year === "all" ? "allyears" : year;
340
342
  var filename = "";
341
343
  if (api === Feature.recentObservations) {
342
- filename = "".concat(taxonInfo.short, "-").concat(placeInfo.short, "-recent.json");
344
+ filename = "".concat(taxon.str, "-").concat(place.str, "-recent.json");
343
345
  }
344
346
  else if (api === Feature.commonTaxa) {
345
- filename = "".concat(taxonInfo.short, "-").concat(placeInfo.short, "-").concat(yearStr, "-commonTaxa.json");
347
+ filename = "".concat(taxon.str, "-").concat(place.str, "-").concat(yearStr, "-commonTaxa.json");
346
348
  }
347
349
  else if (api === Feature.favourites) {
348
- filename = "".concat(taxonInfo.short, "-").concat(placeInfo.short, "-").concat(yearStr, "-favourites.json");
350
+ filename = "".concat(taxon.str, "-").concat(place.str, "-").concat(yearStr, "-favourites.json");
349
351
  }
350
352
  else if (api === Feature.stats) {
351
- filename = "".concat(taxonInfo.short, "-").concat(placeInfo.short, "-").concat(yearStr, "-stats.json");
353
+ filename = "".concat(taxon.str, "-").concat(place.str, "-").concat(yearStr, "-stats.json");
352
354
  }
353
355
  return filename;
354
356
  };
@@ -396,18 +398,18 @@ function styleInject(css, ref) {
396
398
  }
397
399
  }
398
400
 
399
- var css_248z$5 = ".observation-module_obs__-5hGT {\n cursor: pointer;\n border-radius: 8px;\n background-color: #f9f9f9;\n text-align: center;\n transition: all 0.15s ease-in-out; }\n .observation-module_obs__-5hGT:hover {\n background-color: #e1e1e1; }\n\n.observation-module_obs__-5hGT h3 {\n margin: 0; }\n\n.observation-module_image__BBTP8 {\n max-width: 100%;\n max-height: 100%; }\n";
400
- var styles$5 = {"obs":"observation-module_obs__-5hGT","image":"observation-module_image__BBTP8"};
401
- styleInject(css_248z$5);
401
+ var css_248z$4 = ".observation-module_obs__-5hGT {\n cursor: pointer;\n border-radius: 8px;\n background-color: #f9f9f9;\n text-align: center;\n transition: all 0.15s ease-in-out;\n}\n.observation-module_obs__-5hGT:hover {\n background-color: #e1e1e1;\n}\n\n.observation-module_obs__-5hGT h3 {\n margin: 0;\n}\n\n.observation-module_image__BBTP8 {\n max-width: 100%;\n max-height: 100%;\n}";
402
+ var styles$4 = {"obs":"observation-module_obs__-5hGT","image":"observation-module_image__BBTP8"};
403
+ styleInject(css_248z$4);
402
404
 
403
405
  var Observation = function (_a) {
404
- var imageUrl = _a.imageUrl, linkUrl = _a.linkUrl, children = _a.children;
406
+ var imageUrl = _a.imageUrl, linkUrl = _a.linkUrl, itemWidth = _a.itemWidth, children = _a.children;
405
407
  var gotoObservation = useCallback(function () {
406
408
  window.open(linkUrl);
407
409
  }, [linkUrl]);
408
- return (jsxs("article", __assign({ className: styles$5.obs, onClick: gotoObservation }, { children: [jsx("div", { style: {
409
- width: 200,
410
- height: 200,
410
+ return (jsxs("article", __assign({ className: styles$4.obs, onClick: gotoObservation }, { children: [jsx("div", { style: {
411
+ width: itemWidth,
412
+ height: itemWidth,
411
413
  overflow: "hidden",
412
414
  borderRadius: 5,
413
415
  background: "url(".concat(imageUrl, ") 50% 50% no-repeat"),
@@ -416,250 +418,194 @@ var Observation = function (_a) {
416
418
  } }), children] })));
417
419
  };
418
420
 
419
- var css_248z$4 = ".general-module_page__ziNB9 {\n padding: 80px 10px 10px;\n margin: 0 auto;\n max-width: 1100px; }\n .general-module_page__ziNB9 h1 {\n border-bottom: 1px solid #efefef;\n padding-bottom: 2px;\n margin-bottom: 25px; }\n\n.general-module_panel__WjWzy {\n position: relative; }\n\n.general-module_grid__VwNiL {\n display: grid;\n grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));\n width: 100%;\n grid-gap: 8px;\n text-align: center; }\n\n.general-module_obsLabel__9R-PO {\n padding: 10px 20px; }\n .general-module_obsLabel__9R-PO a {\n text-decoration: none;\n color: #336699; }\n .general-module_obsLabel__9R-PO a:hover {\n text-decoration: underline; }\n\n.general-module_loader__gBvfF {\n position: absolute;\n top: 50px;\n left: 0;\n right: 0;\n z-index: 1;\n margin: 0;\n display: flex;\n align-items: center;\n justify-content: center; }\n\n.general-module_loaderBg__URuj7 {\n position: absolute;\n background-color: #cccccc;\n padding: 20px;\n width: 100px;\n border-radius: 10px;\n height: 100%;\n opacity: 0.8; }\n\n.general-module_count__Gnr8W {\n background-color: #efefef;\n color: #666666;\n padding: 2px 8px;\n margin-top: 6px;\n display: inline-block;\n border-radius: 3px;\n font-weight: bold;\n font-size: 18px; }\n";
420
- var styles$4 = {"page":"general-module_page__ziNB9","panel":"general-module_panel__WjWzy","grid":"general-module_grid__VwNiL","obsLabel":"general-module_obsLabel__9R-PO","loader":"general-module_loader__gBvfF","loaderBg":"general-module_loaderBg__URuj7","count":"general-module_count__Gnr8W"};
421
- styleInject(css_248z$4);
421
+ var css_248z$3 = ".general-module_page__ziNB9 {\n padding: 80px 10px 10px;\n margin: 0 auto;\n max-width: 1100px;\n}\n.general-module_page__ziNB9 h1 {\n border-bottom: 1px solid #efefef;\n padding-bottom: 2px;\n margin-bottom: 25px;\n}\n\n.general-module_panel__WjWzy {\n position: relative;\n}\n\n.general-module_grid__VwNiL {\n display: grid;\n width: 100%;\n grid-gap: 8px;\n text-align: center;\n}\n\n.general-module_obsLabel__9R-PO {\n padding: 10px 20px;\n}\n.general-module_obsLabel__9R-PO a {\n text-decoration: none;\n color: #336699;\n}\n.general-module_obsLabel__9R-PO a:hover {\n text-decoration: underline;\n}\n\n.general-module_loader__gBvfF {\n position: absolute;\n top: 50px;\n left: 0;\n right: 0;\n z-index: 1;\n margin: 0;\n display: flex;\n align-items: center;\n justify-content: center;\n}\n\n.general-module_loaderBg__URuj7 {\n position: absolute;\n background-color: #cccccc;\n padding: 20px;\n width: 100px;\n border-radius: 10px;\n height: 100%;\n opacity: 0.8;\n}\n\n.general-module_count__Gnr8W {\n background-color: #efefef;\n color: #666666;\n padding: 2px 8px;\n margin-top: 6px;\n display: inline-block;\n border-radius: 3px;\n font-weight: bold;\n font-size: 18px;\n}\n\n.general-module_tabDesc__zOFiV {\n font-size: 14px;\n margin-bottom: 20px;\n}";
422
+ var styles$3 = {"page":"general-module_page__ziNB9","panel":"general-module_panel__WjWzy","grid":"general-module_grid__VwNiL","obsLabel":"general-module_obsLabel__9R-PO","loader":"general-module_loader__gBvfF","loaderBg":"general-module_loaderBg__URuj7","count":"general-module_count__Gnr8W","tabDesc":"general-module_tabDesc__zOFiV"};
423
+ styleInject(css_248z$3);
422
424
 
423
425
  var Loader = function (_a) {
424
426
  var loading = _a.loading;
425
- var loaderClasses = styles$4.loader;
427
+ var loaderClasses = styles$3.loader;
426
428
  // if (loading) {
427
429
  // loaderClasses += ` ${styles.loading}`;
428
430
  // }
429
431
  if (!loading) {
430
432
  return null;
431
433
  }
432
- return (jsxs("div", __assign({ className: loaderClasses }, { children: [jsx("div", { className: styles$4.loaderBg }), jsx(LoadingSpinner, { color: "#000000" })] })));
434
+ return (jsxs("div", __assign({ className: loaderClasses }, { children: [jsx("div", { className: styles$3.loaderBg }), jsx(LoadingSpinner, { color: "#000000" })] })));
433
435
  };
434
436
 
435
437
  var NoResults = function () {
436
438
  return (jsx("p", { children: "No results found." }));
437
439
  };
438
440
 
439
- var RecentObservationLabel = function (obs) { return (jsxs("div", __assign({ className: styles$4.obsLabel }, { children: [jsx("h3", { children: obs.taxonCommonName || obs.taxonName }), jsx("div", { children: formatDate(obs.obsDate) }), jsx("div", { children: jsx("a", __assign({ href: "".concat(BASE_URL, "/people/").concat(obs.observerUsername), target: "_blank", rel: "noreferrer", onClick: function (e) { return e.stopPropagation(); } }, { children: obs.observerUsername })) })] }))); };
440
- var RecentObservations = function (_a) {
441
- var taxonId = _a.taxonId, placeId = _a.placeId, data = _a.data, dataUrl = _a.dataUrl, _b = _a.source, source = _b === void 0 ? DataSource.autoLoad : _b, _c = _a.perPage, perPage = _c === void 0 ? PER_PAGE : _c, components = _a.components, className = _a.className;
442
- var _d = useState(false), loading = _d[0], setLoading = _d[1];
443
- var _e = useState(function () { return (source === DataSource.dataProp) ? data : []; }), observations = _e[0], setObservations = _e[1];
444
- useEffect(function () {
445
- if (source !== DataSource.autoLoad) {
446
- return;
447
- }
448
- if (!taxonId) {
449
- console.error("Please supply a `taxonId` prop for the `autoLoad` source prop option.");
450
- return;
451
- }
452
- if (!placeId) {
453
- console.error("Please supply a `placeId` prop for the `autoLoad` source prop option.");
454
- return;
455
- }
456
- (function () { return __awaiter(void 0, void 0, void 0, function () {
457
- var obs;
458
- return __generator(this, function (_a) {
459
- switch (_a.label) {
460
- case 0:
461
- setLoading(true);
462
- return [4 /*yield*/, getRecentObservations({ taxonId: taxonId, placeId: placeId, perPage: perPage })];
463
- case 1:
464
- obs = _a.sent();
465
- setObservations(obs.results);
466
- setLoading(false);
467
- return [2 /*return*/];
468
- }
469
- });
470
- }); })();
471
- }, [source, taxonId, placeId, perPage]);
441
+ /**
442
+ * This hook handles loading the iNat data from whatever source has been specified (DataSource):
443
+ * nothing needs to be done.
444
+ * - "autoLoad": the user is developing locally and wants to just ping iNat directly for the source
445
+ * - "url": the user has generated the data sources at a URL somewhere via @imerss/inat-component-utils
446
+ */
447
+ var useLoadSourceData = function (_a) {
448
+ var taxonId = _a.taxonId, placeId = _a.placeId, numResults = _a.numResults, source = _a.source, dataUrl = _a.dataUrl, year = _a.year, action = _a.action, _b = _a.isSummaryData, isSummaryData = _b === void 0 ? false : _b;
449
+ var _c = useState(false), loading = _c[0], setLoading = _c[1];
450
+ var _d = useState([]), results = _d[0], setResults = _d[1];
472
451
  useEffect(function () {
473
- if (source !== DataSource.url) {
474
- return;
452
+ if (source === DataSourceEnum.autoLoad) {
453
+ if (!taxonId) {
454
+ console.error("Please supply a `taxonId` prop for the `autoLoad` source prop option.");
455
+ return;
456
+ }
457
+ if (!placeId) {
458
+ console.error("Please supply a `placeId` prop for the `autoLoad` source prop option.");
459
+ return;
460
+ }
461
+ (function () { return __awaiter(void 0, void 0, void 0, function () {
462
+ var obs;
463
+ return __generator(this, function (_a) {
464
+ switch (_a.label) {
465
+ case 0:
466
+ setLoading(true);
467
+ return [4 /*yield*/, action({ taxonId: taxonId, placeId: placeId, numResults: numResults, year: year })];
468
+ case 1:
469
+ obs = _a.sent();
470
+ setResults(obs.results);
471
+ setLoading(false);
472
+ return [2 /*return*/];
473
+ }
474
+ });
475
+ }); })();
475
476
  }
476
- if (!dataUrl) {
477
- console.error("Please supply a `dataUrl` prop for the `url` source prop option.");
478
- return;
477
+ if (source === DataSourceEnum.url) {
478
+ if (!dataUrl) {
479
+ console.error("Please supply a `dataUrl` prop for the `url` source prop option.");
480
+ return;
481
+ }
482
+ (function () { return __awaiter(void 0, void 0, void 0, function () {
483
+ var obs, json;
484
+ return __generator(this, function (_a) {
485
+ switch (_a.label) {
486
+ case 0:
487
+ setLoading(true);
488
+ return [4 /*yield*/, fetch(dataUrl)];
489
+ case 1:
490
+ obs = _a.sent();
491
+ return [4 /*yield*/, obs.json()];
492
+ case 2:
493
+ json = _a.sent();
494
+ // hack workaround. Better solution would have been to standardize the JSON structure at the top-level
495
+ if (isSummaryData) {
496
+ setResults(json);
497
+ }
498
+ else {
499
+ setResults(json.results);
500
+ }
501
+ setLoading(false);
502
+ return [2 /*return*/];
503
+ }
504
+ });
505
+ }); })();
479
506
  }
480
- (function () { return __awaiter(void 0, void 0, void 0, function () {
481
- var obs, json;
482
- return __generator(this, function (_a) {
483
- switch (_a.label) {
484
- case 0:
485
- setLoading(true);
486
- return [4 /*yield*/, fetch(dataUrl)];
487
- case 1:
488
- obs = _a.sent();
489
- return [4 /*yield*/, obs.json()];
490
- case 2:
491
- json = _a.sent();
492
- setObservations(json.results);
493
- setLoading(false);
494
- return [2 /*return*/];
495
- }
496
- });
497
- }); })();
498
- }, [source, dataUrl]);
507
+ }, [source, dataUrl, taxonId, placeId, year, numResults, isSummaryData]);
508
+ return {
509
+ loading: loading,
510
+ results: results
511
+ };
512
+ };
513
+
514
+ var RecentObservationLabel = function (obs) {
515
+ var _a, _b, _c;
516
+ return (jsxs("div", __assign({ className: styles$3.obsLabel }, { children: [jsx("h3", __assign({ className: (_a = obs.classes) === null || _a === void 0 ? void 0 : _a.observationLabelTitle }, { children: obs.taxonCommonName || obs.taxonName })), jsx("div", __assign({ className: (_b = obs.classes) === null || _b === void 0 ? void 0 : _b.observationLabelDate }, { children: formatDate(obs.obsDate) })), jsx("div", __assign({ className: (_c = obs.classes) === null || _c === void 0 ? void 0 : _c.observationLabelName }, { children: jsx("a", __assign({ href: "".concat(BASE_URL, "/people/").concat(obs.observerUsername), target: "_blank", rel: "noreferrer", onClick: function (e) { return e.stopPropagation(); } }, { children: obs.observerUsername })) }))] })));
517
+ };
518
+ var RecentObservations = function (_a) {
519
+ var taxonId = _a.taxonId, placeId = _a.placeId, dataUrl = _a.dataUrl, components = _a.components, className = _a.className, generalClasses = _a.generalClasses, tabDesc = _a.tabDesc, _b = _a.source, source = _b === void 0 ? DataSourceEnum.autoLoad : _b, _c = _a.numResults, numResults = _c === void 0 ? NUM_RESULTS : _c, _d = _a.itemWidth, itemWidth = _d === void 0 ? DEFAULT_ITEM_WIDTH : _d;
520
+ var _e = useLoadSourceData({
521
+ taxonId: taxonId,
522
+ placeId: placeId,
523
+ numResults: numResults,
524
+ dataUrl: dataUrl,
525
+ source: source,
526
+ action: getRecentObservations
527
+ }), loading = _e.loading, observations = _e.results;
499
528
  var Load = (components === null || components === void 0 ? void 0 : components.loader) ? components.loader : Loader;
500
529
  var Label = (components === null || components === void 0 ? void 0 : components.label) ? components.label : RecentObservationLabel;
501
- var classes = styles$4.panel;
530
+ var componentClasses = styles$3.panel;
502
531
  if (className) {
503
- classes += " ".concat(className);
532
+ componentClasses += " ".concat(className);
504
533
  }
505
- return (jsxs("div", __assign({ className: classes }, { children: [jsx(Load, { loading: loading }), jsxs("div", __assign({ className: styles$4.grid }, { children: [!loading && observations.length === 0 && jsx(NoResults, {}), observations.map(function (obs) { return (jsx(Observation, __assign({ imageUrl: obs.imageUrl.replace(/square/, "medium"), linkUrl: obs.obsUrl }, { children: jsx(Label, __assign({}, obs)) }), obs.id)); })] }))] })));
534
+ var descClasses = styles$3.tabDesc;
535
+ if (generalClasses === null || generalClasses === void 0 ? void 0 : generalClasses.tabDesc) {
536
+ descClasses += " ".concat(generalClasses.tabDesc);
537
+ }
538
+ return (jsxs("div", __assign({ className: componentClasses }, { children: [tabDesc && jsx("p", __assign({ className: descClasses }, { children: tabDesc })), jsx(Load, { loading: loading }), jsxs("div", __assign({ className: styles$3.grid, style: { gridTemplateColumns: "repeat(auto-fit, minmax(".concat(itemWidth, "px, 1fr))") } }, { children: [!loading && observations.length === 0 && jsx(NoResults, {}), observations.map(function (obs) { return (jsx(Observation, __assign({ imageUrl: obs.imageUrl.replace(/square/, "medium"), itemWidth: itemWidth, linkUrl: obs.obsUrl }, { children: jsx(Label, __assign({}, obs, { classes: generalClasses })) }), obs.id)); })] }))] })));
506
539
  };
507
540
 
508
- var css_248z$3 = "/*\n * Replace this with your own classes\n *\n * e.g.\n * .container {\n * }\n*/\n";
509
- var styles$3 = {};
510
- styleInject(css_248z$3);
511
-
512
- var Error = function (props) {
513
- return (jsx("div", __assign({ className: styles$3['container'] }, { children: jsx("h1", { children: "Welcome to Error!" }) })));
541
+ var CommonTaxaLabel = function (data) {
542
+ var _a, _b;
543
+ return (jsxs("div", __assign({ className: styles$3.obsLabel }, { children: [jsx("h3", __assign({ className: (_a = data.classes) === null || _a === void 0 ? void 0 : _a.observationLabelTitle }, { children: data.taxonCommonName || data.taxonName })), jsx("label", __assign({ className: "".concat(((_b = data.classes) === null || _b === void 0 ? void 0 : _b.observationCount) || '', " ").concat(styles$3.count) }, { children: numberWithCommas(data.obsCount) }))] })));
514
544
  };
515
-
516
- var CommonTaxaLabel = function (data) { return (jsxs("div", __assign({ className: styles$4.obsLabel }, { children: [jsx("h3", { children: data.taxonCommonName || data.taxonName }), jsx("label", __assign({ className: styles$4.count }, { children: numberWithCommas(data.obsCount) }))] }))); };
517
545
  var CommonTaxa = function (_a) {
518
- var year = _a.year, source = _a.source, taxonId = _a.taxonId, placeId = _a.placeId, _b = _a.perPage, perPage = _b === void 0 ? PER_PAGE : _b, data = _a.data, dataUrl = _a.dataUrl, components = _a.components, className = _a.className;
519
- var _c = useState(function () { return (source === DataSource.dataProp) ? data : []; }), taxa = _c[0], setTaxa = _c[1];
520
- var _d = useState(false), loading = _d[0], setLoading = _d[1];
521
- useEffect(function () {
522
- if (source !== DataSource.autoLoad) {
523
- return;
524
- }
525
- if (!taxonId) {
526
- console.error("Please supply a `taxonId` prop for the `autoLoad` source prop option.");
527
- return;
528
- }
529
- if (!placeId) {
530
- console.error("Please supply a `placeId` prop for the `autoLoad` source prop option.");
531
- return;
532
- }
533
- (function () { return __awaiter(void 0, void 0, void 0, function () {
534
- var resp;
535
- return __generator(this, function (_a) {
536
- switch (_a.label) {
537
- case 0:
538
- setLoading(true);
539
- return [4 /*yield*/, getCommonTaxa({ taxonId: taxonId, placeId: placeId, year: year, perPage: perPage })];
540
- case 1:
541
- resp = _a.sent();
542
- setTaxa(resp.results);
543
- setLoading(false);
544
- return [2 /*return*/];
545
- }
546
- });
547
- }); })();
548
- }, [source, year, placeId, taxonId, perPage]);
549
- useEffect(function () {
550
- if (source !== DataSource.url) {
551
- return;
552
- }
553
- if (!dataUrl) {
554
- console.error("Please supply a `dataUrl` prop for the `url` source prop option.");
555
- return;
556
- }
557
- (function () { return __awaiter(void 0, void 0, void 0, function () {
558
- var obs, json;
559
- return __generator(this, function (_a) {
560
- switch (_a.label) {
561
- case 0:
562
- setLoading(true);
563
- return [4 /*yield*/, fetch(dataUrl)];
564
- case 1:
565
- obs = _a.sent();
566
- return [4 /*yield*/, obs.json()];
567
- case 2:
568
- json = _a.sent();
569
- setTaxa(json.results);
570
- setLoading(false);
571
- return [2 /*return*/];
572
- }
573
- });
574
- }); })();
575
- }, [source, dataUrl]);
546
+ var year = _a.year, source = _a.source, taxonId = _a.taxonId, placeId = _a.placeId, _b = _a.numResults, numResults = _b === void 0 ? NUM_RESULTS : _b, _c = _a.itemWidth, itemWidth = _c === void 0 ? DEFAULT_ITEM_WIDTH : _c, dataUrl = _a.dataUrl, components = _a.components, generalClasses = _a.generalClasses, className = _a.className, tabDesc = _a.tabDesc;
547
+ var _d = useLoadSourceData({
548
+ taxonId: taxonId,
549
+ placeId: placeId,
550
+ numResults: numResults,
551
+ dataUrl: dataUrl,
552
+ source: source,
553
+ year: year,
554
+ action: getCommonTaxa
555
+ }), loading = _d.loading, taxa = _d.results;
576
556
  var Load = (components === null || components === void 0 ? void 0 : components.loader) ? components.loader : Loader;
577
557
  var Label = (components === null || components === void 0 ? void 0 : components.label) ? components.label : CommonTaxaLabel;
578
- (components === null || components === void 0 ? void 0 : components.error) ? components.error : Error;
579
- var classes = styles$4.panel;
558
+ var elClasses = styles$3.panel;
580
559
  if (className) {
581
- classes += " ".concat(className);
560
+ elClasses += " ".concat(className);
561
+ }
562
+ var descClasses = styles$3.tabDesc;
563
+ if (generalClasses === null || generalClasses === void 0 ? void 0 : generalClasses.tabDesc) {
564
+ descClasses += " ".concat(generalClasses.tabDesc);
582
565
  }
583
- return (jsxs("div", __assign({ className: classes }, { children: [jsx(Load, { loading: loading }), !loading && taxa.length === 0 && jsx(NoResults, {}), jsx("div", __assign({ className: styles$4.grid }, { children: taxa.map(function (data) { return (jsx(Observation, __assign({ imageUrl: data.imageUrl.replace(/square/, "medium"), linkUrl: "".concat(BASE_URL, "/").concat(data.id) }, { children: jsx(Label, __assign({}, data)) }), data.id)); }) }))] })));
566
+ return (jsxs("div", __assign({ className: elClasses }, { children: [tabDesc && jsx("p", __assign({ className: descClasses }, { children: tabDesc })), jsx(Load, { loading: loading }), !loading && taxa.length === 0 && jsx(NoResults, {}), jsx("div", __assign({ className: styles$3.grid, style: { gridTemplateColumns: "repeat(auto-fit, minmax(".concat(itemWidth, "px, 1fr))") } }, { children: taxa.map(function (data) { return (jsx(Observation, __assign({ imageUrl: data.imageUrl.replace(/square/, "medium"), itemWidth: itemWidth, linkUrl: "".concat(BASE_URL, "/").concat(data.id) }, { children: jsx(Label, __assign({}, data, { classes: generalClasses })) }), data.id)); }) }))] })));
584
567
  };
585
568
 
586
- var FavouritesLabel = function (data) { return (jsxs("div", __assign({ className: styles$4.obsLabel }, { children: [jsx("h3", { children: data.taxonCommonName || data.taxonName }), jsx("div", { children: data.observerUsername }), jsx("div", { children: formatDate(data.obsDate) }), jsx("label", __assign({ className: styles$4.count }, { children: data.numFaves }))] }))); };
569
+ var FavouritesLabel = function (data) {
570
+ var _a, _b, _c, _d;
571
+ return (jsxs("div", __assign({ className: styles$3.obsLabel }, { children: [jsx("h3", __assign({ className: (_a = data.classes) === null || _a === void 0 ? void 0 : _a.observationLabelTitle }, { children: data.taxonCommonName || data.taxonName })), jsx("div", __assign({ className: (_b = data.classes) === null || _b === void 0 ? void 0 : _b.observationLabelTitle }, { children: data.observerUsername })), jsx("div", __assign({ className: (_c = data.classes) === null || _c === void 0 ? void 0 : _c.observationLabelDate }, { children: formatDate(data.obsDate) })), jsx("label", __assign({ className: "".concat(((_d = data.classes) === null || _d === void 0 ? void 0 : _d.observationCount) || '', " ").concat(styles$3.count) }, { children: data.numFaves }))] })));
572
+ };
587
573
  var Favourites = function (_a) {
588
- var year = _a.year, source = _a.source, taxonId = _a.taxonId, placeId = _a.placeId, data = _a.data, dataUrl = _a.dataUrl, components = _a.components, className = _a.className, _b = _a.perPage, perPage = _b === void 0 ? PER_PAGE : _b;
589
- var _c = useState(function () { return (source === DataSource.dataProp) ? data : []; }), observations = _c[0], setObservations = _c[1];
590
- var _d = useState(false), loading = _d[0], setLoading = _d[1];
591
- useEffect(function () {
592
- if (source !== DataSource.autoLoad) {
593
- return;
594
- }
595
- if (!taxonId) {
596
- console.error("Please supply a `taxonId` prop for the `autoLoad` source prop option.");
597
- return;
598
- }
599
- if (!placeId) {
600
- console.error("Please supply a `placeId` prop for the `autoLoad` source prop option.");
601
- return;
602
- }
603
- (function () { return __awaiter(void 0, void 0, void 0, function () {
604
- var resp;
605
- return __generator(this, function (_a) {
606
- switch (_a.label) {
607
- case 0:
608
- setLoading(true);
609
- return [4 /*yield*/, getFavourites({ taxonId: taxonId, placeId: placeId, year: year, perPage: perPage })];
610
- case 1:
611
- resp = _a.sent();
612
- setObservations(resp.results);
613
- setLoading(false);
614
- return [2 /*return*/];
615
- }
616
- });
617
- }); })();
618
- }, [source, year, placeId, taxonId, perPage]);
619
- useEffect(function () {
620
- if (source !== DataSource.url) {
621
- return;
622
- }
623
- if (!dataUrl) {
624
- console.error("Please supply a `dataUrl` prop for the `url` source prop option.");
625
- return;
626
- }
627
- (function () { return __awaiter(void 0, void 0, void 0, function () {
628
- var obs, json;
629
- return __generator(this, function (_a) {
630
- switch (_a.label) {
631
- case 0:
632
- setLoading(true);
633
- return [4 /*yield*/, fetch(dataUrl)];
634
- case 1:
635
- obs = _a.sent();
636
- return [4 /*yield*/, obs.json()];
637
- case 2:
638
- json = _a.sent();
639
- setObservations(json.results);
640
- setLoading(false);
641
- return [2 /*return*/];
642
- }
643
- });
644
- }); })();
645
- }, [source, dataUrl]);
574
+ var year = _a.year, source = _a.source, taxonId = _a.taxonId, placeId = _a.placeId, dataUrl = _a.dataUrl, components = _a.components, className = _a.className, tabDesc = _a.tabDesc, generalClasses = _a.generalClasses, _b = _a.itemWidth, itemWidth = _b === void 0 ? DEFAULT_ITEM_WIDTH : _b, _c = _a.numResults, numResults = _c === void 0 ? NUM_RESULTS : _c;
575
+ var _d = useLoadSourceData({
576
+ year: year,
577
+ taxonId: taxonId,
578
+ placeId: placeId,
579
+ numResults: numResults,
580
+ dataUrl: dataUrl,
581
+ source: source,
582
+ action: getFavourites
583
+ }), loading = _d.loading, observations = _d.results;
646
584
  var Load = (components === null || components === void 0 ? void 0 : components.loader) ? components.loader : Loader;
647
585
  var Label = (components === null || components === void 0 ? void 0 : components.label) ? components.label : FavouritesLabel;
648
- var classes = styles$4.panel;
586
+ var elClasses = styles$3.panel;
649
587
  if (className) {
650
- classes += " ".concat(className);
588
+ elClasses += " ".concat(className);
589
+ }
590
+ var descClasses = styles$3.tabDesc;
591
+ if (generalClasses === null || generalClasses === void 0 ? void 0 : generalClasses.tabDesc) {
592
+ descClasses += " ".concat(generalClasses.tabDesc);
651
593
  }
652
- return (jsxs("div", __assign({ className: classes }, { children: [jsx(Load, { loading: loading }), !loading && observations.length === 0 && jsx(NoResults, {}), jsx("div", __assign({ className: styles$4.grid }, { children: observations.map(function (obs) { return (jsx(Observation, __assign({ imageUrl: obs.imageUrl.replace(/square/, "medium"), linkUrl: obs.obsUrl }, { children: jsx(Label, __assign({}, obs)) }), obs.id)); }) }))] })));
594
+ return (jsxs("div", __assign({ className: elClasses }, { children: [tabDesc && jsx("p", __assign({ className: descClasses }, { children: tabDesc })), jsx(Load, { loading: loading }), !loading && observations.length === 0 && jsx(NoResults, {}), jsx("div", __assign({ className: styles$3.grid, style: { gridTemplateColumns: "repeat(auto-fit, minmax(".concat(itemWidth, "px, 1fr))") } }, { children: observations.map(function (obs) { return (jsx(Observation, __assign({ imageUrl: obs.imageUrl.replace(/square/, "medium"), itemWidth: itemWidth, linkUrl: obs.obsUrl }, { children: jsx(Label, __assign({}, obs, { classes: generalClasses })) }), obs.id)); }) }))] })));
653
595
  };
654
596
 
655
- var css_248z$2 = ".summary-module_summaryPage__NMmsj {\n position: relative; }\n .summary-module_summaryPage__NMmsj section {\n display: flex; }\n\n.summary-module_top__TKW0j {\n list-style-type: none;\n margin: 0;\n padding: 0; }\n .summary-module_top__TKW0j .summary-module_avatar__16ZeD, .summary-module_top__TKW0j .summary-module_noAvatar__OsMWn {\n margin-right: 10px;\n border-radius: 20px;\n width: 40px;\n height: 40px; }\n .summary-module_top__TKW0j .summary-module_noAvatar__OsMWn {\n display: inline-block;\n background-color: #efefef; }\n .summary-module_top__TKW0j h3 {\n flex: 1;\n color: black; }\n .summary-module_top__TKW0j label {\n flex: 0;\n background-color: #efefef;\n color: #666666;\n padding: 2px 8px;\n margin-top: 6px;\n border-radius: 3px;\n font-weight: bold;\n font-size: 16px; }\n .summary-module_top__TKW0j li {\n border-radius: 3px; }\n .summary-module_top__TKW0j li a {\n display: flex;\n align-items: center;\n text-decoration: none; }\n .summary-module_top__TKW0j li:hover {\n background-color: #efefef; }\n\n.summary-module_countSummary__Xc2Kd {\n list-style-type: none;\n line-height: 28px;\n font-size: 16px;\n padding: 0;\n margin: 0 0 30px; }\n\n.summary-module_seasonalityBlock__BL8L- {\n flex: 3; }\n\n.summary-module_observersBlock__0wnbm {\n flex: 1;\n margin-left: 40px;\n margin-bottom: -40px; }\n\n@media screen and (max-width: 800px) {\n .summary-module_summaryPage__NMmsj section {\n display: block; }\n .summary-module_seasonalityBlock__BL8L- {\n height: 250px;\n margin-bottom: 80px; }\n .summary-module_observersBlock__0wnbm {\n margin-left: 0; } }\n";
597
+ var css_248z$2 = ".summary-module_summaryPage__NMmsj {\n position: relative;\n}\n.summary-module_summaryPage__NMmsj section {\n display: flex;\n}\n\n.summary-module_top__TKW0j {\n list-style-type: none;\n margin: 0;\n padding: 0;\n}\n.summary-module_top__TKW0j .summary-module_avatar__16ZeD, .summary-module_top__TKW0j .summary-module_noAvatar__OsMWn {\n margin-right: 10px;\n border-radius: 20px;\n width: 40px;\n height: 40px;\n}\n.summary-module_top__TKW0j .summary-module_noAvatar__OsMWn {\n display: inline-block;\n background-color: #efefef;\n}\n.summary-module_top__TKW0j h3 {\n flex: 1;\n color: black;\n}\n.summary-module_top__TKW0j label {\n flex: 0;\n background-color: #efefef;\n color: #666666;\n padding: 2px 8px;\n margin-top: 6px;\n border-radius: 3px;\n font-weight: bold;\n font-size: 16px;\n}\n.summary-module_top__TKW0j li {\n border-radius: 3px;\n}\n.summary-module_top__TKW0j li a {\n display: flex;\n align-items: center;\n text-decoration: none;\n}\n.summary-module_top__TKW0j li:hover {\n background-color: #efefef;\n}\n\n.summary-module_countSummary__Xc2Kd {\n list-style-type: none;\n line-height: 28px;\n font-size: 16px;\n padding: 0;\n margin: 0 0 30px;\n}\n\n.summary-module_seasonalityBlock__BL8L- {\n flex: 3;\n}\n\n.summary-module_observersBlock__0wnbm {\n flex: 1;\n margin-left: 40px;\n margin-bottom: -40px;\n}\n\n@media screen and (max-width: 800px) {\n .summary-module_summaryPage__NMmsj section {\n display: block;\n }\n .summary-module_seasonalityBlock__BL8L- {\n height: 250px;\n margin-bottom: 80px;\n }\n .summary-module_observersBlock__0wnbm {\n margin-left: 0;\n }\n}";
656
598
  var styles$2 = {"summaryPage":"summary-module_summaryPage__NMmsj","top":"summary-module_top__TKW0j","avatar":"summary-module_avatar__16ZeD","noAvatar":"summary-module_noAvatar__OsMWn","countSummary":"summary-module_countSummary__Xc2Kd","seasonalityBlock":"summary-module_seasonalityBlock__BL8L-","observersBlock":"summary-module_observersBlock__0wnbm"};
657
599
  styleInject(css_248z$2);
658
600
 
659
601
  var ObserverList = function (_a) {
660
- var observers = _a.observers;
661
- return (jsx("ul", __assign({ className: styles$2.top }, { children: observers.map(function (obs) { return (jsx("li", { children: jsxs("a", __assign({ href: "".concat(BASE_URL, "/people/").concat(obs.userName), target: "_blank", rel: "noreferrer" }, { children: [obs.iconUrl ? jsx("img", { src: obs.iconUrl || "", className: styles$2.avatar, alt: "User icon" }) :
662
- jsx("div", { className: styles$2.noAvatar }), jsx("h3", { children: obs.userName }), jsx("label", { children: numberWithCommas(obs.numObservations) })] })) }, obs.id)); }) })));
602
+ var observers = _a.observers, generalClasses = _a.generalClasses, _b = _a.className, className = _b === void 0 ? '' : _b;
603
+ var classes = styles$2.top;
604
+ if (className) {
605
+ classes += " ".concat(className);
606
+ }
607
+ return (jsx("ul", __assign({ className: classes }, { children: observers.map(function (obs) { return (jsx("li", { children: jsxs("a", __assign({ href: "".concat(BASE_URL, "/people/").concat(obs.userName), target: "_blank", rel: "noreferrer" }, { children: [obs.iconUrl ? jsx("img", { src: obs.iconUrl || "", className: styles$2.avatar, alt: "User icon" }) :
608
+ jsx("div", { className: styles$2.noAvatar }), jsx("h3", { children: obs.userName }), jsx("label", __assign({ className: generalClasses === null || generalClasses === void 0 ? void 0 : generalClasses.observationCount }, { children: numberWithCommas(obs.numObservations) }))] })) }, obs.id)); }) })));
663
609
  };
664
610
 
665
611
  var SeasonalityGraph = function (_a) {
@@ -691,81 +637,58 @@ var SeasonalityGraph = function (_a) {
691
637
 
692
638
  var Summary = function (_a) {
693
639
  var _b, _c, _d;
694
- var source = _a.source; _a.data; var dataUrl = _a.dataUrl, taxonId = _a.taxonId, placeId = _a.placeId, year = _a.year;
695
- var _e = useState({}), summaryData = _e[0], setSummaryData = _e[1];
696
- var _f = useState(false), loading = _f[0], setLoading = _f[1];
697
- useEffect(function () {
698
- if (source !== DataSource.autoLoad) {
699
- return;
700
- }
701
- if (!taxonId) {
702
- console.error("Please supply a `taxonId` prop for the `autoLoad` source prop option.");
703
- return;
704
- }
705
- if (!placeId) {
706
- console.error("Please supply a `placeId` prop for the `autoLoad` source prop option.");
707
- return;
708
- }
709
- (function () { return __awaiter(void 0, void 0, void 0, function () {
710
- var data;
711
- return __generator(this, function (_a) {
712
- switch (_a.label) {
713
- case 0:
714
- setLoading(true);
715
- return [4 /*yield*/, getSummary({ taxonId: taxonId, placeId: placeId, year: year })];
716
- case 1:
717
- data = _a.sent();
718
- setSummaryData(data);
719
- setLoading(false);
720
- return [2 /*return*/];
721
- }
722
- });
723
- }); })();
724
- }, [source, year, placeId, taxonId]);
725
- useEffect(function () {
726
- if (source !== DataSource.url) {
727
- return;
728
- }
729
- if (!dataUrl) {
730
- console.error("Please supply a `dataUrl` prop for the `url` source prop option.");
731
- return;
732
- }
733
- (function () { return __awaiter(void 0, void 0, void 0, function () {
734
- var obs, json;
640
+ var source = _a.source, dataUrl = _a.dataUrl, taxonId = _a.taxonId, placeId = _a.placeId, year = _a.year, generalClasses = _a.generalClasses, className = _a.className, tabDesc = _a.tabDesc, observersListClass = _a.observersListClass, statsCountSummaryClass = _a.statsCountSummaryClass;
641
+ var _e = useLoadSourceData({
642
+ year: year,
643
+ taxonId: taxonId,
644
+ placeId: placeId,
645
+ dataUrl: dataUrl,
646
+ source: source,
647
+ isSummaryData: true,
648
+ // shim to standardize the response from the `action` method with a top-level `results` property. This
649
+ // just lets the useLoadSourceData hook work for all tab components
650
+ action: function (data) { return __awaiter(void 0, void 0, void 0, function () {
651
+ var results;
735
652
  return __generator(this, function (_a) {
736
653
  switch (_a.label) {
737
- case 0:
738
- setLoading(true);
739
- return [4 /*yield*/, fetch(dataUrl)];
654
+ case 0: return [4 /*yield*/, getSummary(data)];
740
655
  case 1:
741
- obs = _a.sent();
742
- return [4 /*yield*/, obs.json()];
743
- case 2:
744
- json = _a.sent();
745
- setSummaryData(json);
746
- setLoading(false);
747
- return [2 /*return*/];
656
+ results = _a.sent();
657
+ return [2 /*return*/, { results: results }];
748
658
  }
749
659
  });
750
- }); })();
751
- }, [source, dataUrl]);
752
- return (jsxs("div", __assign({ className: styles$2.summaryPage }, { children: [jsx(Loader, { loading: loading }), jsxs("ul", __assign({ className: styles$2.countSummary }, { children: [jsxs("li", { children: ["Total number of observers: ", jsx("b", { children: ((_b = summaryData.observers) === null || _b === void 0 ? void 0 : _b.totalCount) ? numberWithCommas(summaryData.observers.totalCount) : "" })] }), jsxs("li", { children: ["Total number of observations: ", jsx("b", { children: ((_c = summaryData.observations) === null || _c === void 0 ? void 0 : _c.totalCount) ? numberWithCommas(summaryData.observations.totalCount) : "" })] })] })), jsxs("section", { children: [jsxs("div", __assign({ className: styles$2.seasonalityBlock }, { children: [jsx("h1", { children: "Seasonality" }), summaryData.seasonalityData && jsx(SeasonalityGraph, { data: summaryData.seasonalityData.monthOfYear })] })), jsxs("div", __assign({ className: styles$2.observersBlock }, { children: [jsx("h1", { children: "Top observers" }), ((_d = summaryData.observers) === null || _d === void 0 ? void 0 : _d.top) && jsx(ObserverList, { observers: summaryData.observers.top })] }))] })] })));
660
+ }); }
661
+ }), loading = _e.loading, summaryData = _e.results;
662
+ var countSummaryClasses = styles$2.countSummary;
663
+ if (statsCountSummaryClass) {
664
+ countSummaryClasses += " ".concat(statsCountSummaryClass);
665
+ }
666
+ var descClasses = styles$2.tabDesc;
667
+ if (generalClasses === null || generalClasses === void 0 ? void 0 : generalClasses.tabDesc) {
668
+ descClasses += " ".concat(generalClasses.tabDesc);
669
+ }
670
+ var classList = styles$2.summaryPage;
671
+ if (className) {
672
+ classList += " ".concat(className);
673
+ }
674
+ return (jsxs("div", __assign({ className: classList }, { children: [tabDesc && jsx("p", __assign({ className: descClasses }, { children: tabDesc })), jsx(Loader, { loading: loading }), jsxs("ul", __assign({ className: countSummaryClasses }, { children: [jsxs("li", { children: ["Total number of observers: ", jsx("b", { children: ((_b = summaryData.observers) === null || _b === void 0 ? void 0 : _b.totalCount) ? numberWithCommas(summaryData.observers.totalCount) : "" })] }), jsxs("li", { children: ["Total number of observations: ", jsx("b", { children: ((_c = summaryData.observations) === null || _c === void 0 ? void 0 : _c.totalCount) ? numberWithCommas(summaryData.observations.totalCount) : "" })] })] })), jsxs("section", { children: [jsxs("div", __assign({ className: styles$2.seasonalityBlock }, { children: [jsx("h1", { children: "Seasonality" }), summaryData.seasonalityData && jsx(SeasonalityGraph, { data: summaryData.seasonalityData.monthOfYear })] })), jsxs("div", __assign({ className: styles$2.observersBlock }, { children: [jsx("h1", { children: "Top observers" }), ((_d = summaryData.observers) === null || _d === void 0 ? void 0 : _d.top) && (jsx(ObserverList, { observers: summaryData.observers.top, className: observersListClass, generalClasses: generalClasses }))] }))] })] })));
753
675
  };
754
676
 
755
- var css_248z$1 = ".year-dropdown-module_dropdown__iD9sj {\n font-size: 18px; }\n";
677
+ var css_248z$1 = ".year-dropdown-module_dropdown__iD9sj {\n font-size: 18px;\n}";
756
678
  var styles$1 = {"dropdown":"year-dropdown-module_dropdown__iD9sj"};
757
679
  styleInject(css_248z$1);
758
680
 
759
681
  var Years = function (_a) {
760
- var value = _a.value, onChange = _a.onChange, className = _a.className;
761
- var years = useState(function () {
682
+ var value = _a.value, onChange = _a.onChange, numYears = _a.numYears, className = _a.className;
683
+ var _b = useState([]), years = _b[0], setYears = _b[1];
684
+ useEffect(function () {
762
685
  var currentYear = getCurrentYear();
763
686
  var years = [];
764
- for (var i = currentYear; i >= currentYear - 10; i--) {
687
+ for (var i = currentYear; i > currentYear - numYears; i--) {
765
688
  years.push(i);
766
689
  }
767
- return years;
768
- })[0];
690
+ setYears(years);
691
+ }, [numYears]);
769
692
  var classes = styles$1.dropdown;
770
693
  if (className) {
771
694
  classes += " ".concat(className);
@@ -773,16 +696,16 @@ var Years = function (_a) {
773
696
  return (jsxs("select", __assign({ className: classes, onChange: function (e) { return onChange(e.target.value); }, defaultValue: value }, { children: [jsx("option", __assign({ value: "all" }, { children: "All years" })), years.map(function (year) { return jsx("option", __assign({ value: year }, { children: year }), year); })] })));
774
697
  };
775
698
 
776
- var css_248z = ".tabs-module_tabs__UMeM9 {\n display: flex;\n flex-direction: row;\n list-style: none;\n font-size: 18px;\n padding: 0;\n margin-bottom: 30px; }\n .tabs-module_tabs__UMeM9 li {\n margin: 0 20px;\n padding: 4px 20px;\n cursor: pointer;\n color: #999999;\n transition: all 0.2s ease-in-out; }\n .tabs-module_tabs__UMeM9 li.tabs-module_selected__SVr0E, .tabs-module_tabs__UMeM9 li:hover {\n border-bottom: 5px solid #0099cc;\n color: black; }\n\n@media screen and (max-width: 600px) {\n .tabs-module_tabs__UMeM9 li {\n margin: 0 5px;\n padding: 4px 6px; } }\n";
699
+ var css_248z = ".tabs-module_tabs__UMeM9 {\n display: flex;\n flex-direction: row;\n list-style: none;\n font-size: 18px;\n padding: 0;\n margin-bottom: 30px;\n}\n.tabs-module_tabs__UMeM9 li {\n margin: 0 20px;\n padding: 4px 20px;\n cursor: pointer;\n color: #999999;\n transition: all 0.2s ease-in-out;\n}\n.tabs-module_tabs__UMeM9 li.tabs-module_selected__SVr0E, .tabs-module_tabs__UMeM9 li:hover {\n border-bottom: 5px solid #0099cc;\n color: black;\n}\n\n@media screen and (max-width: 600px) {\n .tabs-module_tabs__UMeM9 li {\n margin: 0 5px;\n padding: 4px 6px;\n }\n}";
777
700
  var styles = {"tabs":"tabs-module_tabs__UMeM9","selected":"tabs-module_selected__SVr0E"};
778
701
  styleInject(css_248z);
779
702
 
780
703
  var _a;
781
704
  var defaultTitles = (_a = {},
782
- _a[Tab.recent] = "Recent",
783
- _a[Tab.commonTaxa] = "Most common",
784
- _a[Tab.favourites] = "Most favourited",
785
- _a[Tab.stats] = "General stats",
705
+ _a[Feature.recentObservations] = "Recent",
706
+ _a[Feature.commonTaxa] = "Most common",
707
+ _a[Feature.favourites] = "Most favourited",
708
+ _a[Feature.stats] = "General stats",
786
709
  _a);
787
710
  var useFeatureTitles = function (features) {
788
711
  var _a = useState(defaultTitles), titles = _a[0], setTitles = _a[1];
@@ -790,88 +713,98 @@ var useFeatureTitles = function (features) {
790
713
  var _a;
791
714
  var _b, _c, _d, _e;
792
715
  setTitles((_a = {},
793
- _a[Tab.recent] = ((_b = features.recentObservations) === null || _b === void 0 ? void 0 : _b.label) || defaultTitles[Tab.recent],
794
- _a[Tab.commonTaxa] = ((_c = features.commonTaxa) === null || _c === void 0 ? void 0 : _c.label) || defaultTitles[Tab.commonTaxa],
795
- _a[Tab.favourites] = ((_d = features.favourites) === null || _d === void 0 ? void 0 : _d.label) || defaultTitles[Tab.favourites],
796
- _a[Tab.stats] = ((_e = features.stats) === null || _e === void 0 ? void 0 : _e.label) || defaultTitles[Tab.stats],
716
+ _a[Feature.recentObservations] = ((_b = features.recentObservations) === null || _b === void 0 ? void 0 : _b.title) || defaultTitles[Feature.recentObservations],
717
+ _a[Feature.commonTaxa] = ((_c = features.commonTaxa) === null || _c === void 0 ? void 0 : _c.title) || defaultTitles[Feature.commonTaxa],
718
+ _a[Feature.favourites] = ((_d = features.favourites) === null || _d === void 0 ? void 0 : _d.title) || defaultTitles[Feature.favourites],
719
+ _a[Feature.stats] = ((_e = features.stats) === null || _e === void 0 ? void 0 : _e.title) || defaultTitles[Feature.stats],
797
720
  _a));
798
721
  }, [features]);
799
722
  return titles;
800
723
  };
724
+ var convertFeaturesToObj = function (features) {
725
+ var featuresObj = {};
726
+ features.forEach(function (row) {
727
+ var feature = row.feature, other = __rest(row, ["feature"]);
728
+ featuresObj[feature] = other;
729
+ });
730
+ return featuresObj;
731
+ };
801
732
 
802
733
  var Tabs = function (_a) {
803
- var selectedTab = _a.selectedTab, onChangeTab = _a.onChangeTab, features = _a.features;
734
+ var selectedTab = _a.selectedTab, onChangeTab = _a.onChangeTab, features = _a.features, className = _a.className;
804
735
  var titles = useFeatureTitles(features);
805
- return (jsxs("ul", __assign({ className: styles.tabs }, { children: [features.recentObservations && (jsx("li", __assign({ onClick: function () { return onChangeTab(Tab.recent); }, className: selectedTab === Tab.recent ? styles.selected : "" }, { children: titles[Tab.recent] }))), features.commonTaxa && (jsx("li", __assign({ onClick: function () { return onChangeTab(Tab.commonTaxa); }, className: selectedTab === Tab.commonTaxa ? styles.selected : "" }, { children: titles[Tab.commonTaxa] }))), features.favourites && (jsx("li", __assign({ onClick: function () { return onChangeTab(Tab.favourites); }, className: selectedTab === Tab.favourites ? styles.selected : "" }, { children: titles[Tab.favourites] }))), features.stats && (jsx("li", __assign({ onClick: function () { return onChangeTab(Tab.stats); }, className: selectedTab === Tab.stats ? styles.selected : "" }, { children: titles[Tab.stats] })))] })));
736
+ var classes = styles.tabs;
737
+ if (className) {
738
+ classes += " ".concat(className);
739
+ }
740
+ var items = features.map(function (item) {
741
+ if (item.feature == Feature.recentObservations) {
742
+ return (jsx("li", __assign({ onClick: function () { return onChangeTab(Feature.recentObservations); }, className: selectedTab === Feature.recentObservations ? styles.selected : "" }, { children: titles[Feature.recentObservations] }), Feature.recentObservations));
743
+ }
744
+ else if (item.feature == Feature.commonTaxa) {
745
+ return (jsx("li", __assign({ onClick: function () { return onChangeTab(Feature.commonTaxa); }, className: selectedTab === Feature.commonTaxa ? styles.selected : "" }, { children: titles[Feature.commonTaxa] }), Feature.commonTaxa));
746
+ }
747
+ else if (item.feature == Feature.favourites) {
748
+ return (jsx("li", __assign({ onClick: function () { return onChangeTab(Feature.favourites); }, className: selectedTab === Feature.favourites ? styles.selected : "" }, { children: titles[Feature.favourites] }), Feature.favourites));
749
+ }
750
+ else if (item.feature == Feature.stats) {
751
+ return (jsx("li", __assign({ onClick: function () { return onChangeTab(Feature.stats); }, className: selectedTab === Feature.stats ? styles.selected : "" }, { children: titles[Feature.stats] }), Feature.stats));
752
+ }
753
+ // possibly a user has included something wacky
754
+ return undefined;
755
+ });
756
+ return (jsx("ul", __assign({ className: classes }, { children: items })));
806
757
  };
807
758
 
808
759
  var TaxonPanel = function (_a) {
809
- var taxonId = _a.taxonId, placeId = _a.placeId, dataSource = _a.dataSource, config = _a.config, baseURL = _a.baseURL;
810
- var _b = useState(Tab.recent), tab = _b[0], setTab = _b[1];
811
- var _c = useState("all"), year = _c[0], setYear = _c[1];
812
- var titles = useFeatureTitles(config.features);
813
- var _d = useState(function () { return config.taxa.find(function (i) { return i.taxonId === taxonId; }); }), taxonInfo = _d[0]; _d[1];
814
- var _e = useState(function () { return config.places.find(function (i) { return i.placeId === placeId; }); }), placeInfo = _e[0]; _e[1];
760
+ var _b;
761
+ var taxon = _a.taxon, place = _a.place, features = _a.features, dataSource = _a.dataSource, dataSourceBaseUrl = _a.dataSourceBaseUrl, itemWidth = _a.itemWidth, generalClasses = _a.generalClasses;
762
+ var _c = useState(features[0].feature), tab = _c[0], setTab = _c[1];
763
+ var _d = useState("all"), year = _d[0], setYear = _d[1];
764
+ var featuresObj = useMemo(function () {
765
+ return convertFeaturesToObj(features);
766
+ }, [features]);
767
+ var titles = useFeatureTitles(featuresObj);
768
+ var getProps = function (feature) {
769
+ var _a, _b, _c;
770
+ var props = {
771
+ source: dataSource,
772
+ itemWidth: itemWidth,
773
+ tabDesc: (_a = featuresObj[feature]) === null || _a === void 0 ? void 0 : _a.desc,
774
+ generalClasses: generalClasses,
775
+ className: (_b = featuresObj[feature]) === null || _b === void 0 ? void 0 : _b.className
776
+ };
777
+ if (dataSource === DataSourceEnum.url) {
778
+ props.dataUrl = dataSourceBaseUrl + '/' + getSourceFile(feature, taxon, place, year);
779
+ }
780
+ else {
781
+ props.placeId = place.id;
782
+ props.taxonId = taxon.id;
783
+ }
784
+ if (feature !== Feature.stats) {
785
+ props.numResults = (_c = featuresObj[feature]) === null || _c === void 0 ? void 0 : _c.numResults;
786
+ }
787
+ if (feature !== Feature.recentObservations) {
788
+ props.year = year;
789
+ }
790
+ return props;
791
+ };
815
792
  var getCurrentTab = function () {
793
+ var _a, _b;
816
794
  switch (tab) {
817
- case Tab.recent: {
818
- var props = {
819
- source: dataSource
820
- };
821
- if (dataSource === DataSource.url) {
822
- props.dataUrl = baseURL + '/' + getSourceFile(Feature.recentObservations, taxonInfo, placeInfo);
823
- }
824
- else {
825
- props.placeId = placeId;
826
- props.taxonId = taxonId;
827
- }
828
- return (jsx(RecentObservations, __assign({}, props)));
829
- }
830
- case Tab.commonTaxa: {
831
- var props = {
832
- source: dataSource,
833
- year: year
834
- };
835
- if (dataSource === DataSource.url) {
836
- props.dataUrl = baseURL + '/' + getSourceFile(Feature.commonTaxa, taxonInfo, placeInfo, year);
837
- }
838
- else {
839
- props.placeId = placeId;
840
- props.taxonId = taxonId;
841
- }
842
- return (jsx(CommonTaxa, __assign({}, props)));
843
- }
844
- case Tab.favourites: {
845
- var props = {
846
- source: dataSource,
847
- year: year
848
- };
849
- if (dataSource === DataSource.url) {
850
- props.dataUrl = baseURL + '/' + getSourceFile(Feature.favourites, taxonInfo, placeInfo, year);
851
- }
852
- else {
853
- props.placeId = placeId;
854
- props.taxonId = taxonId;
855
- }
856
- return (jsx(Favourites, __assign({}, props)));
857
- }
858
- case Tab.stats: {
859
- var props = {
860
- source: dataSource,
861
- year: year
862
- };
863
- if (dataSource === DataSource.url) {
864
- props.dataUrl = baseURL + '/' + getSourceFile(Feature.stats, taxonInfo, placeInfo, year);
865
- }
866
- else {
867
- props.placeId = placeId;
868
- props.taxonId = taxonId;
869
- }
870
- return jsx(Summary, __assign({}, props));
871
- }
795
+ case Feature.recentObservations:
796
+ return jsx(RecentObservations, __assign({}, getProps(Feature.recentObservations)));
797
+ case Feature.commonTaxa:
798
+ return jsx(CommonTaxa, __assign({}, getProps(Feature.commonTaxa)));
799
+ case Feature.favourites:
800
+ return jsx(Favourites, __assign({}, getProps(Feature.favourites)));
801
+ case Feature.stats:
802
+ return (jsx(Summary, __assign({}, getProps(Feature.stats), { observersListClass: (_a = featuresObj[Feature.stats]) === null || _a === void 0 ? void 0 : _a.observersListClass, statsCountSummaryClass: (_b = featuresObj[Feature.stats]) === null || _b === void 0 ? void 0 : _b.statsCountSummaryClass })));
872
803
  }
873
804
  };
874
- return (jsxs("div", __assign({ className: styles$4.page }, { children: [jsx(Tabs, { selectedTab: tab, onChangeTab: setTab, features: config.features }), jsxs("div", { children: [tab !== Tab.recent && (jsx("div", __assign({ style: { float: "right" } }, { children: jsx(Years, { value: year, onChange: setYear }) }))), jsx("h1", { children: titles[tab] })] }), getCurrentTab()] })));
805
+ var tabsClass = (generalClasses === null || generalClasses === void 0 ? void 0 : generalClasses.tabsElement) || '';
806
+ var yearDropdownClass = (generalClasses === null || generalClasses === void 0 ? void 0 : generalClasses.yearsDropdown) || '';
807
+ return (jsxs("div", __assign({ className: styles$3.page }, { children: [features.length > 1 && jsx(Tabs, { selectedTab: tab, onChangeTab: setTab, features: features, className: tabsClass }), jsxs("div", { children: [tab !== Feature.recentObservations && (jsx("div", __assign({ style: { float: "right" }, className: yearDropdownClass }, { children: jsx(Years, { value: year, numYears: ((_b = featuresObj[tab]) === null || _b === void 0 ? void 0 : _b.numYears) || DEFAULT_NUM_YEARS, onChange: setYear }) }))), jsx("h1", __assign({ className: generalClasses === null || generalClasses === void 0 ? void 0 : generalClasses.pageHeadings }, { children: titles[tab] }))] }), getCurrentTab()] })));
875
808
  };
876
809
 
877
- export { constants as C, CommonTaxa, CommonTaxaLabel, DataSource, Favourites, FavouritesLabel, Feature, Observation, RecentObservationLabel, RecentObservations, SeasonalityGraph, Summary, Tab, TaxonPanel as default, formatDate, getCommonTaxa, getCurrentYear, getFavourites, getObservationSummary, getObserverSummary, getRecentObservations, getSeasonalityData, getSourceFile, getSummary, numberWithCommas };
810
+ export { constants as C, CommonTaxa, CommonTaxaLabel, DataSourceEnum, Favourites, FavouritesLabel, Feature, Observation, RecentObservationLabel, RecentObservations, SeasonalityGraph, Summary, TaxonPanel as default, formatDate, getCommonTaxa, getCurrentYear, getFavourites, getObservationSummary, getObserverSummary, getRecentObservations, getSeasonalityData, getSourceFile, getSummary, numberWithCommas };